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

1.6       paf         1: /** @file
1.15      paf         2:        Parser: @b table parser class decl.
1.6       paf         3: 
1.58      moko        4:        Copyright (c) 2001-2012 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.63    ! moko       11: #define IDENT_PA_VTABLE_H "$Id: pa_vtable.h,v 1.62 2015/07/28 14:42: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: #define TABLE_FIELDS_ELEMENT_NAME "fields"
                     22: 
1.46      paf        23: // externs
                     24: 
1.49      paf        25: extern Methoded* table_class;
1.16      paf        26: 
1.6       paf        27: /// value of type 'table'. implemented with Table
1.49      paf        28: class VTable: public VStateless_object {
1.1       paf        29: public: // Value
                     30: 
1.49      paf        31:        override const char* type() const { return VTABLE_TYPE; }
                     32:        override VStateless_class *get_class() { return table_class; }
1.32      parser     33:        /// VTable: count
1.49      paf        34:        override int as_int() const { return table().count(); }
1.32      parser     35:        /// VTable: count
1.61      misha      36:        override double as_double() const { return table().count(); }
1.29      parser     37:        /// VTable: count!=0
1.61      misha      38:        override bool is_defined() const { return table().count()!=0; }
1.31      parser     39:        /// VTable: 0 or !0
1.61      misha      40:        override bool as_bool() const { return table().count()!=0; }
1.32      parser     41:        /// VTable: count
1.59      moko       42:        override Value& as_expr_result() { return *new VInt(as_int()); }
1.56      misha      43:        /// VTable: json-string
1.60      moko       44:        override const String* get_json_string(Json_options& options);
1.6       paf        45:        /// extract VTable
1.49      paf        46:        override Table* get_table() { return ftable; }
1.18      paf        47:        /// VTable: columns,methods
1.55      misha      48:        override Value* get_element(const String& aname);
1.63    ! moko       49: #ifdef FEATURE_GET_ELEMENT4CALL
        !            50:        /// VTable: methods,columns
        !            51:        override Value* get_element4call(const String& aname);
        !            52: #endif
1.62      moko       53:        /// VTable: columns
                     54:        virtual const VJunction* put_element(const String&, Value*);
1.1       paf        55: 
                     56: public: // usage
                     57: 
1.49      paf        58:        VTable(Table* atable=0): ftable(atable) {}
                     59: 
1.14      paf        60:        void set_table(Table& avalue) { 
                     61:                ftable=&avalue; 
                     62:        }
1.49      paf        63:        Table& table() const { 
1.4       paf        64:                if(!ftable)
1.49      paf        65:                        bark("getting unset vtable value", 0);
1.1       paf        66: 
1.4       paf        67:                return *ftable; 
1.1       paf        68:        }
                     69: 
                     70: private:
1.27      parser     71: 
1.49      paf        72:        Value* fields_element();
1.1       paf        73: 
1.57      moko       74:        String& get_json_string_array(String&, const char *);
                     75:        String& get_json_string_object(String&, const char *);
                     76:        String& get_json_string_compact(String&, const char *);
                     77: 
1.18      paf        78: private:
                     79: 
1.49      paf        80:        Table* ftable;
1.1       paf        81: 
                     82: };
                     83: 
                     84: #endif

E-mail: