Annotation of parser3/src/types/pa_wcontext.h, revision 1.61
1.12 paf 1: /** @file
2: Parser: write context class decl.
3:
1.60 moko 4: Copyright (c) 2001-2015 Art. Lebedev Studio (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.61 ! moko 11: #define IDENT_PA_WCONTEXT_H "$Id: pa_wcontext.h,v 1.60 2015/10/26 01:22:03 moko Exp $"
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;
1.56 misha 66: astring.append_to(*fstring, 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.55 misha 98: WContext(WContext *aparent):
99: fparent(aparent),
1.51 misha 100: fstring(0),
1.55 misha 101: fvalue(0),
1.54 misha 102: in_expression(false),
103: entered_class(false){}
104:
1.44 paf 105: virtual ~WContext() {
1.39 paf 106: detach_junctions();
107: }
1.1 paf 108:
1.48 paf 109: void set_in_expression(bool ain_expression) { in_expression=ain_expression; }
110: bool get_in_expression() { return in_expression; }
1.28 paf 111:
1.39 paf 112: private:
113:
114: void detach_junctions();
115:
1.1 paf 116: protected:
1.55 misha 117: WContext *fparent;
1.51 misha 118: String* fstring;
1.43 paf 119: Value* fvalue;
1.48 paf 120:
121: private: // status
122:
123: bool in_expression;
124: bool entered_class;
1.39 paf 125:
126: private:
1.52 misha 127: Array<VJunction*> junctions;
1.38 paf 128:
1.1 paf 129: };
130:
131: #endif
E-mail: