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.24 by root, Sat Sep 9 21:48:28 2006 UTC vs.
Revision 1.32 by root, Fri Nov 17 19:40:54 2006 UTC

51#define ARG_AV(o) DT_AV , static_cast<AV *> (o) 51#define ARG_AV(o) DT_AV , static_cast<AV *> (o)
52#define ARG_INT(v) DT_INT , static_cast<int> (v) 52#define ARG_INT(v) DT_INT , static_cast<int> (v)
53#define ARG_INT64(v) DT_INT64 , static_cast<sint64> (v) 53#define ARG_INT64(v) DT_INT64 , static_cast<sint64> (v)
54#define ARG_DOUBLE(v) DT_DOUBLE, static_cast<double> (v) 54#define ARG_DOUBLE(v) DT_DOUBLE, static_cast<double> (v)
55#define ARG_STRING(v) DT_STRING, static_cast<const char *> (v) 55#define ARG_STRING(v) DT_STRING, static_cast<const char *> (v)
56#define ARG_DATA(s,l) DT_DATA , static_cast<const void *> (s), (l) 56#define ARG_DATA(s,l) DT_DATA , static_cast<const void *> (s), int (l)
57#define ARG_OBJECT(o) DT_OBJECT, (void *)static_cast<struct object *> (o) 57#define ARG_OBJECT(o) DT_OBJECT, (void *)static_cast<object *> (o)
58#define ARG_MAP(o) DT_MAP , (void *)static_cast<struct mapstruct *> (o) 58#define ARG_MAP(o) DT_MAP , (void *)static_cast<maptile *> (o)
59#define ARG_PLAYER(o) DT_PLAYER, (void *)static_cast<struct pl *> (o) 59#define ARG_PLAYER(o) DT_PLAYER, (void *)static_cast<player *> (o)
60#define ARG_ARCH(o) DT_ARCH , (void *)static_cast<struct archetype *> (o) 60#define ARG_ARCH(o) DT_ARCH , (void *)static_cast<archetype *> (o)
61#define ARG_PARTY(o) DT_PARTY , (void *)static_cast<struct party *> (o) 61#define ARG_PARTY(o) DT_PARTY , (void *)static_cast<party *> (o)
62#define ARG_REGION(o) DT_REGION, (void *)static_cast<struct region *> (o) 62#define ARG_REGION(o) DT_REGION, (void *)static_cast<region *> (o)
63 63
64// the ", ## __VA_ARGS" is, unfortunately, a gnu-cpp extension 64// the ", ## __VA_ARGS" is, unfortunately, a gnu-cpp extension
65 65
66// all these return true when the normal event processing should be skipped (if any) 66// all these return true when the normal event processing should be skipped (if any)
67#define INVOKE_(event, ...) cfperl_invoke (event, ## __VA_ARGS__, DT_END) 67#define INVOKE_(event, ...) cfperl_invoke (event, ## __VA_ARGS__, DT_END)
73#define INVOKE_MAP(event, map, ...) INVOKE_(EVENT_ ## MAP ## _ ## event, ARG_MAP (map) , ## __VA_ARGS__) 73#define INVOKE_MAP(event, map, ...) INVOKE_(EVENT_ ## MAP ## _ ## event, ARG_MAP (map) , ## __VA_ARGS__)
74 74
75//TODO should index into @result 75//TODO should index into @result
76#define RESULT(idx,type) cfperl_result_ ## type (idx) 76#define RESULT(idx,type) cfperl_result_ ## type (idx)
77#define RESULT_INT(idx) RESULT(idx, INT) 77#define RESULT_INT(idx) RESULT(idx, INT)
78#define RESULT_MAP(idx) RESULT(idx, MAP)
78 79
79bool cfperl_invoke (event_type event, ...); 80bool cfperl_invoke (event_type event, ...);
80int cfperl_result_INT (int idx); 81int cfperl_result_INT (int idx);
82int cfperl_result_MAP (int idx);
81 83
82struct attachable_base 84struct attachable_base
83{ 85{
84 SV *self; 86 SV *self;
85 AV *cb; // CF+ perl self and callback 87 AV *cb; // CF+ perl self and callback
107 } 109 }
108 110
109 attachable_base (const attachable_base &src) 111 attachable_base (const attachable_base &src)
110 : self (0), cb (0), attach (src.attach) 112 : self (0), cb (0), attach (src.attach)
111 { 113 {
114 }
115
116 attachable_base &operator = (const attachable_base &src)
117 {
118 clear ();
119 attach = src.attach;
120 return *this;
112 } 121 }
113}; 122};
114 123
115// objects attachable from perl (or any other extension) should include or 124// objects attachable from perl (or any other extension) should include or
116// derive using the curiously recurring template pattern, to avoid 125// derive using the curiously recurring template pattern, to avoid
138 void put (attachable<subclass> *obj) 147 void put (attachable<subclass> *obj)
139 { 148 {
140 put ((attachable_base *)obj); 149 put ((attachable_base *)obj);
141 } 150 }
142 151
143 //TODO//temporary 152 // used only for user-defined key-value pairs
144 void put (const char *k, const char *v) 153 void put (const shstr &k, const shstr &v)
145 { 154 {
146 add (k); 155 add (k);
147 156
148 if (v) 157 if (v)
149 add (' '), add (v); 158 add (' '), add (v);
150 159
151 add ('\n'); 160 add ('\n');
152 } 161 }
153 162
154 //TODO//temporary 163 //TODO//temporary, used only for saving body locations
155 void put (const char *k, int v) 164 void put (const char *k, int v)
156 { 165 {
157 add (k); 166 add (k);
158 add (' '); 167 add (' ');
159 add (sint32 (v)); 168 add (sint32 (v));
160 add ('\n'); 169 add ('\n');
161 } 170 }
162 171
163#if 1 172 template<typename T>
164 void put (keyword k, const char *v) 173 void put_string (keyword k, const T &v)
165 { 174 {
166 int klen = keyword_len [k]; 175 int klen = keyword_len [k];
167 int vlen = v ? strlen (v) + 1 : 0; 176 int vlen = v ? strlen (v) + 1 : 0;
168 177
169 char *p = (char *)alloc (klen + vlen + 1); 178 char *p = (char *)alloc (klen + vlen + 1);
170 179
171 memcpy (p, keyword_str [k], klen); p += klen; 180 memcpy (p, keyword_str [k], klen); p += klen;
172 181
173 if (v) 182 if (v)
174 { 183 {
175 *p++ = ' '; vlen--; //TODO//cf compatibility always add space 184 *p++ = ' '; vlen--;
176 memcpy (p, v, vlen); p += vlen; 185 memcpy (p, v, vlen); p += vlen;
177 } 186 }
178 187
179 *p = '\n'; 188 *p = '\n';
180 } 189 }
181#endif
182 190
183#if 0 191 void put (keyword k, const char *v)
192 {
193 put_string (k, v);
194 }
195
184 void put (keyword k, const shstr &v) 196 void put (keyword k, const shstr &v)
185 { 197 {
186 int klen = keyword_len [k]; 198 put_string (k, v);
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 } 199 }
201#endif
202 200
203 void put (keyword k, double v) 201 void put (keyword k, double v)
204 { 202 {
205 char buf [128]; 203 char buf [128];
206 204
249 void put (keyword k, unsigned long v) { put_(k, (sint64)v); } 247 void put (keyword k, unsigned long v) { put_(k, (sint64)v); }
250 void put (keyword k, signed long long v) { put_(k, (sint64)v); } 248 void put (keyword k, signed long long v) { put_(k, (sint64)v); }
251 void put (keyword k, unsigned long long v) { put_(k, (sint64)v); } 249 void put (keyword k, unsigned long long v) { put_(k, (sint64)v); }
252 250
253 template<typename T> 251 template<typename T>
254 void put (keyword k, T *v) 252 void put (keyword k, const T *v)
255 { 253 {
256 if (v) 254 if (v)
257 put (k, v->name); 255 put (k, v->name);
258 else 256 else
259 put (k, (const char *)0); 257 put (k, (const char *)0);
260 } 258 }
261 259
260 template<typename T>
261 void put (keyword k, const refptr<T> &v)
262 {
263 put (k, (T *)v);
264 }
265
262 bool save (const char *filename); 266 bool save (const char *filename);
267 char *as_string (); // like strdup
263 268
264 operator bool () { return !!av; } 269 operator bool () { return !!av; }
265}; 270};
266 271
267// compatibility support, should be removed when no longer needed 272// compatibility support, should be removed when no longer needed
276 char *last_value; 281 char *last_value;
277 282
278 operator bool () { return !!text; } 283 operator bool () { return !!text; }
279 284
280 object_thawer (const char *filename = 0); 285 object_thawer (const char *filename = 0);
286 object_thawer (const char *data, AV *perlav);
281 ~object_thawer (); 287 ~object_thawer ();
282 288
283 void get (data_type type, void *obj, attachable_base *ext, int oid); 289 void get (data_type type, void *obj, attachable_base *ext, int oid);
284 290
285 template<class subclass> 291 template<class subclass>

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines