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

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.12    ! misha      11: static const char * const IDENT_VCONSOLE_H="$Date: 2007/02/07 15:50:51 $";
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) {
1.12    ! misha      54:                        fused=true;
1.1       paf        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: 
1.12    ! misha      67:        bool was_used(){
        !            68:                return fused;
        !            69:        }
        !            70: 
1.1       paf        71: public: // usage
                     72: 
1.12    ! misha      73:        VConsole() {
        !            74:                fused=false;
        !            75:        }
1.1       paf        76: 
1.12    ! misha      77: private:
        !            78:        bool fused;
1.1       paf        79: };
                     80: 
                     81: #endif

E-mail: