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