Annotation of parser3/src/types/pa_wcontext.h, revision 1.53
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.53 ! misha 11: static const char * const IDENT_WCONTEXT_H="$Date: 2009-04-21 09:26:08 $";
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.53 ! misha 75: virtual void write(Value& avalue, String::Language alang) {
1.43 paf 76: if(const String* fstring=avalue.get_string())
77: write(*fstring, alang);
1.32 paf 78: else
1.43 paf 79: write(avalue);
1.32 paf 80: }
1.1 paf 81:
1.12 paf 82: /**
83: retrives the resulting value
1.29 paf 84: that can be String if value==0 or the Value object
1.12 paf 85: wmethod_frame first checks for $result and if there is one, returns it instead
86: */
1.29 paf 87: virtual StringOrValue result() {
1.51 misha 88: static String empty;
89: return fvalue?StringOrValue(*fvalue):StringOrValue(fstring?*fstring:empty);
1.7 paf 90: }
91:
1.52 misha 92: void attach_junction(VJunction* ajunction) {
1.43 paf 93: junctions+=ajunction;
1.39 paf 94: }
95:
1.1 paf 96: public: // usage
97:
1.43 paf 98: WContext(Value* avalue, WContext *aparent):
1.51 misha 99: fstring(0),
1.39 paf 100: fvalue(avalue),
1.43 paf 101: fparent(aparent) {
1.48 paf 102: constructing=in_expression=entered_class=entered_object=were_string_writes=false;
1.1 paf 103: }
1.44 paf 104: virtual ~WContext() {
1.39 paf 105: detach_junctions();
106: }
1.1 paf 107:
1.48 paf 108: void set_constructing(bool aconstructing) { constructing=aconstructing; }
109: bool get_constructing() { return constructing; }
1.19 paf 110:
1.48 paf 111: void set_in_expression(bool ain_expression) { in_expression=ain_expression; }
112: bool get_in_expression() { return in_expression; }
1.28 paf 113:
1.48 paf 114: void set_somebody_entered_some_class() { entered_class=true; }
115: bool get_somebody_entered_some_class() { return entered_class; }
1.14 paf 116:
1.39 paf 117: private:
118:
119: void detach_junctions();
120:
1.1 paf 121: protected:
1.51 misha 122: String* fstring;
1.43 paf 123: Value* fvalue;
1.48 paf 124:
125: private: // status
126:
127: bool constructing;
128: bool in_expression;
129: bool entered_object;
130: bool entered_class;
131: bool were_string_writes;
1.39 paf 132:
133: private:
134:
135: WContext *fparent;
1.52 misha 136: Array<VJunction*> junctions;
1.38 paf 137:
1.1 paf 138: };
139:
140: #endif
E-mail: