-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZTObject.h
160 lines (127 loc) · 2.44 KB
/
ZTObject.h
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
typedef ZSymbolTable<ZTvar> ZTvTable;
#define INST_TO_STR(x) ZTvarp res=ZAlloc(ZTvar,1);\
*res=ZTString(x);\
return res;
class ZObjP : public ZTRoot
{
public:
typedef ZObjP* IType;
ZObjP* val;
ZTvTable DyProps;
ZObjP()
{
myType=ZETObject;
val=this;
}
ZTvTable getDyn()
{
return DyProps;
}
virtual ZTvarp toString(ZTvarS inp)
{
INST_TO_STR(ZIString(_ZC("Base Object")));
}
template<class T>
void AddDataMember(ZChar* dName,ZTvar T::*mdi )
{
ZTvarp zv=ZAlloc(ZTvar,1);
*zv=ZTMemData( reinterpret_cast<ZMemD>(mdi) );
DyProps.InsertSymbol( dName , zv );
}
virtual void cpy(ZObjP*& A,ZTvarS args)
{
std::cout<<"Parent cpy"<<std::endl;
*(reinterpret_cast<ZObjP*>(A))=*this;
}
};
template <class T>
class ZTBaseObject : public ZObjP
{
public:
static ZTvTable StProps;
ZTBaseObject()
{
DyProps = StProps;
}
static void Inheriet(ZTvTable child)
{
StProps.InitScope(child);
}
template<class T>
static void AddFunction(ZChar* mfpName,int mfpNumArgs, ZTvarp (T::*mfp)(ZTvarS) )
{
ZIFunction* zf=ZAlloc(ZIFunction,1);
ZTvarp zv=ZAlloc(ZTvar,1);
ZTmfp v=reinterpret_cast<ZTmfp>(mfp);
zf->pMFunInit(mfpNumArgs,v);
*zv=ZTFunction(zf);
StProps.InsertSymbol(_ZC(mfpName),zv);
}
void cpy(ZObjP*& A,ZTvarS args)
{
A=new T(args);
*A=*this;
/**(reinterpret_cast<T*>(A))=
*(reinterpret_cast<T*>(this));*/
}
};
template <class T> ZTvTable ZTBaseObject<T>::StProps;
class ZTObject;
typedef ZTBaseObject<ZTObject> ZTObjBase;
class ZTObject : public ZTObjBase
{
public:
/*ZBaseObject(ZIInteger in)
{
myType=ZETInt;
val=in;
}*/
ZTObject(ZTvarS inp)
{
}
ZTObject()
{
}
ZTObject(const ZTObjBase & other) : ZTObjBase(other)
{
ZTObject();
}
static void Init()
{
StProps.InitScope();
AddFunction(_ZC("toString"),0,&ZTObject::toString);
}
ZTvarp toString(ZTvarS inp)
{
INST_TO_STR(ZIString(_ZC("Base Object")));
}
ZChar* Oname()
{
return _ZC("Object");
}
};
typedef ZObjP* pZObjP;
class ZTOInstance : public ZTRoot
{
public:
typedef pZObjP IType;
pZObjP val;
ZTOInstance(pZObjP in)
{
myType=ZETInstance;
val=in;
}
ZTOInstance()
{
myType=ZETInstance;
//ZTOInstance(NULL);
}
ZTOInstance(const ZTRoot & other) :ZTRoot(other)
{
ZTOInstance();
}
ZChar* Oname()
{
return _ZC("Object");
}
};