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.19 by root, Thu Aug 31 17:54:14 2006 UTC

8 8
9using namespace std; 9using namespace std;
10 10
11#include <EXTERN.h> 11#include <EXTERN.h>
12#include <perl.h> 12#include <perl.h>
13
14#include "keyword.h"
15 13
16// optimisations/workaround for functions requiring my_perl in scope (anti-bloat) 14// optimisations/workaround for functions requiring my_perl in scope (anti-bloat)
17#undef localtime 15#undef localtime
18#undef srand48 16#undef srand48
19#undef drand48 17#undef drand48
27// perl bug #40256: perl does overwrite those with reentrant versions 25// perl bug #40256: perl does overwrite those with reentrant versions
28// but does not initialise their state structures. 26// but does not initialise their state structures.
29#undef random 27#undef random
30#undef crypt 28#undef crypt
31 29
32struct pl;
33struct object;
34struct mapstruct;
35
36void cfperl_init (); 30void cfperl_init ();
37void cfperl_boot (); 31void cfperl_boot ();
38void cfperl_main (); 32void 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 33
61enum event_klass 34enum event_klass
62{ 35{
63 KLASS_NONE, 36 KLASS_NONE,
64 KLASS_GLOBAL, 37 KLASS_GLOBAL,
128// derive using the curiously recurring template pattern, to avoid 101// derive using the curiously recurring template pattern, to avoid
129// virtual method calls etc. 102// virtual method calls etc.
130template<class subclass> 103template<class subclass>
131struct attachable : attachable_base 104struct attachable : attachable_base
132{ 105{
133 static data_type get_dt ()
134 {
135 return subclass::get_dt ();
136 }
137
138 void instantiate () 106 void instantiate ()
139 { 107 {
140 if (attach) 108 if (attach)
141 attachable_base::instantiate (get_dt (), static_cast<subclass *>(this)); 109 attachable_base::instantiate ((data_type) cftype<subclass>::dt, static_cast<subclass *>(this));
142 } 110 }
143}; 111};
144 112
145struct object_freezer 113struct object_freezer : dynbuf
146{ 114{
147 AV *av; 115 AV *av;
148 SV *text;
149 116
150 object_freezer (); 117 object_freezer ();
151 ~object_freezer (); 118 ~object_freezer ();
152 119
153 void put (attachable_base *ext); 120 void put (attachable_base *ext);
154 121
155 template<class subclass> 122 template<class subclass>
156 void put (attachable<subclass> *obj) 123 void put (attachable<subclass> *obj)
157 { 124 {
158 put ((attachable_base *)obj); 125 put ((attachable_base *)obj);
126 }
127
128 void put (const char *k, const char *v); //TODO//temporary
129 void put (const char *k, int v); //TODO//temporary
130
131 void put (keyword k, const char *v);
132 void put (keyword k, double v);
133 void put (keyword k, float v) { put (k, (double)v); }
134
135 void put_ (keyword k, sint32 v);
136 void put_ (keyword k, sint64 v);
137
138 void put (keyword k, signed char v) { put_(k, (sint32)v); }
139 void put (keyword k, unsigned char v) { put_(k, (sint32)v); }
140 void put (keyword k, signed short v) { put_(k, (sint32)v); }
141 void put (keyword k, unsigned short v) { put_(k, (sint32)v); }
142 void put (keyword k, signed int v) { put_(k, (sint32)v); }
143 void put (keyword k, unsigned int v) { put_(k, (sint64)v); }
144 void put (keyword k, signed long v) { put_(k, (sint64)v); }
145 void put (keyword k, unsigned long v) { put_(k, (sint64)v); }
146 void put (keyword k, signed long long v) { put_(k, (sint64)v); }
147 void put (keyword k, unsigned long long v) { put_(k, (sint64)v); }
148
149 void put (keyword kbeg, keyword kend, const char *v); // multiline
150
151 template<typename T>
152 void put (keyword k, T *v)
153 {
154 put (k, v ? (const char *)v->name : 0);
159 } 155 }
160 156
161 bool save (const char *filename); 157 bool save (const char *filename);
162 158
163 operator bool () { return !!av; } 159 operator bool () { return !!av; }
188 184
189 template<class subclass> 185 template<class subclass>
190 void get (attachable<subclass> *obj, int oid) 186 void get (attachable<subclass> *obj, int oid)
191 { 187 {
192 if (av) 188 if (av)
193 get (subclass::get_dt (), (subclass *)obj, obj, oid); 189 get ((data_type) cftype<subclass>::dt, (subclass *)obj, obj, oid);
194 } 190 }
195 191
196 token get_token (); 192 token get_token ();
197 193
198 operator FILE *() { return fp; } 194 operator FILE *() { return fp; }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines