Annotation of parser3/src/types/pa_vtable.h, revision 1.69

1.6       paf         1: /** @file
1.15      paf         2:        Parser: @b table parser class decl.
1.6       paf         3: 
1.68      moko        4:        Copyright (c) 2001-2020 Art. Lebedev Studio (http://www.artlebedev.com)
1.37      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1       paf         6: */
                      7: 
                      8: #ifndef PA_VTABLE_H
                      9: #define PA_VTABLE_H
1.39      paf        10: 
1.69    ! moko       11: #define IDENT_PA_VTABLE_H "$Id: pa_vtable.h,v 1.68 2020/12/15 17:10:44 moko Exp $"
1.1       paf        12: 
                     13: #include "pa_vstateless_object.h"
                     14: #include "pa_table.h"
1.49      paf        15: //#include "pa_vvoid.h"
1.30      parser     16: #include "pa_vint.h"
1.1       paf        17: 
1.46      paf        18: // defines
                     19: 
                     20: #define VTABLE_TYPE "table"
1.27      parser     21: 
1.46      paf        22: // externs
                     23: 
1.49      paf        24: extern Methoded* table_class;
1.16      paf        25: 
1.6       paf        26: /// value of type 'table'. implemented with Table
1.49      paf        27: class VTable: public VStateless_object {
1.1       paf        28: public: // Value
                     29: 
1.49      paf        30:        override const char* type() const { return VTABLE_TYPE; }
                     31:        override VStateless_class *get_class() { return table_class; }
1.32      parser     32:        /// VTable: count
1.67      moko       33:        override int as_int() const { return (int)table().count(); }
1.32      parser     34:        /// VTable: count
1.69    ! moko       35:        override double as_double() const { return (double)table().count(); }
1.29      parser     36:        /// VTable: count!=0
1.61      misha      37:        override bool is_defined() const { return table().count()!=0; }
1.31      parser     38:        /// VTable: 0 or !0
1.61      misha      39:        override bool as_bool() const { return table().count()!=0; }
1.32      parser     40:        /// VTable: count
1.59      moko       41:        override Value& as_expr_result() { return *new VInt(as_int()); }
1.56      misha      42:        /// VTable: json-string
1.60      moko       43:        override const String* get_json_string(Json_options& options);
1.6       paf        44:        /// extract VTable
1.49      paf        45:        override Table* get_table() { return ftable; }
1.18      paf        46:        /// VTable: columns,methods
1.55      misha      47:        override Value* get_element(const String& aname);
1.63      moko       48: #ifdef FEATURE_GET_ELEMENT4CALL
                     49:        /// VTable: methods,columns
                     50:        override Value* get_element4call(const String& aname);
                     51: #endif
1.62      moko       52:        /// VTable: columns
                     53:        virtual const VJunction* put_element(const String&, Value*);
1.1       paf        54: 
                     55: public: // usage
                     56: 
1.49      paf        57:        VTable(Table* atable=0): ftable(atable) {}
                     58: 
1.14      paf        59:        void set_table(Table& avalue) { 
                     60:                ftable=&avalue; 
                     61:        }
1.49      paf        62:        Table& table() const { 
1.4       paf        63:                if(!ftable)
1.49      paf        64:                        bark("getting unset vtable value", 0);
1.1       paf        65: 
1.4       paf        66:                return *ftable; 
1.1       paf        67:        }
                     68: 
                     69: private:
1.27      parser     70: 
1.49      paf        71:        Value* fields_element();
1.1       paf        72: 
1.57      moko       73:        String& get_json_string_array(String&, const char *);
                     74:        String& get_json_string_object(String&, const char *);
                     75:        String& get_json_string_compact(String&, const char *);
                     76: 
1.18      paf        77: private:
                     78: 
1.49      paf        79:        Table* ftable;
1.1       paf        80: 
                     81: };
                     82: 
                     83: #endif

E-mail: