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

1.1       paf         1: /** @file
                      2:        Parser: @b console class decl.
                      3: 
1.10      paf         4:        Copyright (c) 2001-2005 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.11    ! misha      11: static const char * const IDENT_VCONSOLE_H="$Date: 2005/08/09 08:14:54 $";
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"
                     23: #define CONSOLE_LINE_NAME "line"
                     24: 
                     25: /// console class
                     26: class VConsole: public Value {
                     27: public: // Value
                     28:        
1.11    ! misha      29:        const char* type() const { return CONSOLE_CLASS_NAME; }
1.1       paf        30:        /// VConsole: 0
                     31:        VStateless_class *get_class() { return 0; }
                     32: 
                     33:        // VConsole: $line
                     34:        Value* get_element(const String& aname, Value& /*aself*/, bool /*looking_up*/) {
                     35:                // $line
                     36:                if(aname==CONSOLE_LINE_NAME) {
                     37:                        char local_value[MAX_STRING];
                     38:                        if(fgets(local_value, sizeof(local_value), stdin)) {
                     39:                                return new VString(*new String(strdup(local_value), true));
                     40:                        }
                     41: 
                     42:                        return 0; // EOF
                     43:                }
                     44: 
                     45:                throw Exception("parser.runtime",
                     46:                        &aname,
                     47:                        "reading of invalid field");
                     48:        }
                     49: 
                     50:        /// VConsole: $line
1.9       paf        51:        override const VJunction* put_element(Value& /*aself*/, const String& aname, Value* avalue, bool /*areplace*/) { 
1.1       paf        52:                // $line
                     53:                if(aname==CONSOLE_LINE_NAME) {
                     54:                        const char* cstr=avalue->as_string().cstr();
                     55:                        puts(cstr);
1.2       paf        56:                        fflush(stdout);
1.1       paf        57: 
1.6       paf        58:                        return PUT_ELEMENT_REPLACED_ELEMENT;
1.1       paf        59:                }
                     60: 
                     61:                throw Exception("parser.runtime",
                     62:                        &aname,
                     63:                        "writing to invalid field");
                     64:        }
                     65: 
                     66: public: // usage
                     67: 
                     68:        VConsole() {}
                     69: 
                     70: };
                     71: 
                     72: #endif

E-mail: