Annotation of parser3/src/types/pa_vconsole.h, revision 1.20
1.1 paf 1: /** @file
2: Parser: @b console class decl.
3:
1.18 moko 4: Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com)
1.1 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
6: */
7:
8: #ifndef PA_VCONSOLE_H
9: #define PA_VCONSOLE_H
10:
1.20 ! misha 11: #define IDENT_PA_VCONSOLE_H "$Id: pa_vconsole.h,v 1.19 2013/10/04 21:21:56 moko Exp $"
1.1 paf 12:
13: // includes
14:
15: #include "pa_sapi.h"
16: #include "pa_common.h"
17: #include "pa_value.h"
18: #include "pa_string.h"
19:
20: // defines
21:
22: #define CONSOLE_CLASS_NAME "console"
1.14 misha 23: static const String console_class_name(CONSOLE_CLASS_NAME);
24:
1.1 paf 25: #define CONSOLE_LINE_NAME "line"
26:
27: /// console class
28: class VConsole: public Value {
29: public: // Value
30:
1.11 misha 31: const char* type() const { return CONSOLE_CLASS_NAME; }
1.1 paf 32: /// VConsole: 0
33: VStateless_class *get_class() { return 0; }
34:
1.20 ! misha 35: /// console: line
1.17 misha 36: Value* get_element(const String& aname) {
1.1 paf 37: // $line
38: if(aname==CONSOLE_LINE_NAME) {
39: char local_value[MAX_STRING];
1.15 misha 40: if(fgets(local_value, sizeof(local_value), stdin))
1.16 misha 41: return new VString(*new String(strdup(local_value), String::L_TAINTED));
1.1 paf 42:
43: return 0; // EOF
44: }
45:
1.20 ! misha 46: #ifndef OPTIMIZE_BYTECODE_GET_ELEMENT__SPECIAL
1.14 misha 47: // $CLASS
48: if(aname==CLASS_NAME)
49: return this;
50:
51: // $CLASS_NAME
52: if(aname==CLASS_NAMETEXT)
53: return new VString(console_class_name);
1.20 ! misha 54: #endif
1.14 misha 55:
1.13 misha 56: throw Exception(PARSER_RUNTIME,
1.1 paf 57: &aname,
58: "reading of invalid field");
59: }
60:
1.14 misha 61: /// console: $line
1.19 moko 62: override const VJunction* put_element(const String& aname, Value* avalue) {
1.1 paf 63: // $line
64: if(aname==CONSOLE_LINE_NAME) {
1.12 misha 65: fused=true;
1.15 misha 66: puts(avalue->as_string().cstr());
1.2 paf 67: fflush(stdout);
1.1 paf 68:
1.6 paf 69: return PUT_ELEMENT_REPLACED_ELEMENT;
1.1 paf 70: }
71:
1.13 misha 72: throw Exception(PARSER_RUNTIME,
1.1 paf 73: &aname,
74: "writing to invalid field");
75: }
76:
1.12 misha 77: bool was_used(){
78: return fused;
79: }
80:
1.1 paf 81: public: // usage
82:
1.12 misha 83: VConsole() {
84: fused=false;
85: }
1.1 paf 86:
1.12 misha 87: private:
88: bool fused;
1.1 paf 89: };
90:
91: #endif
E-mail: