Annotation of parser3/src/types/pa_wcontext.h, revision 1.52
1.12 paf 1: /** @file
2: Parser: write context class decl.
3:
1.51 misha 4: Copyright (c) 2001-2009 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.52 ! misha 11: static const char * const IDENT_WCONTEXT_H="$Date: 2009-04-16 02:06:25 $";
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.51 misha 53: override const String* get_string() {
54: static String empty;
55: return fstring?fstring:∅
56: };
1.1 paf 57:
1.12 paf 58: /// WContext: none yet | transparent
1.43 paf 59: override VStateless_class *get_class() { return fvalue?fvalue->get_class():0; }
1.1 paf 60:
61: public: // WContext
62:
1.12 paf 63: /// appends a fstring to result
1.43 paf 64: virtual void write(const String& astring, String::Language alang) {
1.51 misha 65: if(!fstring) fstring=new String;
66: fstring->append(astring, alang);
1.35 paf 67: }
1.32 paf 68: /// writes Value; raises an error if already, providing origin
1.43 paf 69: virtual void write(Value& avalue);
1.1 paf 70:
1.12 paf 71: /**
72: if value is VString writes fstring,
1.32 paf 73: else writes Value; raises an error if already, providing origin
74: */
1.50 paf 75: void write(
76: Value& avalue, String::Language alang) {
1.43 paf 77: if(const String* fstring=avalue.get_string())
78: write(*fstring, alang);
1.32 paf 79: else
1.43 paf 80: write(avalue);
1.32 paf 81: }
1.1 paf 82:
1.12 paf 83: /**
84: retrives the resulting value
1.29 paf 85: that can be String if value==0 or the Value object
1.12 paf 86: wmethod_frame first checks for $result and if there is one, returns it instead
87: */
1.29 paf 88: virtual StringOrValue result() {
1.51 misha 89: static String empty;
90: return fvalue?StringOrValue(*fvalue):StringOrValue(fstring?*fstring:empty);
1.7 paf 91: }
92:
1.52 ! misha 93: void attach_junction(VJunction* ajunction) {
1.43 paf 94: junctions+=ajunction;
1.39 paf 95: }
96:
1.1 paf 97: public: // usage
98:
1.43 paf 99: WContext(Value* avalue, WContext *aparent):
1.51 misha 100: fstring(0),
1.39 paf 101: fvalue(avalue),
1.43 paf 102: fparent(aparent) {
1.48 paf 103: constructing=in_expression=entered_class=entered_object=were_string_writes=false;
1.1 paf 104: }
1.44 paf 105: virtual ~WContext() {
1.39 paf 106: detach_junctions();
107: }
1.1 paf 108:
1.48 paf 109: void set_constructing(bool aconstructing) { constructing=aconstructing; }
110: bool get_constructing() { return constructing; }
1.19 paf 111:
1.48 paf 112: void set_in_expression(bool ain_expression) { in_expression=ain_expression; }
113: bool get_in_expression() { return in_expression; }
1.28 paf 114:
1.48 paf 115: void set_somebody_entered_some_class() { entered_class=true; }
116: bool get_somebody_entered_some_class() { return entered_class; }
1.14 paf 117:
1.39 paf 118: private:
119:
120: void detach_junctions();
121:
1.1 paf 122: protected:
1.51 misha 123: String* fstring;
1.43 paf 124: Value* fvalue;
1.48 paf 125:
126: private: // status
127:
128: bool constructing;
129: bool in_expression;
130: bool entered_object;
131: bool entered_class;
132: bool were_string_writes;
1.39 paf 133:
134: private:
135:
136: WContext *fparent;
1.52 ! misha 137: Array<VJunction*> junctions;
1.38 paf 138:
1.1 paf 139: };
140:
141: #endif
E-mail: