Added dict object
This commit is contained in:
120
object.h
120
object.h
@@ -1,57 +1,6 @@
|
||||
#ifndef _PYC_OBJECT_H
|
||||
#define _PYC_OBJECT_H
|
||||
|
||||
/* Please only hold PycObjects inside PycRefs! */
|
||||
class PycObject {
|
||||
public:
|
||||
enum Type {
|
||||
// From the Python Marshallers
|
||||
TYPE_NULL = '0',
|
||||
TYPE_NONE = 'N',
|
||||
TYPE_FALSE = 'F',
|
||||
TYPE_TRUE = 'T',
|
||||
TYPE_STOPITER = 'S',
|
||||
TYPE_ELLIPSIS = '.',
|
||||
TYPE_INT = 'i',
|
||||
TYPE_INT64 = 'I',
|
||||
TYPE_FLOAT = 'f',
|
||||
TYPE_BINARY_FLOAT = 'g',
|
||||
TYPE_COMPLEX = 'x',
|
||||
TYPE_BINARY_COMPLEX = 'y',
|
||||
TYPE_LONG = 'l',
|
||||
TYPE_STRING = 's',
|
||||
TYPE_INTERNED = 't',
|
||||
TYPE_STRINGREF = 'R',
|
||||
TYPE_TUPLE = '(',
|
||||
TYPE_LIST = '[',
|
||||
TYPE_DICT = '{',
|
||||
TYPE_CODE = 'c',
|
||||
TYPE_CODE2 = 'C', // Used in Python 1.0 - 1.2
|
||||
TYPE_UNICODE = 'u',
|
||||
TYPE_UNKNOWN = '?',
|
||||
TYPE_SET = '<',
|
||||
TYPE_FROZENSET = '>',
|
||||
};
|
||||
|
||||
PycObject(int type = TYPE_UNKNOWN) : m_refs(0), m_type(type) { }
|
||||
virtual ~PycObject() { }
|
||||
|
||||
int type() const { return (this) ? m_type : TYPE_NULL; }
|
||||
|
||||
virtual bool isType(int type) const
|
||||
{ return (this) ? type == m_type : type == TYPE_NULL; }
|
||||
|
||||
virtual void load(class PycData*, class PycModule*) { }
|
||||
|
||||
private:
|
||||
int m_refs;
|
||||
int m_type;
|
||||
|
||||
public:
|
||||
void addRef() { if (this) ++m_refs; }
|
||||
void delRef() { if (this && --m_refs == 0) delete this; }
|
||||
};
|
||||
|
||||
|
||||
template <class _Obj>
|
||||
class PycRef {
|
||||
@@ -94,15 +43,70 @@ private:
|
||||
_Obj* m_obj;
|
||||
};
|
||||
|
||||
typedef PycRef<PycObject> PycObjRef;
|
||||
|
||||
PycObjRef CreateObject(int type);
|
||||
PycObjRef LoadObject(class PycData* stream, class PycModule* mod);
|
||||
/* Please only hold PycObjects inside PycRefs! */
|
||||
class PycObject {
|
||||
public:
|
||||
enum Type {
|
||||
// From the Python Marshallers
|
||||
TYPE_NULL = '0',
|
||||
TYPE_NONE = 'N',
|
||||
TYPE_FALSE = 'F',
|
||||
TYPE_TRUE = 'T',
|
||||
TYPE_STOPITER = 'S',
|
||||
TYPE_ELLIPSIS = '.',
|
||||
TYPE_INT = 'i',
|
||||
TYPE_INT64 = 'I',
|
||||
TYPE_FLOAT = 'f',
|
||||
TYPE_BINARY_FLOAT = 'g',
|
||||
TYPE_COMPLEX = 'x',
|
||||
TYPE_BINARY_COMPLEX = 'y',
|
||||
TYPE_LONG = 'l',
|
||||
TYPE_STRING = 's',
|
||||
TYPE_INTERNED = 't',
|
||||
TYPE_STRINGREF = 'R',
|
||||
TYPE_TUPLE = '(',
|
||||
TYPE_LIST = '[',
|
||||
TYPE_DICT = '{',
|
||||
TYPE_CODE = 'c',
|
||||
TYPE_CODE2 = 'C', // Used in Python 1.0 - 1.2
|
||||
TYPE_UNICODE = 'u',
|
||||
TYPE_UNKNOWN = '?',
|
||||
TYPE_SET = '<',
|
||||
TYPE_FROZENSET = '>',
|
||||
};
|
||||
|
||||
PycObject(int type = TYPE_UNKNOWN) : m_refs(0), m_type(type) { }
|
||||
virtual ~PycObject() { }
|
||||
|
||||
int type() const { return (this) ? m_type : TYPE_NULL; }
|
||||
|
||||
virtual bool isType(int type) const
|
||||
{ return (this) ? type == m_type : type == TYPE_NULL; }
|
||||
|
||||
virtual bool isEqual(PycRef<PycObject> obj) const
|
||||
{ return (this == (PycObject*)obj); }
|
||||
|
||||
virtual void load(class PycData*, class PycModule*) { }
|
||||
|
||||
private:
|
||||
int m_refs;
|
||||
int m_type;
|
||||
|
||||
public:
|
||||
void addRef() { if (this) ++m_refs; }
|
||||
void delRef() { if (this && --m_refs == 0) delete this; }
|
||||
};
|
||||
|
||||
PycRef<PycObject> CreateObject(int type);
|
||||
PycRef<PycObject> LoadObject(class PycData* stream, class PycModule* mod);
|
||||
|
||||
/* Static Singleton objects */
|
||||
extern PycObjRef Pyc_NULL;
|
||||
extern PycObjRef Pyc_None;
|
||||
extern PycObjRef Pyc_Ellipsis;
|
||||
extern PycObjRef Pyc_StopIteration;
|
||||
extern PycRef<PycObject> Pyc_NULL;
|
||||
extern PycRef<PycObject> Pyc_None;
|
||||
extern PycRef<PycObject> Pyc_Ellipsis;
|
||||
extern PycRef<PycObject> Pyc_StopIteration;
|
||||
extern PycRef<PycObject> Pyc_False;
|
||||
extern PycRef<PycObject> Pyc_True;
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user