ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/cfperl.h
(Generate patch)

Comparing deliantra/server/include/cfperl.h (file contents):
Revision 1.17 by root, Thu Aug 31 06:23:19 2006 UTC vs.
Revision 1.18 by root, Thu Aug 31 09:19:34 2006 UTC

27// perl bug #40256: perl does overwrite those with reentrant versions 27// perl bug #40256: perl does overwrite those with reentrant versions
28// but does not initialise their state structures. 28// but does not initialise their state structures.
29#undef random 29#undef random
30#undef crypt 30#undef crypt
31 31
32struct pl;
33struct object;
34struct mapstruct;
35
36void cfperl_init (); 32void cfperl_init ();
37void cfperl_boot (); 33void cfperl_boot ();
38void cfperl_main (); 34void cfperl_main ();
39
40// could have used templates, but a more traditional C api
41// uses more explicit typing which is ok for this purpose.
42enum data_type
43{
44 DT_END, // no further arguments
45 DT_AV, // perl-only av that needs to be flattened out
46 DT_INT,
47 DT_INT64,
48 DT_DOUBLE,
49 DT_STRING, // 0-terminated string
50 DT_DATA, // string + length
51 DT_OBJECT,
52 DT_MAP,
53 DT_PLAYER,
54 DT_ARCH,
55 DT_PARTY,
56 DT_REGION,
57
58 NUM_DATA_TYPES
59};
60 35
61enum event_klass 36enum event_klass
62{ 37{
63 KLASS_NONE, 38 KLASS_NONE,
64 KLASS_GLOBAL, 39 KLASS_GLOBAL,
128// derive using the curiously recurring template pattern, to avoid 103// derive using the curiously recurring template pattern, to avoid
129// virtual method calls etc. 104// virtual method calls etc.
130template<class subclass> 105template<class subclass>
131struct attachable : attachable_base 106struct attachable : attachable_base
132{ 107{
133 static data_type get_dt ()
134 {
135 return subclass::get_dt ();
136 }
137
138 void instantiate () 108 void instantiate ()
139 { 109 {
140 if (attach) 110 if (attach)
141 attachable_base::instantiate (get_dt (), static_cast<subclass *>(this)); 111 attachable_base::instantiate ((data_type) cftype<subclass>::dt, static_cast<subclass *>(this));
142 } 112 }
143}; 113};
144 114
145struct object_freezer 115struct object_freezer
146{ 116{
154 124
155 template<class subclass> 125 template<class subclass>
156 void put (attachable<subclass> *obj) 126 void put (attachable<subclass> *obj)
157 { 127 {
158 put ((attachable_base *)obj); 128 put ((attachable_base *)obj);
129 }
130
131 void put (keyword k);
132 void put (const char *v);
133 void put (int v);
134
135 template<typename value>
136 void put (keyword k, value v)
137 {
138 put (k);
139 put (v);
159 } 140 }
160 141
161 bool save (const char *filename); 142 bool save (const char *filename);
162 143
163 operator bool () { return !!av; } 144 operator bool () { return !!av; }
188 169
189 template<class subclass> 170 template<class subclass>
190 void get (attachable<subclass> *obj, int oid) 171 void get (attachable<subclass> *obj, int oid)
191 { 172 {
192 if (av) 173 if (av)
193 get (subclass::get_dt (), (subclass *)obj, obj, oid); 174 get ((data_type) cftype<subclass>::dt, (subclass *)obj, obj, oid);
194 } 175 }
195 176
196 token get_token (); 177 token get_token ();
197 178
198 operator FILE *() { return fp; } 179 operator FILE *() { return fp; }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines