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

1.1       paf         1: /** @file
                      2:        Parser: @b console class decl.
                      3: 
1.5       paf         4:        Copyright (c) 2001-2004 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.7.2.3 ! paf        11: static const char * const IDENT_VCONSOLE_H="$Date: 2005/07/27 10:57:52 $";
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:        }
                     50: 
                     51:        /// VConsole: $line
1.7.2.3 ! paf        52:        override const Junction* put_element(Value& /*aself*/, const String& aname, Value* avalue, bool /*areplace*/) { 
1.1       paf        53:                // $line
                     54:                if(aname==CONSOLE_LINE_NAME) {
                     55:                        const char* cstr=avalue->as_string().cstr();
                     56:                        puts(cstr);
1.2       paf        57:                        fflush(stdout);
1.1       paf        58: 
1.6       paf        59:                        return PUT_ELEMENT_REPLACED_ELEMENT;
1.1       paf        60:                }
                     61: 
                     62:                throw Exception("parser.runtime",
                     63:                        &aname,
                     64:                        "writing to invalid field");
                     65:        }
                     66: 
                     67: public: // usage
                     68: 
                     69:        VConsole() {}
                     70: 
                     71: };
                     72: 
                     73: #endif

E-mail: