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