Annotation of parser3/src/types/pa_wcontext.h, revision 1.30
1.12 paf 1: /** @file
2: Parser: write context class decl.
3:
1.26 paf 4: Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
1.27 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1 paf 6:
1.30 ! paf 7: $Id: pa_wcontext.h,v 1.29 2002/04/15 10:35:22 paf Exp $
1.1 paf 8: */
9:
10: #ifndef PA_WCONTEXT_H
11: #define PA_WCONTEXT_H
12:
13: #include "pa_value.h"
14: #include "pa_vstring.h"
15: #include "pa_vhash.h"
16:
17: class Request;
18:
1.29 paf 19: class StringOrValue {
20: public:
21: StringOrValue() : fstring(0), fvalue(0) {}
22: /// anticipating either String or Value [must not be 0&0]
1.30 ! paf 23: StringOrValue(const String *astring, Value *avalue) : fstring(astring), fvalue(avalue) {}
! 24: void set_string(const String& astring) { fstring=&astring; }
1.29 paf 25: void set_value(Value& avalue) { fvalue=&avalue; }
26: Value& as_value() const {
27: return *(fvalue?fvalue:new(fstring->pool()) VString(*fstring));
28: }
29: const String& as_string() const {
30: return fstring?*fstring:fvalue->as_string();
31: }
32: private:
1.30 ! paf 33: const String *fstring;
1.29 paf 34: Value *fvalue;
35: };
36:
1.12 paf 37: /** Write context
38: they do different write()s here, later picking up the result
39: @see Request::wcontext
40: */
1.1 paf 41: class WContext : public Value {
1.18 paf 42: friend class Request;
1.19 paf 43:
1.1 paf 44: public: // Value
45:
46: const char *type() const { return "wcontext"; }
1.12 paf 47: /// WContext: accumulated fstring
1.1 paf 48: const String *get_string() { return &fstring; };
49:
1.12 paf 50: /// WContext: none yet | transparent
1.5 paf 51: VStateless_class *get_class() { return fvalue?fvalue->get_class():0; }
1.12 paf 52: /// WContext: transparent
1.1 paf 53: VAliased *get_aliased() { return fvalue?fvalue->get_aliased():0; }
54:
55: public: // WContext
56:
1.12 paf 57: /// appends a fstring to result
1.22 paf 58: virtual void write(const String& astring, uchar lang);
1.6 paf 59:
1.12 paf 60: /// writes Value; raises an error if already
1.6 paf 61: virtual void write(Value& avalue);
1.1 paf 62:
1.12 paf 63: /**
64: if value is VString writes fstring,
65: else writes Value; raises an error if already
66: */
1.22 paf 67: virtual void write(Value& avalue, uchar lang);
1.1 paf 68:
1.12 paf 69: /**
70: retrives the resulting value
1.29 paf 71: that can be String if value==0 or the Value object
1.12 paf 72: wmethod_frame first checks for $result and if there is one, returns it instead
73: */
1.29 paf 74: virtual StringOrValue result() {
75: return fvalue?StringOrValue(0, fvalue):StringOrValue(&fstring, 0);
1.7 paf 76: }
77:
1.1 paf 78: public: // usage
79:
1.16 parser 80: WContext(Pool& apool, Value *avalue) : Value(apool),
1.7 paf 81: fstring(*new(apool) String(apool)),
1.20 paf 82: fvalue(avalue) {
83: flags.constructing=
84: flags.entered_class=
85: flags.entered_object=0;
1.1 paf 86: }
87:
1.20 paf 88: void set_constructing(bool aconstructing) { flags.constructing=aconstructing?1:0; }
89: bool get_constructing() { return flags.constructing!=0; }
1.19 paf 90:
1.28 paf 91: void set_in_expression(bool ain_expression) { flags.in_expression=ain_expression?1:0; }
92: bool get_in_expression() { return flags.in_expression!=0; }
93:
1.25 paf 94: void set_somebody_entered_some_class() { flags.entered_class=1; }
1.20 paf 95: bool get_somebody_entered_some_class() { return flags.entered_class!=0; }
1.19 paf 96:
97: void set_somebody_entered_some_object(bool aentered_object) {
1.24 paf 98: flags.entered_object=aentered_object?1:0;
99: }
1.20 paf 100: bool get_somebody_entered_some_object() { return flags.entered_object!=0; }
1.14 paf 101:
1.1 paf 102: protected:
1.7 paf 103: String& fstring;
1.19 paf 104: Value *fvalue;
1.1 paf 105: private:
1.19 paf 106: struct {
1.20 paf 107: int constructing:1;
1.28 paf 108: int in_expression:1;
1.20 paf 109: int entered_object:1;
110: int entered_class:1;
111: } flags;
1.1 paf 112: };
113:
114: #endif
E-mail: