Annotation of parser3/src/include/pa_table.h, revision 1.48.2.5
1.14 paf 1: /** @file
1.15 paf 2: Parser: table class decl.
3:
1.48 paf 4: Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com)
1.41 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1 paf 6: */
7:
8: #ifndef PA_TABLE_H
9: #define PA_TABLE_H
1.45 paf 10:
1.48.2.5! paf 11: static const char* IDENT_TABLE_H="$Date: 2003/01/24 11:33:02 $";
1.1 paf 12:
13: #include "pa_types.h"
14: #include "pa_array.h"
15: #include "pa_hash.h"
1.2 paf 16: #include "pa_string.h"
1.1 paf 17:
1.16 paf 18: /**
1.19 paf 19: VTable backend.
1.16 paf 20:
21: holds:
1.14 paf 22: - column names[if any]
23: - data rows
24: - current row pointer
25:
26: uses String for column names and data items
27:
1.28 paf 28: hence most of tables are "named", no need to uptimize nameless onces.
29: rows and strings stored are read-only. once stored they can be removed,
30: but not altered. that's handy for quick copying & co. see table:join
1.14 paf 31: */
1.48.2.4 paf 32: class Table: public Array<object_ptr<const Array<ConstStringPtr > > > {
1.1 paf 33: public:
1.48.2.4 paf 34: typedef object_ptr<const Array<ConstStringPtr> > columns_type;
1.1 paf 35:
1.48.2.1 paf 36: Table(
1.48.2.3 paf 37: ConstStringPtr aorigin_string,
1.48.2.4 paf 38: columns_type acolumns,
1.48.2.1 paf 39: int initial_rows=3);
40: Table(const Table& src, int offset=0, int limit=0);
1.2 paf 41:
1.21 paf 42: /// where this table came from, may be NULL
1.48.2.3 paf 43: ConstStringPtr origin_string() { return forigin_string; }
1.21 paf 44:
1.42 paf 45: /// gets column names
1.48.2.4 paf 46: columns_type columns() { return fcolumns; }
1.5 paf 47:
1.18 paf 48: /// moves @a current pointer
1.5 paf 49: void set_current(int acurrent) { fcurrent=acurrent; }
1.17 paf 50: /// @return current pointer
1.47 paf 51: int current() const { return fcurrent; }
1.37 paf 52: void offset(bool absolute, int offset);
1.5 paf 53:
1.32 paf 54: /** @return column index from @a column_name. '<0' if no such column
1.48.2.1 paf 55: if no such - 'bark'
1.32 paf 56: */
1.48.2.4 paf 57: int column_name2index(ConstStringPtr column, bool bark) const;
1.30 paf 58:
1.26 paf 59: /// @return item from @a column
1.48.2.4 paf 60: ConstStringPtr item(int column) const;
1.30 paf 61:
62: /// @return item from @a column. '0' if no such column
1.48.2.4 paf 63: ConstStringPtr item(ConstStringPtr column) const {
1.32 paf 64: int index=column_name2index(column, false);
1.48.2.4 paf 65: return index>=0?item(index):ConstStringPtr(0);
1.24 paf 66: }
1.23 paf 67:
68: /// saves to text file
1.48.2.2 paf 69: void save(bool nameless_save, object_ptr<const String> file_spec);
1.2 paf 70:
1.48.2.4 paf 71: bool locate(int column, ConstStringPtr value);
72: bool locate(object_ptr<const String> column, ConstStringPtr value);
1.24 paf 73:
1.48.2.1 paf 74: element_type at(int index) const {
75: return get(index);
1.27 paf 76: }
77:
1.12 paf 78: private:
1.21 paf 79:
80: // where this table came from, may be NULL
1.48.2.3 paf 81: ConstStringPtr forigin_string;
1.1 paf 82:
1.5 paf 83: // current row
84: int fcurrent;
85:
86: // columns
1.48.2.4 paf 87: columns_type fcolumns;
1.48.2.1 paf 88:
89: // column names are already referenced in fcolumns, no need to doublecheck references here
90: // column name->number lookup table
1.48.2.5! paf 91: typedef Hash<const String&, int> name2number_hash_class;
1.48.2.1 paf 92: object_ptr<name2number_hash_class> name2number;
93:
94: // we own columns?
1.5 paf 95:
1.48.2.1 paf 96: bool valid(int index) const { return index>=0 && index<count(); }
1.2 paf 97:
1.1 paf 98: };
1.48.2.3 paf 99:
100: typedef object_ptr<Table> TablePtr;
1.1 paf 101:
102: #endif
E-mail: