Annotation of parser3/src/types/pa_vtable.h, revision 1.73
1.6 paf 1: /** @file
1.15 paf 2: Parser: @b table parser class decl.
1.6 paf 3:
1.72 moko 4: Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com)
1.70 moko 5: Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
1.1 paf 6: */
7:
8: #ifndef PA_VTABLE_H
9: #define PA_VTABLE_H
1.39 paf 10:
1.73 ! moko 11: #define IDENT_PA_VTABLE_H "$Id: pa_vtable.h,v 1.72 2026/04/25 13:38:46 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.73 ! moko 46: /// VTable: columns
1.55 misha 47: override Value* get_element(const String& aname);
1.62 moko 48: /// VTable: columns
49: virtual const VJunction* put_element(const String&, Value*);
1.1 paf 50:
51: public: // usage
52:
1.49 paf 53: VTable(Table* atable=0): ftable(atable) {}
54:
1.14 paf 55: void set_table(Table& avalue) {
56: ftable=&avalue;
57: }
1.49 paf 58: Table& table() const {
1.4 paf 59: if(!ftable)
1.49 paf 60: bark("getting unset vtable value", 0);
1.1 paf 61:
1.4 paf 62: return *ftable;
1.1 paf 63: }
64:
65: private:
1.27 parser 66:
1.49 paf 67: Value* fields_element();
1.1 paf 68:
1.57 moko 69: String& get_json_string_array(String&, const char *);
70: String& get_json_string_object(String&, const char *);
71: String& get_json_string_compact(String&, const char *);
72:
1.18 paf 73: private:
74:
1.49 paf 75: Table* ftable;
1.1 paf 76:
77: };
78:
79: #endif
E-mail: