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.23 by root, Mon Sep 4 13:55:54 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
99 attachable_base () 101 attachable_base ()
100 { 102 {
101 attachable_clear (); 103 attachable_clear ();
102 } 104 }
103 105
106 ~attachable_base ()
107 {
108 clear ();
109 }
110
104 attachable_base (const attachable_base &src) 111 attachable_base (const attachable_base &src)
105 : self (0), cb (0), attach (src.attach) 112 : self (0), cb (0), attach (src.attach)
106 { 113 {
114 }
115
116 attachable_base &operator = (const attachable_base &src)
117 {
118 clear ();
119 attach = src.attach;
120 return *this;
107 } 121 }
108}; 122};
109 123
110// objects attachable from perl (or any other extension) should include or 124// objects attachable from perl (or any other extension) should include or
111// derive using the curiously recurring template pattern, to avoid 125// derive using the curiously recurring template pattern, to avoid
133 void put (attachable<subclass> *obj) 147 void put (attachable<subclass> *obj)
134 { 148 {
135 put ((attachable_base *)obj); 149 put ((attachable_base *)obj);
136 } 150 }
137 151
138 //TODO//temporary 152 // used only for user-defined key-value pairs
139 void put (const char *k, const char *v) 153 void put (const shstr &k, const shstr &v)
140 { 154 {
141 add (k); 155 add (k);
142 156
143 if (v) 157 if (v)
144 add (' '), add (v); 158 add (' '), add (v);
145 159
146 add ('\n'); 160 add ('\n');
147 } 161 }
148 162
149 //TODO//temporary 163 //TODO//temporary, used only for saving body locations
150 void put (const char *k, int v) 164 void put (const char *k, int v)
151 { 165 {
152 add (k); 166 add (k);
153 add (' '); 167 add (' ');
154 add (sint32 (v)); 168 add (sint32 (v));
155 add ('\n'); 169 add ('\n');
156 } 170 }
157 171
158#if 1 172 template<typename T>
159 void put (keyword k, const char *v) 173 void put_string (keyword k, const T &v)
160 { 174 {
161 int klen = keyword_len [k]; 175 int klen = keyword_len [k];
162 int vlen = v ? strlen (v) + 1 : 0; 176 int vlen = v ? strlen (v) + 1 : 0;
163 177
164 char *p = (char *)alloc (klen + vlen + 1); 178 char *p = (char *)alloc (klen + vlen + 1);
165 179
166 memcpy (p, keyword_str [k], klen); p += klen; 180 memcpy (p, keyword_str [k], klen); p += klen;
167 181
168 if (v) 182 if (v)
169 { 183 {
170 *p++ = ' '; vlen--; //TODO//cf compatibility always add space 184 *p++ = ' '; vlen--;
171 memcpy (p, v, vlen); p += vlen; 185 memcpy (p, v, vlen); p += vlen;
172 } 186 }
173 187
174 *p = '\n'; 188 *p = '\n';
175 } 189 }
176#endif
177 190
178#if 0 191 void put (keyword k, const char *v)
192 {
193 put_string (k, v);
194 }
195
179 void put (keyword k, const shstr &v) 196 void put (keyword k, const shstr &v)
180 { 197 {
181 int klen = keyword_len [k]; 198 put_string (k, v);
182 int vlen = v ? v.length () + 1 : 0;
183
184 char *p = (char *)alloc (klen + vlen + 1);
185
186 memcpy (p, keyword_str [k], klen); p += klen;
187
188 if (v)
189 {
190 *p++ = ' '; vlen--; //TODO//cf compatibility always add space
191 memcpy (p, v, vlen); p += vlen;
192 }
193
194 *p = '\n';
195 } 199 }
196#endif
197 200
198 void put (keyword k, double v) 201 void put (keyword k, double v)
199 { 202 {
200 char buf [128]; 203 char buf [128];
201 204
244 void put (keyword k, unsigned long v) { put_(k, (sint64)v); } 247 void put (keyword k, unsigned long v) { put_(k, (sint64)v); }
245 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); }
246 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); }
247 250
248 template<typename T> 251 template<typename T>
249 void put (keyword k, T *v) 252 void put (keyword k, const T *v)
250 { 253 {
251 if (v) 254 if (v)
252 put (k, v->name); 255 put (k, v->name);
253 else 256 else
254 put (k, (const char *)0); 257 put (k, (const char *)0);
255 } 258 }
256 259
260 template<typename T>
261 void put (keyword k, const refptr<T> &v)
262 {
263 put (k, (T *)v);
264 }
265
257 bool save (const char *filename); 266 bool save (const char *filename);
267 char *as_string (); // like strdup
258 268
259 operator bool () { return !!av; } 269 operator bool () { return !!av; }
260}; 270};
261 271
262// compatibility support, should be removed when no longer needed 272// compatibility support, should be removed when no longer needed
271 char *last_value; 281 char *last_value;
272 282
273 operator bool () { return !!text; } 283 operator bool () { return !!text; }
274 284
275 object_thawer (const char *filename = 0); 285 object_thawer (const char *filename = 0);
286 object_thawer (const char *data, AV *perlav);
276 ~object_thawer (); 287 ~object_thawer ();
277 288
278 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);
279 290
280 template<class subclass> 291 template<class subclass>

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines