summaryrefslogtreecommitdiffstats
path: root/dcoppython/shell/marshaller.h
blob: 5eefc8003497716201a30a5a1b6025ef8647e866 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/***************************************************************************
 *   Copyright (C) 2003 by Julian Rockey                                   *
 *   linux@jrockey.com                                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#ifndef __marshaller_h__
#define __marshaller_h__

#include <tqmap.h>
#include <Python.h>
#include <tqstring.h>

class TTQDataStream;

namespace PythonDCOP {
//   class Marshaller;
  class PCOPType;

  class Marshaller {
  public:
    Marshaller();
    ~Marshaller();
    bool marshal(const PCOPType &type, PyObject *obj, TTQDataStream &str) const
      { return marsh_private(type,obj,&str); }
    bool canMarshal(const PCOPType &type, PyObject *obj) const
      { return marsh_private(type,obj,NULL); }
    bool marshalList(const PCOPType &list_type, PyObject *obj, TTQDataStream *str) const;
    PyObject *demarshal(const PCOPType &type, TTQDataStream &str) const
      { return demarsh_private(type, &str); }
    PyObject *demarshalList(const PCOPType &list_type, TTQDataStream *str) const;
    bool marshalDict(const PCOPType &key_type, const PCOPType &value_type,
                     PyObject *obj, TTQDataStream *str) const;
    PyObject *demarshalDict(const PCOPType &key_type,
                            const PCOPType &value_type,
                            TTQDataStream *str) const;
    static Marshaller *instance() { return m_instance; }
  protected:
    TTQMap<TTQString,bool(*)(PyObject*,TTQDataStream*)> m_marsh_funcs;
    TTQMap<TTQString,PyObject*(*)(TTQDataStream*)> m_demarsh_funcs;

    static Marshaller *m_instance;

    void initFuncs();
  private:
    bool marsh_private(const PCOPType &type,
                       PyObject *obj,
                       TTQDataStream *str) const;
    PyObject *demarsh_private(const PCOPType &type,
                              TTQDataStream *str) const;



  };

//   bool marshall_bool(PyObject *obj, TTQDataStream *str);
//   bool marshall_int(PyObject *obj, TTQDataStream *str);
//   bool marshall_uint(PyObject *obj, TTQDataStream *str);
//   bool marshall_double(PyObject *obj, TTQDataStream *str);
//   bool marshall_QByteArray(PyObject *obj, TTQDataStream *str);
//   bool marshall_QString(PyObject *obj, TTQDataStream *str);
//   bool marshall_QCString(PyObject *obj, TTQDataStream *str);


}

#endif