Annotation of parser3/src/types/pa_wcontext.h, revision 1.66
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.66 ! moko 11: #define IDENT_PA_WCONTEXT_H "$Id: pa_wcontext.h,v 1.65 2016/10/26 16:40:50 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.65 moko 55: virtual void write(const String& astring) {
1.51 misha 56: if(!fstring) fstring=new String;
1.65 moko 57: astring.append_to(*fstring);
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.66 ! moko 62: /// if value is string convertable writes fstring, else writes Value
1.65 moko 63: virtual void write_as_string(Value& avalue) {
1.62 moko 64: if(const String* string=avalue.get_string())
1.65 moko 65: write(*string);
1.32 paf 66: else
1.43 paf 67: write(avalue);
1.32 paf 68: }
1.1 paf 69:
1.12 paf 70: /**
71: retrives the resulting value
1.29 paf 72: that can be String if value==0 or the Value object
1.12 paf 73: wmethod_frame first checks for $result and if there is one, returns it instead
74: */
1.63 moko 75: virtual Value& result() {
1.51 misha 76: static String empty;
1.63 moko 77: static VString vempty(empty);
78: return fvalue ? *fvalue: fstring ? *new VString(*fstring) : vempty;
1.7 paf 79: }
80:
1.52 misha 81: void attach_junction(VJunction* ajunction) {
1.43 paf 82: junctions+=ajunction;
1.39 paf 83: }
84:
1.1 paf 85: public: // usage
86:
1.55 misha 87: WContext(WContext *aparent):
88: fparent(aparent),
1.51 misha 89: fstring(0),
1.55 misha 90: fvalue(0),
1.64 moko 91: in_expression(false){}
1.54 misha 92:
1.44 paf 93: virtual ~WContext() {
1.39 paf 94: detach_junctions();
95: }
1.1 paf 96:
1.48 paf 97: void set_in_expression(bool ain_expression) { in_expression=ain_expression; }
98: bool get_in_expression() { return in_expression; }
1.28 paf 99:
1.39 paf 100: private:
101:
102: void detach_junctions();
103:
1.1 paf 104: protected:
1.55 misha 105: WContext *fparent;
1.51 misha 106: String* fstring;
1.43 paf 107: Value* fvalue;
1.48 paf 108:
109: private: // status
110:
111: bool in_expression;
1.39 paf 112:
113: private:
1.52 misha 114: Array<VJunction*> junctions;
1.38 paf 115:
1.1 paf 116: };
117:
1.66 ! moko 118:
! 119: class WExpressionContext: public WContext {
! 120:
! 121: /// in expressions we don't attempt to convert to string
! 122: virtual void write_as_string(Value& avalue) {
! 123: write(avalue);
! 124: }
! 125: };
! 126:
1.1 paf 127: #endif
E-mail: