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.16 by root, Wed Aug 30 16:30:37 2006 UTC vs.
Revision 1.17 by root, Thu Aug 31 06:23:19 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"
13 15
14// optimisations/workaround for functions requiring my_perl in scope (anti-bloat) 16// optimisations/workaround for functions requiring my_perl in scope (anti-bloat)
15#undef localtime 17#undef localtime
16#undef srand48 18#undef srand48
17#undef drand48 19#undef drand48
104bool cfperl_invoke (event_type event, ...); 106bool cfperl_invoke (event_type event, ...);
105int cfperl_result_INT (int idx); 107int cfperl_result_INT (int idx);
106 108
107struct attachable_base 109struct attachable_base
108{ 110{
109 struct sv *self; 111 SV *self;
110 struct av *cb; // CF+ perl self and callback 112 AV *cb; // CF+ perl self and callback
111 const char *attach; // generic extension attachment information 113 const char *attach; // generic extension attachment information
112 114
113 void clear (); // called when free'ing objects 115 void clear (); // called when free'ing objects
114 void optimise (); // possibly save some memory by destroying unneeded data 116 void optimise (); // possibly save some memory by destroying unneeded data
115 void instantiate (data_type type, void *obj); 117 void instantiate (data_type type, void *obj);
138 if (attach) 140 if (attach)
139 attachable_base::instantiate (get_dt (), static_cast<subclass *>(this)); 141 attachable_base::instantiate (get_dt (), static_cast<subclass *>(this));
140 } 142 }
141}; 143};
142 144
143struct object_freezethaw 145struct object_freezer
144{ 146{
145 struct av *av; 147 AV *av;
146}; 148 SV *text;
147 149
148struct object_freezer : object_freezethaw 150 object_freezer ();
149{
150 struct sv *text;
151 void *filename;
152
153 object_freezer (const char *filename);
154 ~object_freezer (); 151 ~object_freezer ();
155 152
156 void put (attachable_base *ext); 153 void put (attachable_base *ext);
157 154
158 template<class subclass> 155 template<class subclass>
159 void put (attachable<subclass> *obj) 156 void put (attachable<subclass> *obj)
160 { 157 {
161 put ((attachable_base *)obj); 158 put ((attachable_base *)obj);
162 } 159 }
163 160
161 bool save (const char *filename);
162
164 operator bool () { return !!av; } 163 operator bool () { return !!av; }
165};
166
167struct object_thawer : object_freezethaw
168{
169 FILE *fp;
170
171 object_thawer (const char *filename = 0);
172 ~object_thawer ();
173
174 void get (data_type type, void *obj, attachable_base *ext, int oid);
175
176 template<class subclass>
177 void get (attachable<subclass> *obj, int oid)
178 {
179 if (av)
180 get (subclass::get_dt (), (subclass *)obj, obj, oid);
181 }
182
183 operator FILE *() { return fp; }
184}; 164};
185 165
186// compatibility support, should be removed when no longer needed 166// compatibility support, should be removed when no longer needed
187int fprintf (object_freezer &freezer, const char *format, ...); 167int fprintf (object_freezer &freezer, const char *format, ...);
188int fputs (const char *s, object_freezer &freezer); 168int fputs (const char *s, object_freezer &freezer);
189 169
170// a single key-value line from a file
171struct token {
172 keyword k;
173 const char *v;
174
175 token (keyword k, const char *v = 0) : k(k), v(v) { }
176};
177
178struct object_thawer
179{
180 AV *av;
181 FILE *fp;
182 char line[1024];
183
184 object_thawer (const char *filename = 0);
185 ~object_thawer ();
186
187 void get (data_type type, void *obj, attachable_base *ext, int oid);
188
189 template<class subclass>
190 void get (attachable<subclass> *obj, int oid)
191 {
192 if (av)
193 get (subclass::get_dt (), (subclass *)obj, obj, oid);
194 }
195
196 token get_token ();
197
198 operator FILE *() { return fp; }
199};
200
190#endif 201#endif
191 202

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines