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

1.1       paf         1: /** @file
                      2:        Parser: @b console class decl.
                      3: 
1.30      moko        4:        Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com)
1.28      moko        5:        Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
1.1       paf         6: */
                      7: 
                      8: #ifndef PA_VCONSOLE_H
                      9: #define PA_VCONSOLE_H
                     10: 
1.31    ! moko       11: #define IDENT_PA_VCONSOLE_H "$Id: pa_vconsole.h,v 1.30 2024/11/04 03:53:25 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.24      moko       32: #ifndef OPTIMIZE_BYTECODE_GET_ELEMENT__SPECIAL
                     33:                // CLASS, CLASS_NAME
1.23      moko       34:                if(Value* result=VStateless_class::get_element(aname))
                     35:                        return result;
1.24      moko       36: #endif
1.23      moko       37: 
1.1       paf        38:                // $line
                     39:                if(aname==CONSOLE_LINE_NAME) {
                     40:                        char local_value[MAX_STRING];
1.15      misha      41:                        if(fgets(local_value, sizeof(local_value), stdin))
1.31    ! moko       42:                                return new VString(pa_strdup(local_value));
1.1       paf        43: 
                     44:                        return 0; // EOF
                     45:                }
                     46: 
1.29      moko       47:                return bark("%s field not found", &aname);
1.1       paf        48:        }
                     49: 
1.14      misha      50:        /// console: $line
1.19      moko       51:        override const VJunction* put_element(const String& aname, Value* avalue) { 
1.1       paf        52:                // $line
                     53:                if(aname==CONSOLE_LINE_NAME) {
1.12      misha      54:                        fused=true;
1.15      misha      55:                        puts(avalue->as_string().cstr());
1.2       paf        56:                        fflush(stdout);
1.1       paf        57: 
1.26      moko       58:                        return 0;
1.1       paf        59:                }
                     60: 
1.26      moko       61:                throw Exception(PARSER_RUNTIME, &aname, "writing to invalid field");
1.1       paf        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: