|
|
1.1 paf 1: /*
1.5 ! paf 2: $Id: pa_vobject.h,v 1.4 2001/02/25 08:50:12 paf Exp $
1.1 paf 3: */
4:
5: #ifndef PA_VOBJECT_H
6: #define PA_VOBJECT_H
7:
8: #include "pa_value.h"
9: #include "pa_vjunction.h"
1.4 paf 10:
1.1 paf 11: class VObject : public Value {
12: public: // Value
13:
14: // all: for error reporting after fail(), etc
15: const char *type() const { return "Object"; }
16:
1.4 paf 17: // object_instance: (field)=value;(CLASS)=vclass;(method)=method_ref
1.1 paf 18: Value *get_element(const String& name) {
1.4 paf 19: // $CLASS=my class
20: if(name==CLASS_NAME)
21: return &vclass;
1.1 paf 22:
23: // $method=junction(this+method)
1.3 paf 24: if(Method *method=static_cast<Method *>(vclass.methods().get(name))) {
1.1 paf 25: Junction& j=*NEW Junction(pool(),
26: *this,
27: method,0,0,0,0);
28:
29: return NEW VJunction(j);
30: }
31:
32: // $field=fields.field
33: return static_cast<Value *>(fields.get(name));
34: }
35:
36: // object_instance: (field)=value
37: void put_element(const String& name, Value *value) {
38: // speed1:
1.4 paf 39: // will not check for '$CLASS(subst)' trick
1.1 paf 40: // will hope that user ain't THAT self-hating person
41: // speed2:
42: // will not check for '$method_name(subst)' trick
43: // -same-
44:
45: fields.put(name, value);
46: }
47:
48: // object_class, object_instance: object_class
49: VClass *get_class() { return &vclass; }
50:
51: public: // creation
52:
53: VObject(Pool& apool, VClass& vclass) :
54: Value(apool),
55: vclass(vclass),
56: fields(apool) {
57: }
58:
59: private:
60:
61: VClass& vclass;
62: Hash fields;
63: };
64:
65: #endif