Annotation of parser3/src/types/pa_vconsole.h, revision 1.18

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.18    ! moko       11: #define IDENT_PA_VCONSOLE_H "$Id: 2009-08-08 13:30:21 $"
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.15      misha      35:        /// console: line, CLASS, CLASS_NAME
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.14      misha      46:                // $CLASS
                     47:                if(aname==CLASS_NAME)
                     48:                        return this;
                     49: 
                     50:                // $CLASS_NAME
                     51:                if(aname==CLASS_NAMETEXT)
                     52:                        return new VString(console_class_name);
                     53: 
1.13      misha      54:                throw Exception(PARSER_RUNTIME,
1.1       paf        55:                        &aname,
                     56:                        "reading of invalid field");
                     57:        }
                     58: 
1.14      misha      59:        /// console: $line
1.17      misha      60:        override const VJunction* put_element(const String& aname, Value* avalue, bool /*areplace*/) { 
1.1       paf        61:                // $line
                     62:                if(aname==CONSOLE_LINE_NAME) {
1.12      misha      63:                        fused=true;
1.15      misha      64:                        puts(avalue->as_string().cstr());
1.2       paf        65:                        fflush(stdout);
1.1       paf        66: 
1.6       paf        67:                        return PUT_ELEMENT_REPLACED_ELEMENT;
1.1       paf        68:                }
                     69: 
1.13      misha      70:                throw Exception(PARSER_RUNTIME,
1.1       paf        71:                        &aname,
                     72:                        "writing to invalid field");
                     73:        }
                     74: 
1.12      misha      75:        bool was_used(){
                     76:                return fused;
                     77:        }
                     78: 
1.1       paf        79: public: // usage
                     80: 
1.12      misha      81:        VConsole() {
                     82:                fused=false;
                     83:        }
1.1       paf        84: 
1.12      misha      85: private:
                     86:        bool fused;
1.1       paf        87: };
                     88: 
                     89: #endif

E-mail: