Annotation of parser3/src/types/pa_vconsole.h, revision 1.14
1.1 paf 1: /** @file
2: Parser: @b console class decl.
3:
1.14 ! misha 4: Copyright (c) 2001-2009 ArtLebedev Group (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.14 ! misha 11: static const char * const IDENT_VCONSOLE_H="$Date: 2007/04/23 10:30:49 $";
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.14 ! misha 35: /// console: line,CLASS,CLASS_NAME
1.1 paf 36: Value* get_element(const String& aname, Value& /*aself*/, bool /*looking_up*/) {
37: // $line
38: if(aname==CONSOLE_LINE_NAME) {
39: char local_value[MAX_STRING];
40: if(fgets(local_value, sizeof(local_value), stdin)) {
41: return new VString(*new String(strdup(local_value), true));
42: }
43:
44: return 0; // EOF
45: }
46:
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);
! 54:
1.13 misha 55: throw Exception(PARSER_RUNTIME,
1.1 paf 56: &aname,
57: "reading of invalid field");
58: }
59:
1.14 ! misha 60: /// console: $line
1.9 paf 61: override const VJunction* put_element(Value& /*aself*/, const String& aname, Value* avalue, bool /*areplace*/) {
1.1 paf 62: // $line
63: if(aname==CONSOLE_LINE_NAME) {
1.12 misha 64: fused=true;
1.1 paf 65: const char* cstr=avalue->as_string().cstr();
66: puts(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: