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