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

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

E-mail: