Annotation of parser3/src/include/pa_table.h, revision 1.29
1.14 paf 1: /** @file
1.15 paf 2: Parser: table class decl.
3:
1.9 paf 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.15 paf 5:
1.10 paf 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.9 paf 7:
1.29 ! paf 8: $Id: pa_table.h,v 1.28 2001/04/02 09:29:18 paf Exp $
1.1 paf 9: */
10:
11: #ifndef PA_TABLE_H
12: #define PA_TABLE_H
13:
14: #include "pa_types.h"
15: #include "pa_array.h"
16: #include "pa_hash.h"
1.2 paf 17: #include "pa_string.h"
1.1 paf 18:
1.16 paf 19: /**
1.19 paf 20: VTable backend.
1.16 paf 21:
22: holds:
1.14 paf 23: - column names[if any]
24: - data rows
25: - current row pointer
26:
27: uses String for column names and data items
28:
1.28 paf 29: hence most of tables are "named", no need to uptimize nameless onces.
30: rows and strings stored are read-only. once stored they can be removed,
31: but not altered. that's handy for quick copying & co. see table:join
1.14 paf 32: */
1.1 paf 33: class Table : public Array {
34: public:
35:
1.11 paf 36: Table(Pool& apool,
1.21 paf 37: const String *aorigin,
1.2 paf 38: Array *acolumns,
39: int initial_rows=CR_INITIAL_ROWS_DEFAULT);
40:
1.21 paf 41: /// where this table came from, may be NULL
42: const String *origin_string() { return forigin_string; }
43:
1.14 paf 44: /// column names
1.5 paf 45: const Array *columns() { return fcolumns; }
46:
1.18 paf 47: /// moves @a current pointer
1.5 paf 48: void set_current(int acurrent) { fcurrent=acurrent; }
1.17 paf 49: /// @return current pointer
1.25 paf 50: int current() { return fcurrent; }
51: void shift(int offset);
1.5 paf 52:
1.26 paf 53: /// @return item from @a column
54: const String *item(int column) const;
55: /// @return item from @a column
1.24 paf 56: const String *item(const String& column) const {
57: return item(column_name2index(column));
58: }
1.23 paf 59:
60: /// saves to text file
61: void save(bool nameless_save, const String& file_spec);
1.2 paf 62:
1.26 paf 63: bool locate(int column, const String& value);
64: bool locate(const String& column, const String& value) {
65: return locate(column_name2index(column), value);
66: }
1.24 paf 67:
1.27 paf 68: const Array& at(int index) const {
69: // force @c const result
70: return *const_cast<const Array *>(static_cast<Array *>(get(index)));
71: }
72:
1.12 paf 73: private:
1.21 paf 74:
75: // where this table came from, may be NULL
76: const String *forigin_string;
1.5 paf 77:
1.1 paf 78: // column name->number lookup table
79: Hash name2number;
80:
1.5 paf 81: // current row
82: int fcurrent;
83:
84: // columns
85: Array *fcolumns;
86:
1.24 paf 87: bool valid(int index) const { return index>=0 && index<size(); }
88:
89: /// @return column index from @a column_name
1.25 paf 90: int column_name2index(const String& column) const;
1.12 paf 91:
1.2 paf 92:
1.1 paf 93: };
94:
95: #endif
E-mail: