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.20 by root, Thu Aug 31 18:59:24 2006 UTC vs.
Revision 1.24 by root, Sat Sep 9 21:48:28 2006 UTC

27// but does not initialise their state structures. 27// but does not initialise their state structures.
28#undef random 28#undef random
29#undef crypt 29#undef crypt
30 30
31void cfperl_init (); 31void cfperl_init ();
32void cfperl_boot ();
33void cfperl_main (); 32void cfperl_main ();
34 33
35enum event_klass 34enum event_klass
36{ 35{
37 KLASS_NONE, 36 KLASS_NONE,
82 81
83struct attachable_base 82struct attachable_base
84{ 83{
85 SV *self; 84 SV *self;
86 AV *cb; // CF+ perl self and callback 85 AV *cb; // CF+ perl self and callback
87 const char *attach; // generic extension attachment information 86 shstr attach; // generic extension attachment information
88 87
89 void clear (); // called when free'ing objects 88 void clear (); // called when free'ing objects
90 void optimise (); // possibly save some memory by destroying unneeded data 89 void optimise (); // possibly save some memory by destroying unneeded data
91 void instantiate (data_type type, void *obj); 90 void instantiate (data_type type, void *obj);
92 91
93 void attachable_init () 92 void attachable_clear ()
94 { 93 {
95 self = 0; 94 self = 0;
96 cb = 0; 95 cb = 0;
97 attach = 0; 96 attach = 0;
97 }
98
99 attachable_base ()
100 {
101 attachable_clear ();
102 }
103
104 ~attachable_base ()
105 {
106 clear ();
107 }
108
109 attachable_base (const attachable_base &src)
110 : self (0), cb (0), attach (src.attach)
111 {
98 } 112 }
99}; 113};
100 114
101// objects attachable from perl (or any other extension) should include or 115// objects attachable from perl (or any other extension) should include or
102// derive using the curiously recurring template pattern, to avoid 116// derive using the curiously recurring template pattern, to avoid
129 //TODO//temporary 143 //TODO//temporary
130 void put (const char *k, const char *v) 144 void put (const char *k, const char *v)
131 { 145 {
132 add (k); 146 add (k);
133 147
134 //if (v) 148 if (v)
135 add (' '); //TODO//cf compatibility always add space 149 add (' '), add (v);
136 if (v)
137 add (v);
138 150
139 add ('\n'); 151 add ('\n');
140 } 152 }
141 153
142 //TODO//temporary 154 //TODO//temporary
146 add (' '); 158 add (' ');
147 add (sint32 (v)); 159 add (sint32 (v));
148 add ('\n'); 160 add ('\n');
149 } 161 }
150 162
163#if 1
151 void put (keyword k, const char *v) 164 void put (keyword k, const char *v)
152 { 165 {
153 int klen = keyword_len [k]; 166 int klen = keyword_len [k];
154 int vlen = v ? strlen (v) : 0; 167 int vlen = v ? strlen (v) + 1 : 0;
155 168
156 char *p = (char *)alloc (klen + 1 + vlen + 1); 169 char *p = (char *)alloc (klen + vlen + 1);
157 170
158 memcpy (p, keyword_str [k], klen); p += klen; 171 memcpy (p, keyword_str [k], klen); p += klen;
172
173 if (v)
174 {
159 *p++ = ' '; //TODO//cf compatibility always add space 175 *p++ = ' '; vlen--; //TODO//cf compatibility always add space
160 memcpy (p, v, vlen); p += vlen; 176 memcpy (p, v, vlen); p += vlen;
177 }
178
161 *p = '\n'; 179 *p = '\n';
162 } 180 }
181#endif
182
183#if 0
184 void put (keyword k, const shstr &v)
185 {
186 int klen = keyword_len [k];
187 int vlen = v ? v.length () + 1 : 0;
188
189 char *p = (char *)alloc (klen + vlen + 1);
190
191 memcpy (p, keyword_str [k], klen); p += klen;
192
193 if (v)
194 {
195 *p++ = ' '; vlen--; //TODO//cf compatibility always add space
196 memcpy (p, v, vlen); p += vlen;
197 }
198
199 *p = '\n';
200 }
201#endif
163 202
164 void put (keyword k, double v) 203 void put (keyword k, double v)
165 { 204 {
166 char buf [128]; 205 char buf [128];
167 206
184 add (' '); 223 add (' ');
185 add (v); 224 add (v);
186 add ('\n'); 225 add ('\n');
187 } 226 }
188 227
189 void put (keyword kbeg, keyword kend, const char *v) 228 void put (keyword kbeg, keyword kend, const shstr &v)
190 { 229 {
191 add (keyword_str [kbeg], keyword_len [kbeg]); add ('\n'); 230 add (keyword_str [kbeg], keyword_len [kbeg]); add ('\n');
192 231
193 if (v) 232 if (v)
194 { 233 {
212 void put (keyword k, unsigned long long v) { put_(k, (sint64)v); } 251 void put (keyword k, unsigned long long v) { put_(k, (sint64)v); }
213 252
214 template<typename T> 253 template<typename T>
215 void put (keyword k, T *v) 254 void put (keyword k, T *v)
216 { 255 {
256 if (v)
257 put (k, v->name);
258 else
217 put (k, v ? (const char *)v->name : 0); 259 put (k, (const char *)0);
218 } 260 }
219 261
220 bool save (const char *filename); 262 bool save (const char *filename);
221 263
222 operator bool () { return !!av; } 264 operator bool () { return !!av; }
224 266
225// compatibility support, should be removed when no longer needed 267// compatibility support, should be removed when no longer needed
226int fprintf (object_freezer &freezer, const char *format, ...); 268int fprintf (object_freezer &freezer, const char *format, ...);
227int fputs (const char *s, object_freezer &freezer); 269int fputs (const char *s, object_freezer &freezer);
228 270
229// a single key-value line from a file
230struct token {
231 keyword k;
232 const char *v;
233
234 token (keyword k, const char *v = 0) : k(k), v(v) { }
235};
236
237struct object_thawer 271struct object_thawer
238{ 272{
239 AV *av; 273 SV *text; // text part
240 FILE *fp; 274 AV *av; // perl part
241 char line[1024]; 275 char *line; // current beginning of line
276 char *last_value;
277
278 operator bool () { return !!text; }
242 279
243 object_thawer (const char *filename = 0); 280 object_thawer (const char *filename = 0);
244 ~object_thawer (); 281 ~object_thawer ();
245 282
246 void get (data_type type, void *obj, attachable_base *ext, int oid); 283 void get (data_type type, void *obj, attachable_base *ext, int oid);
250 { 287 {
251 if (av) 288 if (av)
252 get ((data_type) cftype<subclass>::dt, (subclass *)obj, obj, oid); 289 get ((data_type) cftype<subclass>::dt, (subclass *)obj, obj, oid);
253 } 290 }
254 291
255 token get_token (); 292 keyword get_kv (); // also parse value for later use
256 293
257 operator FILE *() { return fp; } 294 const char *get_str () { return last_value; } // may be 0
295
296 void get (shstr &sh) const;
297 void get_ornull (shstr &sh) const { sh = last_value; }
298 void get_ml (keyword kend, shstr &sh);
299
300 sint32 get_sint32 () const;
301 sint64 get_sint64 () const;
302 double get_double () const;
303
304 void get (float &v) { v = get_double (); }
305 void get (double &v) { v = get_double (); }
306
307 void get (sint8 &i) { i = get_sint32 (); }
308 void get (uint8 &i) { i = get_sint32 (); }
309 void get (sint16 &i) { i = get_sint32 (); }
310 void get (uint16 &i) { i = get_sint32 (); }
311 void get (sint32 &i) { i = get_sint32 (); }
312
313 void get (uint32 &i) { i = get_sint64 (); }
314 void get (sint64 &i) { i = get_sint64 (); }
258}; 315};
316
317char *fgets (char *s, int n, object_thawer &thawer);
259 318
260#endif 319#endif
261 320

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines