4
* Copyright (c) 2000, 2002 Michael J. Roberts. All Rights Reserved.
6
* Please see the accompanying license file, LICENSE.TXT, for information
7
* on using and copying this software.
11
vmcoll.h - T3 Collection base class
13
A Collection is the base class for List, Array, and other objects
14
providing a collection of objects that can be iterated via an
17
Collection is an abstract base class: it cannot be instantiated, and
18
thus has no image-file or state-file representation.
22
04/22/00 MJRoberts - Creation
36
class CVmObjCollection: public CVmObject
38
friend class CVmMetaclassCollection;
41
/* metaclass registration object */
42
static class CVmMetaclass *metaclass_reg_;
43
class CVmMetaclass *get_metaclass_reg() const { return metaclass_reg_; }
45
/* am I of the given metaclass? */
46
virtual int is_of_metaclass(class CVmMetaclass *meta) const
48
/* try my own metaclass and my base class */
49
return (meta == metaclass_reg_
50
|| CVmObject::is_of_metaclass(meta));
54
* call a static property - we don't have any of our own, so simply
55
* "inherit" the base class handling
57
static int call_stat_prop(VMG_ vm_val_t *result,
58
const uchar **pc_ptr, uint *argc,
60
{ return CVmObject::call_stat_prop(vmg_ result, pc_ptr, argc, prop); }
63
int get_prop(VMG_ vm_prop_id_t prop, vm_val_t *retval,
64
vm_obj_id_t self, vm_obj_id_t *source_obj, uint *argc);
67
* constant value property evaluator - this allows us to evaluate a
68
* property for an object value or for a constant value using the
71
int const_get_coll_prop(VMG_ vm_prop_id_t prop, vm_val_t *retval,
72
const vm_val_t *self_val, vm_obj_id_t *src_obj,
77
* Create an iterator for this collection. Fills in *retval with a
78
* reference to the new iterator object. This iterator must refer
79
* to an immutable snapshot of the collection.
81
virtual void new_iterator(VMG_ vm_val_t *retval,
82
const vm_val_t *self_val) = 0;
85
* Create a "live" iterator for this collection. Fills in *retval
86
* with a reference to the new iterator object. This iterator must
87
* refer to the original "live" collection.
89
virtual void new_live_iterator(VMG_ vm_val_t *retval,
90
const vm_val_t *self_val) = 0;
92
/* property evaluator - undefined property */
93
int getp_undef(VMG_ vm_val_t *, const vm_val_t *, uint *)
96
/* property evaluator - create iterator */
97
int getp_create_iter(VMG_ vm_val_t *retval, const vm_val_t *self_val,
100
/* property evaluator - create live iterator */
101
int getp_create_live_iter(VMG_ vm_val_t *retval,
102
const vm_val_t *self_val, uint *argc);
104
/* property evaluation function table */
105
static int (CVmObjCollection::*func_table_[])(VMG_ vm_val_t *retval,
106
const vm_val_t *self_val, uint *argc);
110
/* ------------------------------------------------------------------------ */
112
* Registration table object
114
class CVmMetaclassCollection: public CVmMetaclass
117
/* get the global name */
118
const char *get_meta_name() const { return "collection/030000"; }
120
/* create from image file */
121
void create_for_image_load(VMG_ vm_obj_id_t id)
122
{ err_throw(VMERR_BAD_STATIC_NEW); }
124
/* create from restoring from saved state */
125
void create_for_restore(VMG_ vm_obj_id_t id)
126
{ err_throw(VMERR_BAD_STATIC_NEW); }
128
/* create dynamically using stack arguments */
129
vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, uint argc)
131
err_throw(VMERR_BAD_DYNAMIC_NEW);
132
AFTER_ERR_THROW(return VM_INVALID_OBJ;)
135
/* call a static property */
136
int call_stat_prop(VMG_ vm_val_t *result,
137
const uchar **pc_ptr, uint *argc,
140
return CVmObjCollection::
141
call_stat_prop(vmg_ result, pc_ptr, argc, prop);
145
#endif /* VMCOLL_H */
150
VM_REGISTER_METACLASS(CVmObjCollection)