Debian Codegraph @

terps/tads/tads3/vmtzobj.h

raw symbols SCIP
1 /*
2 * Copyright (c) 2012 Michael J. Roberts. All Rights Reserved.
3 *
4 * Please see the accompanying license file, LICENSE.TXT, for information
5 * on using and copying this software.
6 */
7 /*
8 Name
9 vmtzobj.h - CVmObjTimeZone object
10 Function
11
12 Notes
13
14 Modified
15 02/06/12 MJRoberts - Creation
16 */
17
18 #ifndef VMTZOBJ_H
19 #define VMTZOBJ_H
20
21 #include "t3std.h"
22 #include "vmtype.h"
23 #include "vmglob.h"
24 #include "vmobj.h"
25 #include "vmundo.h"
26
27
28 /* ------------------------------------------------------------------------ */
29 /*
30 * The image file data simply contains the name of the time zone, as an
31 * ASCII string, with a one-byte length prefix. The block is arranged as
32 * follows:
33 *
34 *. UBYTE name_length
35 *. ASCII name
36 */
37
38
39 /* ------------------------------------------------------------------------ */
40 /*
41 * Our in-memory extension data structure.
42 */
43 struct vm_tzobj_ext
44 {
45 /* allocate the structure */
46 static vm_tzobj_ext *alloc_ext(VMG_ class CVmObjTimeZone *self,
47 class CVmTimeZone *tz);
48
49 /* our CVmTimeZone object */
50 class CVmTimeZone *tz;
51 };
52
53
54 /* ------------------------------------------------------------------------ */
55 /*
56 * CVmObjTimeZone intrinsic class definition
57 */
58
59 class CVmObjTimeZone: public CVmObject
60 {
61 friend class CVmMetaclassTimeZone;
62
63 public:
64 /* metaclass registration object */
65 static class CVmMetaclass *metaclass_reg_;
66 class CVmMetaclass *get_metaclass_reg() const { return metaclass_reg_; }
67
68 /* am I of the given metaclass? */
69 virtual int is_of_metaclass(class CVmMetaclass *meta) const
70 {
71 /* try my own metaclass and my base class */
72 return (meta == metaclass_reg_
73 || CVmObject::is_of_metaclass(meta));
74 }
75
76 /* get my CVmTimeZone object */
77 class CVmTimeZone *get_tz() const { return get_ext()->tz; }
78
79 /* is this a CVmObjTimeZone object? */
80 static int is_CVmObjTimeZone_obj(VMG_ vm_obj_id_t obj)
81 { return vm_objp(vmg_ obj)->is_of_metaclass(metaclass_reg_); }
82
83 /*
84 * Parse TimeZone constructor arguments, returning a CVmTimeZone cache
85 * object if the arguments match, throwing an error if not. Doesn't
86 * actually create a TimeZone object; simply finds the underlying cache
87 * object.
88 */
89 static class CVmTimeZone *parse_ctor_args(
90 VMG_ const vm_val_t *argp, int argc);
91
92 /* create dynamically using stack arguments */
93 static vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr,
94 uint argc);
95
96 /* create from a given CVmTimeZone object */
97 static vm_obj_id_t create(VMG_ class CVmTimeZone *tz);
98
99 /*
100 * call a static property - we don't have any of our own, so simply
101 * "inherit" the base class handling
102 */
103 static int call_stat_prop(VMG_ vm_val_t *result,
104 const uchar **pc_ptr, uint *argc,
105 vm_prop_id_t prop)
106 {
107 return CVmObject::
108 call_stat_prop(vmg_ result, pc_ptr, argc, prop);
109 }
110
111 /* notify of deletion */
112 void notify_delete(VMG_ int in_root_set);
113
114 /* set a property */
115 void set_prop(VMG_ class CVmUndo *undo,
116 vm_obj_id_t self, vm_prop_id_t prop, const vm_val_t *val);
117
118 /* get a property */
119 int get_prop(VMG_ vm_prop_id_t prop, vm_val_t *val,
120 vm_obj_id_t self, vm_obj_id_t *source_obj, uint *argc);
121
122 /*
123 * receive savepoint notification - we don't keep any
124 * savepoint-relative records, so we don't need to do anything here
125 */
126 void notify_new_savept() { }
127
128 /* we're immutable, so there's no undo to mess with */
129 void apply_undo(VMG_ struct CVmUndoRecord *) { }
130 void discard_undo(VMG_ struct CVmUndoRecord *) { }
131 void mark_undo_ref(VMG_ struct CVmUndoRecord *) { }
132
133 /* we have no outgoing references */
134 void mark_refs(VMG_ uint) { }
135 void remove_stale_weak_refs(VMG0_) { }
136 void remove_stale_undo_weak_ref(VMG_ struct CVmUndoRecord *) { }
137
138 /* load from an image file */
139 void load_from_image(VMG_ vm_obj_id_t self, const char *ptr, size_t siz);
140
141 /* reload from an image file */
142 void reload_from_image(VMG_ vm_obj_id_t self,
143 const char *ptr, size_t siz);
144
145 /* rebuild for image file */
146 virtual ulong rebuild_image(VMG_ char *buf, ulong buflen);
147
148 /* save to a file */
149 void save_to_file(VMG_ class CVmFile *fp);
150
151 /* restore from a file */
152 void restore_from_file(VMG_ vm_obj_id_t self,
153 class CVmFile *fp, class CVmObjFixup *fixups);
154
155 /* time zone objects are immutable */
156 int is_changed_since_load() const { return FALSE; }
157
158 /* cast to a string - returns the time zone name */
159 const char *cast_to_string(VMG_ vm_obj_id_t self, vm_val_t *newstr) const;
160
161 protected:
162 /* get my extension data */
163 vm_tzobj_ext *get_ext() const { return (vm_tzobj_ext *)ext_; }
164
165 /* load or reload image data */
166 void load_image_data(VMG_ vm_obj_id_t self, const char *ptr, size_t siz);
167
168 /* create a with no initial contents */
169 CVmObjTimeZone() { ext_ = 0; }
170
171 /* create with contents */
172 CVmObjTimeZone(VMG_ class CVmTimeZone *tz);
173
174 /*
175 * parse a zone name by GMT offset, specified as a string in +-hhmm or
176 * +-hh[:mm[:ss]] format, with the given prefix
177 */
178 static class CVmTimeZone *parse_zone_hhmmss(
179 VMG_ const char *prefix, const char *name, size_t len);
180
181 /* property evaluator - undefined function */
182 int getp_undef(VMG_ vm_obj_id_t, vm_val_t *, uint *) { return FALSE; }
183
184 /* getNames method */
185 int getp_getNames(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc);
186
187 /* getHistory method */
188 int getp_getHistory(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc);
189
190 /* getRules method */
191 int getp_getRules(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc);
192
193 /* getLocation method */
194 int getp_getLocation(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc);
195
196 /* property evaluation function table */
197 static int (CVmObjTimeZone::*func_table_[])(VMG_ vm_obj_id_t self,
198 vm_val_t *retval, uint *argc);
199 };
200
201
202 /* ------------------------------------------------------------------------ */
203 /*
204 * CVmObjTimeZone metaclass registration table object
205 */
206 class CVmMetaclassTimeZone: public CVmMetaclass
207 {
208 public:
209 /* get the global name */
210 const char *get_meta_name() const { return "timezone/030000"; }
211
212 /* create from image file */
213 void create_for_image_load(VMG_ vm_obj_id_t id)
214 {
215 new (vmg_ id) CVmObjTimeZone();
216 G_obj_table->set_obj_gc_characteristics(id, FALSE, FALSE);
217 }
218
219 /* create from restoring from saved state */
220 void create_for_restore(VMG_ vm_obj_id_t id)
221 {
222 new (vmg_ id) CVmObjTimeZone();
223 G_obj_table->set_obj_gc_characteristics(id, FALSE, FALSE);
224 }
225
226 /* create dynamically using stack arguments */
227 vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, uint argc)
228 { return CVmObjTimeZone::create_from_stack(vmg_ pc_ptr, argc); }
229
230 /* call a static property */
231 int call_stat_prop(VMG_ vm_val_t *result,
232 const uchar **pc_ptr, uint *argc,
233 vm_prop_id_t prop)
234 {
235 return CVmObjTimeZone::
236 call_stat_prop(vmg_ result, pc_ptr, argc, prop);
237 }
238 };
239
240 #endif /* VMTZOBJ_H */
241
242 /*
243 * Register the class
244 */
245 VM_REGISTER_METACLASS(CVmObjTimeZone)