1 | /*****************************************************************************/ |
|
|
2 | /* CrossFire, A roguelike realtime multiplayer game */ |
|
|
3 | /*****************************************************************************/ |
|
|
4 | |
|
|
5 | /* |
1 | /* |
6 | * This code is placed under the GNU General Public Licence (GPL) |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
7 | * |
3 | * |
8 | * Copyright (C) 2006 by Marc Lehmann <crossfire@schmorp.de> |
4 | * Copyright (©) 2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
9 | * |
5 | * |
10 | * This program is free software; you can redistribute it and/or modify |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
11 | * it under the terms of the GNU General Public License as published by |
7 | * the terms of the Affero GNU General Public License as published by the |
12 | * the Free Software Foundation; either version 2 of the License, or |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
13 | * (at your option) any later version. |
9 | * option) any later version. |
14 | * |
10 | * |
15 | * This program is distributed in the hope that it will be useful, |
11 | * This program is distributed in the hope that it will be useful, |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | * GNU General Public License for more details. |
14 | * GNU General Public License for more details. |
19 | * |
15 | * |
20 | * You should have received a copy of the GNU General Public License |
16 | * You should have received a copy of the Affero GNU General Public License |
21 | * along with this program; if not, write to the Free Software |
17 | * and the GNU General Public License along with this program. If not, see |
22 | * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
18 | * <http://www.gnu.org/licenses/>. |
|
|
19 | * |
|
|
20 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
21 | */ |
24 | |
22 | |
25 | #include "global.h" // bug in cfperl.h, doesn't include interface_class stuff |
23 | #include "global.h" // bug in cfperl.h, doesn't include interface_class stuff |
26 | #include "logger.h" |
24 | #include "logger.h" |
27 | #include "cfperl.h" |
25 | #include "cfperl.h" |
28 | #include "kw_hash.h" |
26 | #include "kw_hash.h" |
29 | |
27 | |
30 | object_freezer::object_freezer () |
28 | object_freezer::object_freezer () |
31 | : dynbuf (128 * 1024, 64 * 1024) |
29 | : dynbuf_text (128 * 1024, 64 * 1024) |
32 | { |
30 | { |
33 | av = newAV (); |
31 | av = newAV (); |
34 | } |
32 | } |
35 | |
33 | |
36 | object_freezer::~object_freezer () |
34 | object_freezer::~object_freezer () |
37 | { |
35 | { |
38 | SvREFCNT_dec (av); |
36 | SvREFCNT_dec (av); |
39 | } |
37 | } |
40 | |
38 | |
41 | void |
39 | void |
42 | object_freezer::put (attachable *ext) |
40 | object_freezer::put_ (attachable *ext) |
43 | { |
41 | { |
44 | ext->optimise (); |
42 | ext->optimise (); |
45 | |
43 | |
46 | if (ext->self) |
44 | if (ext->self) |
47 | { |
45 | { |
48 | int idx = AvFILLp ((AV *)av) + 1; |
46 | int idx = AvFILLp ((AV *)av) + 1; |
49 | av_store (av, idx, newRV_inc ((SV *)ext->self)); |
47 | av_store (av, idx, newRV_inc ((SV *)ext->self)); |
50 | |
48 | |
51 | add ((void *)"oid ", 4); |
49 | put (KW(oid), sint32(idx)); |
52 | add ((sint32)idx); |
|
|
53 | add ('\n'); |
|
|
54 | } |
50 | } |
55 | } |
51 | } |
56 | |
52 | |
57 | // XXX: function not returning a bool |
|
|
58 | bool |
53 | bool |
59 | object_freezer::save (const char *path) |
54 | object_freezer::save (const char *path) |
60 | { |
55 | { |
61 | CALL_BEGIN (3); |
56 | CALL_BEGIN (3); |
62 | CALL_ARG_SV (newSVpv (path, 0)); |
57 | CALL_ARG_SV (newSVpv (path, 0)); |
63 | CALL_ARG_SV (newRV_noinc (newSVpvn ((char *)linearise (), size ()))); |
58 | CALL_ARG_SV (newRV_noinc (newSVpvn ((char *)linearise (), size ()))); |
64 | CALL_ARG_SV (newRV_inc ((SV *)av)); |
59 | CALL_ARG_SV (newRV_inc ((SV *)av)); |
65 | CALL_CALL ("cf::object_freezer_save", G_VOID | G_DISCARD); |
60 | CALL_CALL ("cf::object_freezer_save", G_VOID | G_DISCARD); |
66 | CALL_END; |
61 | CALL_END; |
|
|
62 | |
|
|
63 | return 1; |
67 | } |
64 | } |
68 | |
65 | |
69 | char * |
66 | char * |
70 | object_freezer::as_string () |
67 | object_freezer::as_string () |
71 | { |
68 | { |
… | |
… | |
81 | CALL_END; |
78 | CALL_END; |
82 | |
79 | |
83 | return res; |
80 | return res; |
84 | } |
81 | } |
85 | |
82 | |
86 | // XXX: function not returning an int |
83 | #if 0 |
87 | int |
84 | void |
88 | fprintf (object_freezer &freezer, const char *format, ...) |
85 | fprintf (object_freezer &freezer, const char *format, ...) |
89 | { |
86 | { |
90 | va_list ap; |
87 | va_list ap; |
91 | |
88 | |
92 | va_start (ap, format); |
89 | va_start (ap, format); |
… | |
… | |
98 | |
95 | |
99 | va_end (ap); |
96 | va_end (ap); |
100 | } |
97 | } |
101 | |
98 | |
102 | // XXX: function not returning an int |
99 | // XXX: function not returning an int |
103 | int |
100 | void |
104 | fputs (const char *s, object_freezer &freezer) |
101 | fputs (const char *s, object_freezer &freezer) |
105 | { |
102 | { |
106 | freezer.add (s); |
103 | freezer.add (s); |
107 | } |
104 | } |
|
|
105 | #endif |
108 | |
106 | |
109 | static const char thawer_eof[] = "\n\n\n\0\0\0"; |
107 | static const char thawer_eof[] = "\n\n\n\0\0\0"; |
110 | |
108 | |
|
|
109 | bool object_thawer::errors_are_fatal = true; |
|
|
110 | |
111 | object_thawer::object_thawer (const char *path) |
111 | object_thawer::object_thawer (const char *data, AV *perlav) |
|
|
112 | : name (strdup ("(memory stream)")) |
|
|
113 | { |
|
|
114 | init ("(memory stream)"); |
|
|
115 | |
|
|
116 | av = perlav; |
|
|
117 | text = newSVpv (data, 0); sv_catpv (text, thawer_eof); |
|
|
118 | line = SvPVbyte_nolen (text); |
|
|
119 | next (); |
|
|
120 | } |
|
|
121 | |
|
|
122 | object_thawer::object_thawer (const_utf8_string path) |
|
|
123 | { |
|
|
124 | init_from_file (path); |
|
|
125 | } |
|
|
126 | |
|
|
127 | // convenience constructor |
|
|
128 | object_thawer::object_thawer (const_utf8_string dir, const_utf8_string file) |
|
|
129 | { |
|
|
130 | init_from_file (format ("%s/%s", dir, file)); |
|
|
131 | } |
|
|
132 | |
|
|
133 | void |
|
|
134 | object_thawer::init (const_utf8_string path) |
|
|
135 | { |
112 | : name (strdup (path)) |
136 | name = strdup (path); |
113 | { |
|
|
114 | static const char eof[] = "\n\n\n\0\0\0"; |
|
|
115 | |
|
|
116 | av = 0; |
137 | av = 0; |
117 | text = 0; |
138 | text = 0; |
118 | line = 0; |
139 | line = 0; |
119 | linenum = 0; |
140 | linenum = 0; |
120 | |
141 | |
121 | kw = KW_ERROR; |
142 | kw = KW_ERROR; |
122 | kw_str = 0; |
143 | kw_str = 0; |
123 | value = 0; |
144 | value = 0; |
|
|
145 | } |
124 | |
146 | |
|
|
147 | void |
|
|
148 | object_thawer::init_from_file (const_utf8_string path) |
|
|
149 | { |
125 | if (path) |
150 | init (path); |
126 | { |
151 | |
127 | CALL_BEGIN (1); |
152 | CALL_BEGIN (1); |
128 | CALL_ARG_SV (newSVpv (path, 0)); |
153 | CALL_ARG_SV (newSVpv (path, 0)); |
129 | CALL_CALL ("cf::object_thawer_load", G_ARRAY); |
154 | CALL_CALL ("cf::object_thawer_load", G_ARRAY); |
130 | |
155 | |
131 | if (count == 2) |
156 | if (count == 2) |
132 | { |
157 | { |
133 | // second value - perl objects |
158 | // second value - perl objects |
134 | { |
159 | { |
135 | SV *sv = POPs; |
160 | SV *sv = POPs; |
136 | if (SvROK (sv)) |
161 | if (SvROK (sv)) |
137 | av = (AV *)SvREFCNT_inc (SvRV (sv)); |
162 | av = (AV *)SvREFCNT_inc (SvRV (sv)); |
138 | } |
163 | } |
139 | |
164 | |
140 | // first value - text part, pad with 3 zeroes |
165 | // first value - text part, pad with 3 zeroes |
141 | { |
166 | { |
142 | SV *sv = POPs; |
167 | SV *sv = POPs; |
143 | STRLEN len; |
168 | STRLEN len; |
144 | char *sv_ = SvPVbyte (sv, len); |
169 | char *sv_ = SvPVbyte (sv, len); |
145 | text = newSV (len + sizeof (eof)); |
170 | text = newSV (len + sizeof (thawer_eof)); |
146 | SvCUR_set (text, len); |
171 | SvCUR_set (text, len + sizeof (thawer_eof)); |
147 | memcpy (SvPVX (text), sv_, len); |
172 | memcpy (SvPVX (text), sv_, len); |
148 | memcpy (SvEND (text), eof, sizeof (eof)); // just to be sure |
173 | memcpy (SvPVX (text) + len, thawer_eof, sizeof (thawer_eof)); |
149 | |
174 | |
150 | line = SvPVX (text); |
175 | line = SvPVX (text); |
151 | } |
176 | next (); |
152 | } |
177 | } |
|
|
178 | } |
153 | |
179 | |
154 | CALL_END; |
180 | CALL_END; |
155 | } |
|
|
156 | } |
|
|
157 | |
|
|
158 | object_thawer::object_thawer (const char *data, AV *perlav) |
|
|
159 | : name (strdup ("(memory stream")) |
|
|
160 | { |
|
|
161 | av = perlav; |
|
|
162 | text = newSVpv (data, 0); |
|
|
163 | sv_catpv (text, thawer_eof); |
|
|
164 | line = SvPVbyte_nolen (text); |
|
|
165 | } |
181 | } |
166 | |
182 | |
167 | void |
183 | void |
168 | object_thawer::get (attachable *obj, int oid) |
184 | object_thawer::get (attachable *obj, int oid) |
169 | { |
185 | { |
… | |
… | |
172 | |
188 | |
173 | SV **svp = av_fetch ((AV *)av, oid, 0); |
189 | SV **svp = av_fetch ((AV *)av, oid, 0); |
174 | |
190 | |
175 | if (!svp || !SvROK (*svp)) |
191 | if (!svp || !SvROK (*svp)) |
176 | { |
192 | { |
177 | printf ("trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid); |
193 | LOG (llevError, "trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid); |
178 | return; |
194 | return; |
179 | } |
195 | } |
180 | |
196 | |
181 | if (!SvROK (*svp)) |
197 | if (!SvROK (*svp)) |
182 | { |
198 | { |
183 | LOG (llevError, "deserialised perl object is not an RV"); |
199 | LOG (llevError, "deserialised perl object is not an RV\n"); |
184 | return; |
200 | return; |
185 | } |
201 | } |
186 | |
202 | |
187 | HV *hv = (HV *)SvRV (*svp); |
203 | HV *hv = (HV *)SvRV (*svp); |
188 | |
204 | |
189 | if (SvTYPE (hv) != SVt_PVHV) |
205 | if (SvTYPE (hv) != SVt_PVHV) |
190 | { |
206 | { |
191 | LOG (llevError, "deserialised perl object is not a PVHV"); |
207 | LOG (llevError, "deserialised perl object is not a PVHV\n"); |
192 | return; |
208 | return; |
193 | } |
209 | } |
194 | |
210 | |
195 | if (obj->self) |
211 | if (obj->self) |
196 | { |
212 | { |
… | |
… | |
220 | object_thawer::~object_thawer () |
236 | object_thawer::~object_thawer () |
221 | { |
237 | { |
222 | if (text) SvREFCNT_dec (text); |
238 | if (text) SvREFCNT_dec (text); |
223 | if (av) SvREFCNT_dec (av); |
239 | if (av) SvREFCNT_dec (av); |
224 | |
240 | |
|
|
241 | resolve_delayed_derefs (false); |
|
|
242 | |
225 | free ((void *)name); |
243 | free ((void *)name); |
226 | } |
244 | } |
227 | |
245 | |
228 | //TODO: remove |
246 | static void |
229 | char * |
247 | error_out () |
230 | fgets (char *s, int n, object_thawer &thawer) |
|
|
231 | { |
248 | { |
232 | char *p = thawer.line; |
249 | if (object_thawer::errors_are_fatal) |
233 | char *q = s; |
|
|
234 | |
|
|
235 | if (!p) |
|
|
236 | return 0; |
|
|
237 | |
|
|
238 | while (--n) |
|
|
239 | { |
|
|
240 | if (!*p) |
|
|
241 | break; |
|
|
242 | |
|
|
243 | *q++ = *p; |
|
|
244 | |
|
|
245 | if (*p++ == '\n') |
|
|
246 | { |
|
|
247 | ++thawer.linenum; |
|
|
248 | break; |
|
|
249 | } |
|
|
250 | } |
250 | { |
|
|
251 | LOG (llevError, "(parse errors at this time are fatal, exiting)"); |
|
|
252 | exit (1); |
|
|
253 | } |
|
|
254 | } |
251 | |
255 | |
252 | *q = 0; |
256 | void |
253 | thawer.line = p; |
257 | object_thawer::parse_warn (const char *msg) const |
254 | |
258 | { |
255 | return s == q ? 0 : s; |
259 | LOG (llevWarn, "%s:%d, \"%s %s\": %s\n", |
|
|
260 | this->name, linenum, |
|
|
261 | kw_str ? kw_str : "<null>", |
|
|
262 | value ? value : "<null>", |
|
|
263 | msg); |
256 | } |
264 | } |
257 | |
265 | |
258 | bool |
266 | bool |
259 | object_thawer::parse_error (const char *type, const char *name, bool skip) |
267 | object_thawer::parse_error (const char *type, const char *name, bool skip) const |
260 | { |
268 | { |
261 | if (!type) type = "file section"; |
269 | if (!type) type = "file section"; |
262 | if (!name) name = "generic"; |
270 | if (!name) name = "generic"; |
263 | |
271 | |
264 | switch (kw) |
272 | switch (kw) |
265 | { |
273 | { |
266 | case KW_EOF: |
274 | case KW_EOF: |
267 | LOG (llevError, "%s:%d end of file while reading %s '%s', aborting load.\n", |
275 | LOG (llevError, "%s:%d end of file while reading %s '%s', aborting load.\n", |
268 | this->name, linenum, type, name); |
276 | this->name, linenum, type, name); |
|
|
277 | error_out (); |
269 | return false; |
278 | return false; |
270 | |
279 | |
271 | case KW_ERROR: |
280 | case KW_ERROR: |
272 | LOG (llevError, "%s:%d error while reading %s '%s', at '%s', aborting load.\n", |
281 | LOG (llevError, "%s:%d error while reading %s '%s', at '%s', aborting load.\n", |
273 | this->name, linenum, |
282 | this->name, linenum, |
274 | type, name, |
283 | type, name, |
275 | kw_str ? kw_str : "<file load>"); |
284 | kw_str ? kw_str : "<file load>"); |
|
|
285 | error_out (); |
276 | return false; |
286 | return false; |
277 | |
287 | |
278 | default: |
288 | default: |
279 | LOG (llevError, "%s:%d unexpected line (%s %s) while reading %s '%s', %s.\n", |
289 | LOG (llevError, "%s:%d unexpected line (%s %s) while reading %s '%s', %s.\n", |
280 | this->name, linenum, |
290 | this->name, linenum, |
281 | kw_str ? kw_str : "<null>", |
291 | kw_str ? kw_str : "<null>", |
282 | value ? value : "<null>", |
292 | value ? value : "<null>", |
283 | type, name, |
293 | type, name, |
284 | skip ? "skipping line" : "aborting load"); |
294 | skip ? "skipping line" : "aborting load"); |
|
|
295 | error_out (); |
285 | return skip; |
296 | return skip; |
286 | } |
297 | } |
287 | } |
298 | } |
288 | |
299 | |
289 | void |
300 | void |
… | |
… | |
296 | } |
307 | } |
297 | |
308 | |
298 | for (;;) |
309 | for (;;) |
299 | { |
310 | { |
300 | char *p = line; |
311 | char *p = line; |
|
|
312 | |
|
|
313 | if (expect_false (*p <= ' ')) |
|
|
314 | { |
|
|
315 | // skip whitespace (only some files need this) |
|
|
316 | while (*p == ' ' || *p == '\t') |
|
|
317 | p++; |
|
|
318 | |
|
|
319 | line = p; |
|
|
320 | } |
301 | |
321 | |
302 | if (!*p) |
322 | if (!*p) |
303 | { |
323 | { |
304 | kw = KW_EOF; |
324 | kw = KW_EOF; |
305 | break; |
325 | break; |
… | |
… | |
309 | while (*p > ' ') |
329 | while (*p > ' ') |
310 | p++; |
330 | p++; |
311 | |
331 | |
312 | int klen = p - line; |
332 | int klen = p - line; |
313 | |
333 | |
|
|
334 | value_nn = ""; |
|
|
335 | value = 0; |
|
|
336 | |
314 | if (*p++ != '\n') |
337 | if (*p++ != '\n') |
315 | { |
338 | { |
316 | // parse value |
339 | // parse value |
317 | while (*(unsigned char *)p <= ' ' && *p != '\n') // skip 0x01 .. 0x20 |
340 | while (*(unsigned char *)p <= ' ' && *p != '\n') |
318 | ++p; |
341 | ++p; |
319 | |
342 | |
320 | value = p; |
343 | value_nn = value = p; |
321 | |
344 | |
322 | while (*p != '\n') |
345 | while (*p != '\n') |
323 | p++; |
346 | p++; |
324 | |
347 | |
325 | *p++ = 0; |
348 | *p++ = 0; |
326 | } |
349 | } |
327 | else |
|
|
328 | value = 0; |
|
|
329 | |
350 | |
330 | ++linenum; |
351 | ++linenum; |
331 | line [klen] = 0; |
352 | line [klen] = 0; |
332 | keyword_idx *kw_idx = kw_lex::match (line, klen); |
353 | keyword_idx *kw_idx = kw_lex::match (line, klen); |
333 | |
354 | |
334 | //printf ("KV %d<%s,%s>\n", kw ? kw->index : 0, line, value);//D |
|
|
335 | |
|
|
336 | kw_str = line; |
355 | kw_str = line; |
337 | line = p; |
356 | line = p; |
338 | |
357 | |
339 | if (kw_idx) |
358 | if (kw_idx) |
340 | { |
359 | { |
… | |
… | |
349 | break; |
368 | break; |
350 | } |
369 | } |
351 | } |
370 | } |
352 | } |
371 | } |
353 | |
372 | |
|
|
373 | bool |
|
|
374 | object_thawer::next_line () |
|
|
375 | { |
|
|
376 | if (!line) |
|
|
377 | { |
|
|
378 | kw = KW_ERROR; |
|
|
379 | return 0; |
|
|
380 | } |
|
|
381 | |
|
|
382 | for (;;) |
|
|
383 | { |
|
|
384 | char *p = line; |
|
|
385 | |
|
|
386 | if (expect_false (*p <= ' ')) |
|
|
387 | { |
|
|
388 | // skip whitespace (only some files need this) |
|
|
389 | while (*p == ' ' || *p == '\t') |
|
|
390 | p++; |
|
|
391 | |
|
|
392 | line = p; |
|
|
393 | } |
|
|
394 | |
|
|
395 | if (!*p) |
|
|
396 | { |
|
|
397 | kw = KW_EOF; |
|
|
398 | return 0; |
|
|
399 | } |
|
|
400 | |
|
|
401 | kw = KW_value; |
|
|
402 | kw_str = p; |
|
|
403 | value_nn = p; |
|
|
404 | value = p; |
|
|
405 | |
|
|
406 | // parse till newline |
|
|
407 | while (*p > '\n') |
|
|
408 | p++; |
|
|
409 | |
|
|
410 | if (*p == '\n') |
|
|
411 | *p++ = 0; |
|
|
412 | |
|
|
413 | ++linenum; |
|
|
414 | |
|
|
415 | line = p; |
|
|
416 | |
|
|
417 | if (*kw_str && *kw_str != '#') |
|
|
418 | break; |
|
|
419 | |
|
|
420 | // empty/comment line -> skip it |
|
|
421 | } |
|
|
422 | |
|
|
423 | return 1; |
|
|
424 | } |
|
|
425 | |
354 | void |
426 | void |
355 | object_thawer::skip () |
427 | object_thawer::skip () |
356 | { |
428 | { |
357 | shstr ml; |
429 | shstr ml; |
358 | |
430 | |
359 | switch (kw) |
431 | switch (kw) |
360 | { |
432 | { |
361 | case KW_msg: get_ml (KW_endmsg , ml); break; |
433 | case KW_msg: get_ml (KW_endmsg , ml); break; |
362 | case KW_lore: get_ml (KW_endlore , ml); break; |
434 | case KW_lore: get_ml (KW_endlore , ml); break; |
363 | case KW_maplore: get_ml (KW_endmaplore, ml); break; |
435 | case KW_maplore: get_ml (KW_endmaplore, ml); break; |
|
|
436 | default: break; |
364 | } |
437 | } |
365 | |
438 | |
366 | next (); |
439 | next (); |
367 | } |
440 | } |
368 | |
441 | |
369 | void |
442 | void |
370 | object_thawer::get (shstr &sh) const |
443 | object_thawer::skip_block () |
371 | { |
444 | { |
372 | if (value) |
445 | // must not stop at KW_ERROR, as those signify custom keys |
373 | sh = value; |
446 | while (kw != KW_EOF) |
374 | else |
|
|
375 | { |
447 | { |
376 | sh = "<value missing>"; |
448 | keyword w = kw; |
377 | LOG (llevError, "keyword \"%s\" requires value, substituting with <value missing>\n", kw_str);//TODO: add filename |
449 | skip (); |
|
|
450 | |
|
|
451 | if (0 && (w == KW_map || w == KW_arch || w == KW_object || w == KW_region)) |
|
|
452 | skip_block (); |
|
|
453 | else if (w == KW_end) |
|
|
454 | break; |
378 | } |
455 | } |
379 | } |
456 | } |
380 | |
457 | |
381 | void |
458 | void |
382 | object_thawer::get_ml (keyword kend, shstr &sh) |
459 | object_thawer::get_ml (keyword kend, shstr &sh) |
… | |
… | |
430 | } |
507 | } |
431 | |
508 | |
432 | sint32 |
509 | sint32 |
433 | object_thawer::get_sint32 () const |
510 | object_thawer::get_sint32 () const |
434 | { |
511 | { |
435 | char *p = value; |
512 | const char *p = value_nn; |
436 | |
|
|
437 | if (!p) |
|
|
438 | return 0; |
|
|
439 | |
513 | |
440 | sint32 val = 0; |
514 | sint32 val = 0; |
441 | bool negate; |
515 | bool negate; |
442 | |
516 | |
443 | if (*p == '-') |
517 | if (*p == '-') |
… | |
… | |
456 | while (*p); |
530 | while (*p); |
457 | |
531 | |
458 | return negate ? -val : val; |
532 | return negate ? -val : val; |
459 | } |
533 | } |
460 | |
534 | |
461 | sint64 |
535 | void |
462 | object_thawer::get_sint64 () const |
536 | object_thawer::delayed_deref (attachable *op, object_ptr &ptr, const char *ref) |
463 | { |
537 | { |
464 | return value ? atoll (value) : 0; |
538 | op->refcnt_inc (); |
|
|
539 | delayed_ref r = { op, &ptr, ref ? strdup (ref) : 0 }; |
|
|
540 | delrefs.push_back (r); |
|
|
541 | ptr = 0; |
465 | } |
542 | } |
466 | |
543 | |
467 | double |
544 | void |
468 | object_thawer::get_double () const |
545 | object_thawer::resolve_delayed_derefs (bool deref) |
469 | { |
546 | { |
470 | return value ? atof (value) : 0; |
547 | while (!delrefs.empty ()) |
471 | } |
548 | { |
|
|
549 | delayed_ref r = delrefs.back (); |
|
|
550 | delrefs.pop_back (); |
472 | |
551 | |
|
|
552 | if (deref) |
|
|
553 | *r.ptr = object::deref (r.ref); |
|
|
554 | |
|
|
555 | free ((void *)r.ref); |
|
|
556 | r.op->refcnt_dec (); |
|
|
557 | } |
|
|
558 | } |