Annotation of parser3/src/types/pa_wcontext.h, revision 1.70
1.12 paf 1: /** @file
2: Parser: write context class decl.
3:
1.70 ! moko 4: Copyright (c) 2001-2017 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.70 ! moko 11: #define IDENT_PA_WCONTEXT_H "$Id: pa_wcontext.h,v 1.69 2016/11/29 15:27:07 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.63 moko 19: /** ValueRef
20: convenient helper when delayed initialization required
21: */
22:
23: class ValueRef {
1.29 paf 24: public:
1.63 moko 25: ValueRef() : fvalue(0) {}
26: ValueRef(Value& avalue) : fvalue(&avalue) {}
1.69 moko 27: ValueRef(Value* avalue) : fvalue(avalue) {}
1.63 moko 28: operator Value& () { return *fvalue; }
1.68 moko 29: Value* operator &() { return fvalue; }
30: const String &as_string() { return fvalue->as_string(); }
1.29 paf 31: private:
1.43 paf 32: Value* fvalue;
1.29 paf 33: };
34:
1.12 paf 35: /** Write context
36: they do different write()s here, later picking up the result
37: @see Request::wcontext
38: */
1.63 moko 39:
1.43 paf 40: class WContext: public Value {
1.18 paf 41: friend class Request;
1.19 paf 42:
1.1 paf 43: public: // Value
44:
1.43 paf 45: override const char* type() const { return "wcontext"; }
1.12 paf 46: /// WContext: accumulated fstring
1.51 misha 47: override const String* get_string() {
48: static String empty;
1.63 moko 49: return fstring ? fstring : ∅
1.51 misha 50: };
1.1 paf 51:
1.12 paf 52: /// WContext: none yet | transparent
1.63 moko 53: override VStateless_class *get_class() { return fvalue ? fvalue->get_class() : 0; }
1.1 paf 54:
55: public: // WContext
56:
1.12 paf 57: /// appends a fstring to result
1.65 moko 58: virtual void write(const String& astring) {
1.51 misha 59: if(!fstring) fstring=new String;
1.65 moko 60: astring.append_to(*fstring);
1.35 paf 61: }
1.32 paf 62: /// writes Value; raises an error if already, providing origin
1.43 paf 63: virtual void write(Value& avalue);
1.1 paf 64:
1.66 moko 65: /// if value is string convertable writes fstring, else writes Value
1.65 moko 66: virtual void write_as_string(Value& avalue) {
1.62 moko 67: if(const String* string=avalue.get_string())
1.65 moko 68: write(*string);
1.32 paf 69: else
1.43 paf 70: write(avalue);
1.32 paf 71: }
1.1 paf 72:
1.12 paf 73: /**
74: retrives the resulting value
1.29 paf 75: that can be String if value==0 or the Value object
1.12 paf 76: wmethod_frame first checks for $result and if there is one, returns it instead
77: */
1.68 moko 78: virtual ValueRef result() {
1.51 misha 79: static String empty;
1.63 moko 80: static VString vempty(empty);
1.69 moko 81: return fvalue ? fvalue : fstring ? new VString(*fstring) : &vempty;
1.7 paf 82: }
83:
1.52 misha 84: void attach_junction(VJunction* ajunction) {
1.43 paf 85: junctions+=ajunction;
1.39 paf 86: }
87:
1.1 paf 88: public: // usage
89:
1.55 misha 90: WContext(WContext *aparent):
91: fparent(aparent),
1.51 misha 92: fstring(0),
1.67 moko 93: fvalue(0){}
1.54 misha 94:
1.44 paf 95: virtual ~WContext() {
1.39 paf 96: detach_junctions();
97: }
1.1 paf 98:
1.39 paf 99: private:
100:
101: void detach_junctions();
102:
1.1 paf 103: protected:
1.55 misha 104: WContext *fparent;
1.51 misha 105: String* fstring;
1.43 paf 106: Value* fvalue;
1.48 paf 107:
1.39 paf 108: private:
1.52 misha 109: Array<VJunction*> junctions;
1.38 paf 110:
1.1 paf 111: };
112:
113: #endif
E-mail: