Annotation of parser3/src/types/pa_wcontext.h, revision 1.42.2.7
1.12 paf 1: /** @file
2: Parser: write context class decl.
3:
1.42.2.5 paf 4: Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
1.27 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1 paf 6: */
7:
8: #ifndef PA_WCONTEXT_H
9: #define PA_WCONTEXT_H
1.33 paf 10:
1.42.2.7! paf 11: static const char* IDENT_WCONTEXT_H="$Date: 2003/01/31 14:03:55 $";
1.1 paf 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.42.2.4 paf 23: StringOrValue(StringPtr astring, ValuePtr avalue) : fstring(astring), fvalue(avalue) {}
24: void set_string(StringPtr astring) { fstring=astring; }
1.42.2.1 paf 25: void set_value(ValuePtr avalue) { fvalue=avalue; }
1.42.2.4 paf 26: StringPtr get_string() { return fstring; }
1.42.2.1 paf 27: ValuePtr get_value() { return fvalue; }
28: ValuePtr as_value() const {
29: return fvalue?fvalue:ValuePtr(new VString(fstring));
1.29 paf 30: }
1.42.2.4 paf 31: StringPtr as_string(Pool *pool) const {
1.42.2.1 paf 32: return fstring?fstring:fvalue->as_string(pool);
1.29 paf 33: }
34: private:
1.42.2.4 paf 35: StringPtr fstring;
1.42.2.1 paf 36: ValuePtr fvalue;
1.29 paf 37: };
38:
1.12 paf 39: /** Write context
40: they do different write()s here, later picking up the result
41: @see Request::wcontext
42: */
1.1 paf 43: class WContext : public Value {
1.18 paf 44: friend class Request;
1.19 paf 45:
1.1 paf 46: public: // Value
47:
1.42.2.5 paf 48: override const char* type() const { return "wcontext"; }
1.12 paf 49: /// WContext: accumulated fstring
1.42.2.7! paf 50: override StringPtr get_string(Pool*) { return fstring; };
1.1 paf 51:
1.12 paf 52: /// WContext: none yet | transparent
1.42.2.1 paf 53: override VStateless_class *get_class() { return fvalue?fvalue->get_class():0; }
1.1 paf 54:
55: public: // WContext
56:
1.12 paf 57: /// appends a fstring to result
1.42.2.3 paf 58: virtual void write(const String& astring, uchar alang) {
59: fstring->append(astring, alang);
1.35 paf 60: }
1.32 paf 61: /// writes Value; raises an error if already, providing origin
1.42.2.6 paf 62: virtual void write(Pool& apool, ValuePtr avalue, StringPtr asource=Exception::undefined_source);
1.1 paf 63:
1.12 paf 64: /**
65: if value is VString writes fstring,
1.32 paf 66: else writes Value; raises an error if already, providing origin
67: */
1.42.2.6 paf 68: void write(Pool& apool,
1.42.2.4 paf 69: ValuePtr avalue, String_UL alang, StringPtr asource=Exception::undefined_source) {
1.42.2.6 paf 70: if(StringPtr fstring=avalue->get_string(&apool))
1.42.2.3 paf 71: write(*fstring, alang);
1.32 paf 72: else
1.42.2.6 paf 73: write(apool, avalue, asource);
1.32 paf 74: }
1.1 paf 75:
1.12 paf 76: /**
77: retrives the resulting value
1.29 paf 78: that can be String if value==0 or the Value object
1.12 paf 79: wmethod_frame first checks for $result and if there is one, returns it instead
80: */
1.29 paf 81: virtual StringOrValue result() {
1.42.2.4 paf 82: return fvalue?StringOrValue(StringPtr(0), fvalue):StringOrValue(fstring, ValuePtr(0));
1.7 paf 83: }
84:
1.42.2.1 paf 85: void attach_junction(JunctionPtr ajunction) {
86: junctions+=ajunction;
1.39 paf 87: }
88:
1.1 paf 89: public: // usage
90:
1.42.2.4 paf 91: WContext(ValuePtr avalue, WContext *aparent):
1.42.2.1 paf 92: fstring(new String),
1.39 paf 93: fvalue(avalue),
1.42.2.1 paf 94: fparent(aparent) {
1.20 paf 95: flags.constructing=
96: flags.entered_class=
97: flags.entered_object=0;
1.1 paf 98: }
1.39 paf 99: ~WContext() {
100: detach_junctions();
101: }
1.1 paf 102:
1.20 paf 103: void set_constructing(bool aconstructing) { flags.constructing=aconstructing?1:0; }
104: bool get_constructing() { return flags.constructing!=0; }
1.19 paf 105:
1.28 paf 106: void set_in_expression(bool ain_expression) { flags.in_expression=ain_expression?1:0; }
107: bool get_in_expression() { return flags.in_expression!=0; }
108:
1.25 paf 109: void set_somebody_entered_some_class() { flags.entered_class=1; }
1.20 paf 110: bool get_somebody_entered_some_class() { return flags.entered_class!=0; }
1.14 paf 111:
1.39 paf 112: private:
113:
114: void detach_junctions();
115:
1.1 paf 116: protected:
1.42.2.1 paf 117: StringPtr fstring;
118: ValuePtr fvalue;
1.1 paf 119: private:
1.19 paf 120: struct {
1.20 paf 121: int constructing:1;
1.28 paf 122: int in_expression:1;
1.20 paf 123: int entered_object:1;
124: int entered_class:1;
125: } flags;
1.39 paf 126:
127: private:
128:
129: WContext *fparent;
1.42.2.1 paf 130: Array<JunctionPtr> junctions;
1.38 paf 131:
1.1 paf 132: };
133:
134: #endif
E-mail: