Annotation of parser3/src/types/pa_wcontext.h, revision 1.50
1.12 paf 1: /** @file
2: Parser: write context class decl.
3:
1.49 paf 4: Copyright (c) 2001-2005 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.50 ! paf 11: static const char * const IDENT_WCONTEXT_H="$Date: 2005/08/09 08:14:56 $";
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.50 ! paf 71: void write(
! 72: Value& avalue, String::Language alang) {
1.43 paf 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.50 ! 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.48 paf 98: constructing=in_expression=entered_class=entered_object=were_string_writes=false;
1.1 paf 99: }
1.44 paf 100: virtual ~WContext() {
1.39 paf 101: detach_junctions();
102: }
1.1 paf 103:
1.48 paf 104: void set_constructing(bool aconstructing) { constructing=aconstructing; }
105: bool get_constructing() { return constructing; }
1.19 paf 106:
1.48 paf 107: void set_in_expression(bool ain_expression) { in_expression=ain_expression; }
108: bool get_in_expression() { return in_expression; }
1.28 paf 109:
1.48 paf 110: void set_somebody_entered_some_class() { entered_class=true; }
111: bool get_somebody_entered_some_class() { return entered_class; }
1.14 paf 112:
1.39 paf 113: private:
114:
115: void detach_junctions();
116:
1.1 paf 117: protected:
1.7 paf 118: String& fstring;
1.43 paf 119: Value* fvalue;
1.48 paf 120:
121: private: // status
122:
123: bool constructing;
124: bool in_expression;
125: bool entered_object;
126: bool entered_class;
127: bool were_string_writes;
1.39 paf 128:
129: private:
130:
131: WContext *fparent;
1.43 paf 132: Array<Junction*> junctions;
1.38 paf 133:
1.1 paf 134: };
135:
136: #endif
E-mail: