/*
 * This code was generated by gen_marshal_code.py
 * Please do not modify, or it'll be overwritten!
 */
 
bool marshal_void(PyObject *obj, TQDataStream *str)
{
  Q_UNUSED(str); // stop warnings
  Q_UNUSED(obj);
  return true;
}
PyObject *demarshal_void(TQDataStream *str)
{
  Q_UNUSED(str); // stop warnings
  Py_INCREF(Py_None);
  return Py_None;
}

bool fromPyObject_bool(PyObject *obj, bool *ok)
  {
    *ok=true;
    return PyObject_IsTrue(obj);
  }
PyObject *toPyObject_bool(bool val)
  {
    return PyLong_FromLong(val ? 1 : 0);
  }
bool marshal_bool(PyObject *obj, TQDataStream *str)
  {
    if (str) {
      bool ok;
      bool b = fromPyObject_bool(obj,&ok);
      (*str) << (TQ_INT8)b;
    }
    return true;
  }
PyObject *demarshal_bool(TQDataStream *str)
  {
    TQ_INT8 i;
    (*str) >> i;
    return toPyObject_bool(i!=0);
  }
bool marshal_int(PyObject *obj, TQDataStream *str)
  {
    if (!PyLong_Check(obj)) return false;
    if (str) {
      (*str) << (TQ_INT32)PyLong_AsLong(obj);
    }
    return true;
  }
PyObject *demarshal_int(TQDataStream *str)
  {
    TQ_INT32 i;
    (*str) >> i;
    return PyLong_FromLong( (long)i );
  }
bool marshal_uint(PyObject *obj, TQDataStream *str)
  {
    if (!PyLong_Check(obj)) return false;
    if (str) {
      (*str) << (TQ_INT32)PyLong_AsLong(obj);
    }
    return true;
  }
PyObject *demarshal_uint(TQDataStream *str)
  {
    TQ_INT32 i;
    (*str) >> i;
    return PyLong_FromLong( (long)i );
  }
bool marshal_double(PyObject *obj, TQDataStream *str)
  {
    if (!PyFloat_Check(obj)) return false;
    if (str) {
      (*str) << PyFloat_AsDouble(obj);
    }
    return true;
  }
PyObject *demarshal_double(TQDataStream *str)
  {
    double d;
    (*str) >> d;
    return PyFloat_FromDouble(d);
  }
bool marshal_uchar(PyObject *obj, TQDataStream *str)
  {
    if (PyBytes_Check(obj) && PyBytes_Size(obj)==1) {
      if (str) {
        char *c = PyBytes_AS_STRING(obj);
        (*str) << (*c);
      }
      return true;
    }

    if (PyLong_Check(obj)) {
      if (str) {
        long l = PyLong_AsLong(obj);
        TQ_UINT8 c = (TQ_UINT8)(l & 0xff);
        (*str) << c;
      }
      return true;
    }

    return false;
  }
PyObject *demarshal_uchar(TQDataStream *str)
  {
    TQ_UINT8 c;
    (*str) >> c;
    return PyBytes_FromStringAndSize((const char *)(&c),1);
  }
bool marshal_char(PyObject *obj, TQDataStream *str)
  {
    if (PyLong_Check(obj)) {
      if (str) {
        long l = PyLong_AsLong(obj);
        TQ_INT8 c = (TQ_INT8)(l & 0xff);
        (*str) << c;
      }
      return true;
    }

    return false;
  }
PyObject *demarshal_char(TQDataStream *str)
  {
    TQ_INT8 c;
    (*str) >> c;
    return PyLong_FromLong((long)c);
  }
bool marshal_TQByteArray(PyObject *obj, TQDataStream *str)
  {
    Py_buffer view;
    if (PyObject_GetBuffer(obj, &view, PyBUF_WRITABLE|PyBUF_SIMPLE))
    {
      return false;
    }

    int size = view.len;
    if (size < 0)
    {
      PyBuffer_Release(&view);
      return false;
    }

    if (str)
    {
      TQByteArray a;
      a.setRawData((const char*)view.buf, size);
      (*str) << a;
      a.resetRawData((const char*)view.buf, size);
    }

    PyBuffer_Release(&view);
    return true;
  }
PyObject *demarshal_TQByteArray(TQDataStream *str)
  {
    // Demarshal to a writable buffer object
    TQByteArray a;
    (*str) >> a;

    uint size = a.size();
    char *data = a.data();

    // Demarshal to a writable buffer object
    return PyBytes_FromStringAndSize(data, size);
  }
bool marshal_TQString(PyObject *obj, TQDataStream *str)
  {
    if (!PyBytes_Check(obj)) return false;
    if (str) {
      TQString s = TQString::fromUtf8(PyBytes_AS_STRING(obj));
      (*str) << s;
    }
    return true;
  }
PyObject *demarshal_TQString(TQDataStream *str)
  {
    TQString s;
    (*str) >> s;
    return PyBytes_FromString( s.utf8().data() );
  }
bool marshal_TQCString(PyObject *obj, TQDataStream *str)
  {
    if (!PyBytes_Check(obj)) return false;
    if (str) {
      TQCString s( PyBytes_AS_STRING(obj) );
      (*str) << s;
    }
    return true;
  }
PyObject *demarshal_TQCString(TQDataStream *str)
  {
    TQCString s;
    (*str) >> s;
    return PyBytes_FromString( s.data() );
  }
TQRect fromPyObject_TQRect(PyObject *obj, bool *ok)
{
  int xp1, yp1, xp2, yp2;
  TQRect r;
  *ok=false;
  if (!PyTuple_Check(obj)) return r;
  if (!PyArg_ParseTuple(obj, (char*)"(ii)(ii)", &xp1, &yp1, &xp2, &yp2) &&
      !PyArg_ParseTuple(obj, (char*)"iiii", &xp1, &yp1, &xp2, &yp2))
    return r;
  r.setCoords( xp1, yp1, xp2, yp2 );
  *ok=true;
   return r;
}
PyObject *toPyObject_TQRect(TQRect val)
{
  int xp1, yp1, xp2, yp2;
  val.coords(&xp1,&yp1,&xp2,&yp2);
  return Py_BuildValue((char*)"(ii)(ii)", xp1, yp1, xp2, yp2);
}

bool marshal_TQRect(PyObject *obj, TQDataStream *str)
{
  bool ok;
  TQRect qobj=fromPyObject_TQRect(obj,&ok);
  if (ok && str) (*str) << qobj;
  return ok;
}
PyObject *demarshal_TQRect(TQDataStream *str)
{
  TQRect qobj;
  (*str) >> qobj;
  return toPyObject_TQRect(qobj);
}
TQPoint fromPyObject_TQPoint(PyObject *obj, bool *ok)
{
  int x,y;
  TQPoint p;
  *ok=false;
  if (!PyTuple_Check(obj)) return p;
  if (!PyArg_ParseTuple(obj, (char*)"ii", &x, &y))
    return p;
  p.setX(x);
  p.setY(y);
  *ok=true;
  return p;
}
PyObject *toPyObject_TQPoint(TQPoint val)
{
  return Py_BuildValue((char*)"ii", val.x(), val.y() );
}
bool marshal_TQPoint(PyObject *obj, TQDataStream *str)
{
  bool ok;
  TQPoint qobj=fromPyObject_TQPoint(obj,&ok);
  if (ok && str) (*str) << qobj;
  return ok;
}
PyObject *demarshal_TQPoint(TQDataStream *str)
{
  TQPoint qobj;
  (*str) >> qobj;
  return toPyObject_TQPoint(qobj);
}
TQSize fromPyObject_TQSize(PyObject *obj, bool *ok)
{
  int w,h;
  TQSize sz;
  *ok=false;
  if (!PyTuple_Check(obj)) return sz;
  if (!PyArg_ParseTuple(obj, (char*)"ii", &w, &h))
    return sz;
  sz.setWidth(w);
  sz.setHeight(h);
  *ok=true;
  return sz;
}
PyObject *toPyObject_TQSize(TQSize val)
{
  return Py_BuildValue((char*)"ii", val.width(), val.height() );
}
bool marshal_TQSize(PyObject *obj, TQDataStream *str)
{
  bool ok;
  TQSize qobj=fromPyObject_TQSize(obj,&ok);
  if (ok && str) (*str) << qobj;
  return ok;
}
PyObject *demarshal_TQSize(TQDataStream *str)
{
  TQSize qobj;
  (*str) >> qobj;
  return toPyObject_TQSize(qobj);
}
TQColor fromPyObject_TQColor(PyObject *obj, bool *ok)
{
  int r,g,b;
  TQColor c;
  *ok=false;
  if (!PyTuple_Check(obj)) return c;
  if (!PyArg_ParseTuple(obj, (char*)"iii", &r, &g, &b))
    return c;
  c.setRgb(r,g,b);
  *ok=true;
  return c;
}
PyObject *toPyObject_TQColor(TQColor val)
{
  return Py_BuildValue((char*)"iii", val.red(), val.green(), val.blue() );
}
bool marshal_TQColor(PyObject *obj, TQDataStream *str)
{
  bool ok;
  TQColor qobj=fromPyObject_TQColor(obj,&ok);
  if (ok && str) (*str) << qobj;
  return ok;
}
PyObject *demarshal_TQColor(TQDataStream *str)
{
  TQColor qobj;
  (*str) >> qobj;
  return toPyObject_TQColor(qobj);
}
TQPointArray fromPyObject_TQPointArray(PyObject *obj, bool *ok)
{
  *ok=false;
  if (!PyList_Check(obj)) return TQPointArray();
  int size = PyList_Size(obj);
  TQPointArray pa(size);
  for(int c=0;c<size;c++) {
    TQPoint p = fromPyObject_TQPoint(PyList_GetItem(obj,c), ok);
    if (!*ok) return false;
    pa.setPoint(c,p);
  }
  *ok=true;
  return pa;
}
PyObject *toPyObject_TQPointArray(TQPointArray val)
{
  PyObject *obj = PyList_New(val.size());
  if (!obj) return NULL;
  for(uint c=0;c<val.size();c++) {
    PyObject *tuple = toPyObject_TQPoint( val.point(c) );
    PyList_SetItem(obj, c, tuple);
//    Py_DECREF(tuple);
  }
  return obj;
}
bool marshal_TQPointArray(PyObject *obj, TQDataStream *str)
{
  bool ok;
  TQPointArray qobj=fromPyObject_TQPointArray(obj,&ok);
  if (ok && str) (*str) << qobj;
  return ok;
}
PyObject *demarshal_TQPointArray(TQDataStream *str)
{
  TQPointArray qobj;
  (*str) >> qobj;
  return toPyObject_TQPointArray(qobj);
}
TQDate fromPyObject_TQDate(PyObject *obj, bool *ok)
{
  *ok=false;
  if (!PyTuple_Check(obj)) return TQDate();
  int y,m,d;
  if (!PyArg_ParseTuple(obj, (char*)"iii", &y, &m, &d))
    return TQDate();
  *ok=true;
  return TQDate(y,m,d);
}
PyObject *toPyObject_TQDate(TQDate val)
{
  return Py_BuildValue((char*)"iii", val.year(), val.month(), val.day() );
}
bool marshal_TQDate(PyObject *obj, TQDataStream *str)
{
  bool ok;
  TQDate qobj=fromPyObject_TQDate(obj,&ok);
  if (ok && str) (*str) << qobj;
  return ok;
}
PyObject *demarshal_TQDate(TQDataStream *str)
{
  TQDate qobj;
  (*str) >> qobj;
  return toPyObject_TQDate(qobj);
}
TQTime fromPyObject_TQTime(PyObject *obj, bool *ok)
{
  *ok=false;
  if (!PyTuple_Check(obj)) return TQTime();
  int h,m,s=0,ms=0;
  if (!PyArg_ParseTuple(obj, (char*)"ii|ii", &h, &m, &s, &ms))
    return TQTime();
  *ok=true;
  return TQTime(h,m,s,ms);
}
PyObject *toPyObject_TQTime(TQTime val)
{
  return Py_BuildValue((char*)"iiii", val.hour(), val.minute(), val.second(), val.msec() );
}
bool marshal_TQTime(PyObject *obj, TQDataStream *str)
{
  bool ok;
  TQTime qobj=fromPyObject_TQTime(obj,&ok);
  if (ok && str) (*str) << qobj;
  return ok;
}
PyObject *demarshal_TQTime(TQDataStream *str)
{
  TQTime qobj;
  (*str) >> qobj;
  return toPyObject_TQTime(qobj);
}
TQDateTime fromPyObject_TQDateTime(PyObject *obj, bool *ok)
{
  *ok=false;

  if (PyLong_Check(obj)) {
    *ok=true;
    TQDateTime dt;
    dt.setTime_t( (uint)PyLong_AsLong(obj) );
    return dt;
  }

  PyObject *date_tuple, *time_tuple;
  if (PyArg_ParseTuple(obj, (char*)"OO", &date_tuple, &time_tuple)) {
    TQDateTime dt;
    dt.setTime( fromPyObject_TQTime(time_tuple, ok) );
    if (*ok) dt.setDate( fromPyObject_TQDate(date_tuple, ok) );
    return dt;
  }

  return TQDateTime();
}
PyObject *toPyObject_TQDateTime(TQDateTime val)
{
  PyObject *date_tuple = toPyObject_TQDate( val.date() );
  PyObject *time_tuple = toPyObject_TQTime( val.time() );
  return Py_BuildValue((char*)"OO", date_tuple, time_tuple );
}
bool marshal_TQDateTime(PyObject *obj, TQDataStream *str)
{
  bool ok;
  TQDateTime qobj=fromPyObject_TQDateTime(obj,&ok);
  if (ok && str) (*str) << qobj;
  return ok;
}
PyObject *demarshal_TQDateTime(TQDataStream *str)
{
  TQDateTime qobj;
  (*str) >> qobj;
  return toPyObject_TQDateTime(qobj);
}
KURL fromPyObject_KURL(PyObject *obj, bool *ok)
{
  *ok=false;
  if (!PyBytes_Check(obj)) return KURL();
  *ok=true;
  return KURL( TQString::fromUtf8(PyBytes_AS_STRING(obj)) );
}
PyObject *toPyObject_KURL(KURL val)
{
  return PyBytes_FromString( val.prettyURL().utf8().data() );
}
bool marshal_KURL(PyObject *obj, TQDataStream *str)
{
  bool ok;
  KURL qobj=fromPyObject_KURL(obj,&ok);
  if (ok && str) (*str) << qobj;
  return ok;
}
PyObject *demarshal_KURL(TQDataStream *str)
{
  KURL qobj;
  (*str) >> qobj;
  return toPyObject_KURL(qobj);
}
DCOPRef fromPyObject_DCOPRef(PyObject *obj, bool *ok)
{
  if (PyType_Check(obj) &&
      PyObject_HasAttrString(obj, (char*)"appname") &&
      PyObject_HasAttrString(obj, (char*)"name")) {
    PyObject *appname = PyObject_GetAttrString(obj, (char*)"appname");
    PyObject *name = PyObject_GetAttrString(obj, (char*)"name");
    if (PyBytes_Check(appname) && PyBytes_Check(name)) {
      char *c_appname = PyBytes_AS_STRING(appname);
      char *c_name = PyBytes_AS_STRING(name);
      DCOPRef ref;
      ref.setRef(TQCString(c_appname), TQCString(c_name) );
      Py_DECREF(appname);
      Py_DECREF(name);
      *ok=true;
      return ref;
    }
    Py_DECREF(appname);
    Py_DECREF(name);
  }
  *ok=false;
  return DCOPRef();
}
PyObject *toPyObject_DCOPRef(DCOPRef val)
{
  if (val.isNull()) {
    Py_INCREF(Py_None);
    return Py_None;
  }
  return ImportedModules::instance()->createDCOPObject(val.app(), val.object() );
}
bool marshal_DCOPRef(PyObject *obj, TQDataStream *str)
{
  bool ok;
  DCOPRef qobj=fromPyObject_DCOPRef(obj,&ok);
  if (ok && str) (*str) << qobj;
  return ok;
}
PyObject *demarshal_DCOPRef(TQDataStream *str)
{
  DCOPRef qobj;
  (*str) >> qobj;
  return toPyObject_DCOPRef(qobj);
}
void Marshaller::initFuncs() {
m_marsh_funcs["void"]=marshal_void;
m_demarsh_funcs["void"]=demarshal_void;
m_marsh_funcs["bool"]=marshal_bool;
m_demarsh_funcs["bool"]=demarshal_bool;
m_marsh_funcs["int"]=marshal_int;
m_demarsh_funcs["int"]=demarshal_int;
m_marsh_funcs["uint"]=marshal_uint;
m_demarsh_funcs["uint"]=demarshal_uint;
m_marsh_funcs["double"]=marshal_double;
m_demarsh_funcs["double"]=demarshal_double;
m_marsh_funcs["uchar"]=marshal_uchar;
m_demarsh_funcs["uchar"]=demarshal_uchar;
m_marsh_funcs["char"]=marshal_char;
m_demarsh_funcs["char"]=demarshal_char;
m_marsh_funcs["TQByteArray"]=marshal_TQByteArray;
m_demarsh_funcs["TQByteArray"]=demarshal_TQByteArray;
m_marsh_funcs["TQString"]=marshal_TQString;
m_demarsh_funcs["TQString"]=demarshal_TQString;
m_marsh_funcs["TQCString"]=marshal_TQCString;
m_demarsh_funcs["TQCString"]=demarshal_TQCString;
m_marsh_funcs["TQRect"]=marshal_TQRect;
m_demarsh_funcs["TQRect"]=demarshal_TQRect;
m_marsh_funcs["TQPoint"]=marshal_TQPoint;
m_demarsh_funcs["TQPoint"]=demarshal_TQPoint;
m_marsh_funcs["TQSize"]=marshal_TQSize;
m_demarsh_funcs["TQSize"]=demarshal_TQSize;
m_marsh_funcs["TQColor"]=marshal_TQColor;
m_demarsh_funcs["TQColor"]=demarshal_TQColor;
m_marsh_funcs["TQPointArray"]=marshal_TQPointArray;
m_demarsh_funcs["TQPointArray"]=demarshal_TQPointArray;
m_marsh_funcs["TQDate"]=marshal_TQDate;
m_demarsh_funcs["TQDate"]=demarshal_TQDate;
m_marsh_funcs["TQTime"]=marshal_TQTime;
m_demarsh_funcs["TQTime"]=demarshal_TQTime;
m_marsh_funcs["TQDateTime"]=marshal_TQDateTime;
m_demarsh_funcs["TQDateTime"]=demarshal_TQDateTime;
m_marsh_funcs["KURL"]=marshal_KURL;
m_demarsh_funcs["KURL"]=demarshal_KURL;
m_marsh_funcs["DCOPRef"]=marshal_DCOPRef;
m_demarsh_funcs["DCOPRef"]=demarshal_DCOPRef;
}
