Annotation of parser3/src/types/pa_wcontext.h, revision 1.46.12.2
1.12 paf 1: /** @file
2: Parser: write context class decl.
3:
1.46.12.1 paf 4: Copyright (c) 2001-2005 ArtLebedev Group (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.46.12.2! paf 11: static const char * const IDENT_WCONTEXT_H="$Date: 2005/08/05 13:03:06 $";
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.43 paf 23: StringOrValue(const String* astring, Value* avalue) : fstring(astring), fvalue(avalue) {}
1.30 paf 24: void set_string(const String& astring) { fstring=&astring; }
1.29 paf 25: void set_value(Value& avalue) { fvalue=&avalue; }
1.43 paf 26: const String* get_string() { return fstring; }
27: Value* get_value() { return fvalue; }
1.29 paf 28: Value& as_value() const {
1.43 paf 29: Value* result=fvalue?fvalue:new VString(*fstring);
30: return *result;
1.29 paf 31: }
32: const String& as_string() const {
33: return fstring?*fstring:fvalue->as_string();
34: }
35: private:
1.43 paf 36: const String* fstring;
37: Value* fvalue;
1.29 paf 38: };
39:
1.12 paf 40: /** Write context
41: they do different write()s here, later picking up the result
42: @see Request::wcontext
43: */
1.43 paf 44: class WContext: public Value {
1.18 paf 45: friend class Request;
1.19 paf 46:
1.1 paf 47: public: // Value
48:
1.43 paf 49: override const char* type() const { return "wcontext"; }
1.12 paf 50: /// WContext: accumulated fstring
1.43 paf 51: override const String* get_string() { return &fstring; };
1.1 paf 52:
1.12 paf 53: /// WContext: none yet | transparent
1.43 paf 54: override VStateless_class *get_class() { return fvalue?fvalue->get_class():0; }
1.1 paf 55:
56: public: // WContext
57:
1.12 paf 58: /// appends a fstring to result
1.43 paf 59: virtual void write(const String& astring, String::Language alang) {
60: fstring.append(astring, alang);
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.12 paf 65: /**
66: if value is VString writes fstring,
1.32 paf 67: else writes Value; raises an error if already, providing origin
68: */
1.46.12.2! paf 69: void write(Value& avalue, String::Language alang) {
1.43 paf 70: if(const String* fstring=avalue.get_string())
71: write(*fstring, alang);
1.32 paf 72: else
1.43 paf 73: write(avalue);
1.32 paf 74: }
1.1 paf 75:
1.12 paf 76: /**
77: retrives the resulting value
1.29 paf 78: that can be String if value==0 or the Value object
1.12 paf 79: wmethod_frame first checks for $result and if there is one, returns it instead
80: */
1.29 paf 81: virtual StringOrValue result() {
82: return fvalue?StringOrValue(0, fvalue):StringOrValue(&fstring, 0);
1.7 paf 83: }
84:
1.43 paf 85: void attach_junction(Junction* ajunction) {
86: junctions+=ajunction;
1.39 paf 87: }
88:
1.1 paf 89: public: // usage
90:
1.43 paf 91: WContext(Value* avalue, WContext *aparent):
92: fstring(*new String),
1.39 paf 93: fvalue(avalue),
1.43 paf 94: fparent(aparent) {
1.46.12.2! paf 95: constructing=in_expression=entered_class=entered_object=were_string_writes=false;
1.1 paf 96: }
1.44 paf 97: virtual ~WContext() {
1.39 paf 98: detach_junctions();
99: }
1.1 paf 100:
1.46.12.2! paf 101: void set_constructing(bool aconstructing) { constructing=aconstructing; }
! 102: bool get_constructing() { return constructing; }
1.19 paf 103:
1.46.12.2! paf 104: void set_in_expression(bool ain_expression) { in_expression=ain_expression; }
! 105: bool get_in_expression() { return in_expression; }
1.28 paf 106:
1.46.12.2! paf 107: void set_somebody_entered_some_class() { entered_class=true; }
! 108: bool get_somebody_entered_some_class() { return entered_class; }
1.14 paf 109:
1.39 paf 110: private:
111:
112: void detach_junctions();
113:
1.1 paf 114: protected:
1.7 paf 115: String& fstring;
1.43 paf 116: Value* fvalue;
1.46.12.2! paf 117:
! 118: private: // status
! 119:
! 120: bool constructing;
! 121: bool in_expression;
! 122: bool entered_object;
! 123: bool entered_class;
1.39 paf 124:
125: private:
126:
127: WContext *fparent;
1.43 paf 128: Array<Junction*> junctions;
1.38 paf 129:
1.1 paf 130: };
131:
132: #endif
E-mail: