/*------------------------------------------------------------------------------
 src/lib/dj/serialize.cxx
 
 Copyright (c) 2004-2006 Darby Johnston.
 All rights reserved.
 Use is subject to license terms.
------------------------------------------------------------------------------*/

#include "djSerialize.h"
#include <djAssert.h>

namespace dj {

const StrList deflateStr(const bool & in) { return StrList() + boolStr()[in]; }
const StrList deflateStr(const int & in) { return StrList() + toStr(in); }
const StrList deflateStr(const uint64_t & in) { return StrList() + toStr(in); }
const StrList deflateStr(const double & in) { return StrList() + toStr(in); }
const StrList deflateStr(char * in) { return StrList() + toStr(in); }
const StrList deflateStr(const char * in) { return StrList() + toStr(in); }
const StrList deflateStr(const Str & in) { return StrList() + in; }
const StrList deflateStr(const StrList & in) { return in; }

bool inflateStr(StrList & in, bool * out)
{
  return inflateStr(in, out, boolStr());
}

bool inflateStr(StrList & in, int * out)
{
  DJ_ASSERT(out);
  if (! in.size()) return false;
  *out = toInt(in.pop());
  return true;
}

bool inflateStr(StrList & in, uint64_t * out)
{
  DJ_ASSERT(out);
  if (! in.size()) return false;
  *out = toLong(in.pop());
  return true;
}

bool inflateStr(StrList & in, double * out)
{
  DJ_ASSERT(out);
  if (! in.size()) return false;
  *out = toFloat(in.pop());
  return true;
}

bool inflateStr(StrList & in, Str * out)
{
  DJ_ASSERT(out);
  if (! in.size()) return false;
  *out = in.pop();
  return true;
}

bool inflateStr(StrList & in, List<int> * out)
{
  DJ_ASSERT(out);
  *out = toIntList(in);
  in.del();
  return true;
}

bool inflateStr(StrList & in, StrList * out)
{
  DJ_ASSERT(out);
  *out = in;
  in.del();
  return true;
}

}
