Annotation of parser3/src/types/pa_vtable.h, revision 1.19
1.6 paf 1: /** @file
1.15 paf 2: Parser: @b table parser class decl.
1.6 paf 3:
1.1 paf 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.6 paf 5:
1.1 paf 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
7:
1.19 ! paf 8: $Id: pa_vtable.h,v 1.18 2001/05/07 08:29:48 paf Exp $
1.1 paf 9: */
10:
11: #ifndef PA_VTABLE_H
12: #define PA_VTABLE_H
13:
14: #include "pa_vstateless_object.h"
15: #include "pa_table.h"
16: #include "pa_vunknown.h"
17:
1.16 paf 18: extern Methoded *table_class;
19:
1.6 paf 20: /// value of type 'table'. implemented with Table
1.1 paf 21: class VTable : public VStateless_object {
22: public: // Value
23:
1.6 paf 24: /// all: for error reporting after fail(), etc
1.1 paf 25: const char *type() const { return "table"; }
1.6 paf 26: /// extract VTable
1.10 paf 27: Table *get_table() { return ftable; }
1.18 paf 28: /// VTable: columns,methods
1.1 paf 29: Value *get_element(const String& name) {
1.17 paf 30: // columns
1.18 paf 31: if(ftable) {
32: int index=ftable->column_name2index(name);
1.19 ! paf 33: if(index>=0) // column name|number valid
! 34: if(const String *string=ftable->item(index)) // there is such column
! 35: return NEW VString(*string);
1.18 paf 36: }
1.17 paf 37:
1.3 paf 38: // methods
1.2 paf 39: if(Value *result=VStateless_object::get_element(name))
40: return result;
1.1 paf 41:
1.18 paf 42: THROW(0, 0,
43: &name,
44: "column not found");
45: return 0; //unreached
1.1 paf 46: }
1.7 paf 47:
1.11 paf 48: public:
49:
50: bool last_locate_was_successful;
51:
1.7 paf 52: protected: // VAliased
53:
1.9 paf 54: /// disable .CLASS element. @see VAliased::get_element
1.13 paf 55: bool hide_class() { return true; }
1.1 paf 56:
57: public: // usage
58:
1.12 paf 59: VTable(Pool& apool, Table* atable=0) : VStateless_object(apool, *table_class),
1.14 paf 60: ftable(atable), locked(false),
1.11 paf 61: last_locate_was_successful(false) {
1.1 paf 62: }
1.16 paf 63: void lock() {
64: check_lock();
65: locked=true;
66: }
1.14 paf 67: void unlock() { locked=false; }
68: void set_table(Table& avalue) {
1.16 paf 69: check_lock();
1.14 paf 70: ftable=&avalue;
71: }
1.1 paf 72: Table& table() {
1.4 paf 73: if(!ftable)
1.1 paf 74: bark("getting unset vtable value");
75:
1.4 paf 76: return *ftable;
1.1 paf 77: }
78:
79: private:
80:
1.16 paf 81: void check_lock() {
82: if(locked)
83: bark("is locked");
84: }
1.18 paf 85:
86: private:
87:
88: Table *ftable;
89: bool locked;
1.1 paf 90:
91: };
92:
93: #endif
E-mail: