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

1.1       paf         1: /** @file
                      2:        Parser: @b console class decl.
                      3: 
1.22      moko        4:        Copyright (c) 2001-2015 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.23    ! moko       11: #define IDENT_PA_VCONSOLE_H "$Id: pa_vconsole.h,v 1.22 2015/10/26 01:22:01 moko Exp $"
1.1       paf        12: 
                     13: // includes
                     14: 
                     15: #include "pa_sapi.h"
                     16: #include "pa_common.h"
1.23    ! moko       17: #include "pa_vstateless_class.h"
1.1       paf        18: #include "pa_string.h"
                     19: 
                     20: // defines
                     21: 
                     22: #define CONSOLE_LINE_NAME "line"
                     23: 
                     24: /// console class
1.23    ! moko       25: class VConsole: public VStateless_class {
1.1       paf        26: public: // Value
                     27:        
1.23    ! moko       28:        const char* type() const { return "console"; }
1.1       paf        29: 
1.20      misha      30:        /// console: line
1.17      misha      31:        Value* get_element(const String& aname) {
1.23    ! moko       32:                // CLASS, CLASS_NAME or method
        !            33:                if(Value* result=VStateless_class::get_element(aname))
        !            34:                        return result;
        !            35: 
1.1       paf        36:                // $line
                     37:                if(aname==CONSOLE_LINE_NAME) {
                     38:                        char local_value[MAX_STRING];
1.15      misha      39:                        if(fgets(local_value, sizeof(local_value), stdin))
1.21      moko       40:                                return new VString(*new String(pa_strdup(local_value), String::L_TAINTED));
1.1       paf        41: 
                     42:                        return 0; // EOF
                     43:                }
                     44: 
1.23    ! moko       45:                throw Exception(PARSER_RUNTIME, &aname, "reading of invalid field");
1.1       paf        46:        }
                     47: 
1.14      misha      48:        /// console: $line
1.19      moko       49:        override const VJunction* put_element(const String& aname, Value* avalue) { 
1.1       paf        50:                // $line
                     51:                if(aname==CONSOLE_LINE_NAME) {
1.12      misha      52:                        fused=true;
1.15      misha      53:                        puts(avalue->as_string().cstr());
1.2       paf        54:                        fflush(stdout);
1.1       paf        55: 
1.6       paf        56:                        return PUT_ELEMENT_REPLACED_ELEMENT;
1.1       paf        57:                }
                     58: 
1.13      misha      59:                throw Exception(PARSER_RUNTIME,
1.1       paf        60:                        &aname,
                     61:                        "writing to invalid field");
                     62:        }
                     63: 
1.12      misha      64:        bool was_used(){
                     65:                return fused;
                     66:        }
                     67: 
1.1       paf        68: public: // usage
                     69: 
1.12      misha      70:        VConsole() {
                     71:                fused=false;
                     72:        }
1.1       paf        73: 
1.12      misha      74: private:
                     75:        bool fused;
1.1       paf        76: };
                     77: 
                     78: #endif

E-mail: