Annotation of parser3/src/types/pa_wcontext.h, revision 1.63
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.63 ! moko 11: #define IDENT_PA_WCONTEXT_H "$Id: pa_wcontext.h,v 1.62 2016/09/21 12:35:19 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.29 paf 28: private:
1.43 paf 29: Value* fvalue;
1.29 paf 30: };
31:
1.12 paf 32: /** Write context
33: they do different write()s here, later picking up the result
34: @see Request::wcontext
35: */
1.63 ! moko 36:
1.43 paf 37: class WContext: public Value {
1.18 paf 38: friend class Request;
1.19 paf 39:
1.1 paf 40: public: // Value
41:
1.43 paf 42: override const char* type() const { return "wcontext"; }
1.12 paf 43: /// WContext: accumulated fstring
1.51 misha 44: override const String* get_string() {
45: static String empty;
1.63 ! moko 46: return fstring ? fstring : ∅
1.51 misha 47: };
1.1 paf 48:
1.12 paf 49: /// WContext: none yet | transparent
1.63 ! moko 50: override VStateless_class *get_class() { return fvalue ? fvalue->get_class() : 0; }
1.1 paf 51:
52: public: // WContext
53:
1.12 paf 54: /// appends a fstring to result
1.43 paf 55: virtual void write(const String& astring, String::Language alang) {
1.51 misha 56: if(!fstring) fstring=new String;
1.56 misha 57: astring.append_to(*fstring, alang);
1.35 paf 58: }
1.32 paf 59: /// writes Value; raises an error if already, providing origin
1.43 paf 60: virtual void write(Value& avalue);
1.1 paf 61:
1.12 paf 62: /**
63: if value is VString writes fstring,
1.32 paf 64: else writes Value; raises an error if already, providing origin
65: */
1.53 misha 66: virtual void write(Value& avalue, String::Language alang) {
1.62 moko 67: if(const String* string=avalue.get_string())
68: write(*string, alang);
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.63 ! moko 78: virtual Value& result() {
1.51 misha 79: static String empty;
1.63 ! moko 80: static VString vempty(empty);
! 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.55 misha 93: fvalue(0),
1.54 misha 94: in_expression(false),
95: entered_class(false){}
96:
1.44 paf 97: virtual ~WContext() {
1.39 paf 98: detach_junctions();
99: }
1.1 paf 100:
1.48 paf 101: void set_in_expression(bool ain_expression) { in_expression=ain_expression; }
102: bool get_in_expression() { return in_expression; }
1.28 paf 103:
1.39 paf 104: private:
105:
106: void detach_junctions();
107:
1.1 paf 108: protected:
1.55 misha 109: WContext *fparent;
1.51 misha 110: String* fstring;
1.43 paf 111: Value* fvalue;
1.48 paf 112:
113: private: // status
114:
115: bool in_expression;
116: bool entered_class;
1.39 paf 117:
118: private:
1.52 misha 119: Array<VJunction*> junctions;
1.38 paf 120:
1.1 paf 121: };
122:
123: #endif
E-mail: