Annotation of parser3/src/include/pa_table.h, revision 1.38
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.36 paf 5: Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru)
1.9 paf 6:
1.38 ! paf 7: $Id: pa_table.h,v 1.37 2001/11/22 15:47:12 paf Exp $
1.1 paf 8: */
9:
10: #ifndef PA_TABLE_H
11: #define PA_TABLE_H
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.1 paf 32: class Table : public Array {
33: public:
34:
1.11 paf 35: Table(Pool& apool,
1.21 paf 36: const String *aorigin,
1.34 parser 37: const Array *acolumns,
1.2 paf 38: int initial_rows=CR_INITIAL_ROWS_DEFAULT);
39:
1.21 paf 40: /// where this table came from, may be NULL
41: const String *origin_string() { return forigin_string; }
42:
1.14 paf 43: /// column names
1.5 paf 44: const Array *columns() { return fcolumns; }
45:
1.18 paf 46: /// moves @a current pointer
1.5 paf 47: void set_current(int acurrent) { fcurrent=acurrent; }
1.17 paf 48: /// @return current pointer
1.25 paf 49: int current() { return fcurrent; }
1.37 paf 50: void offset(bool absolute, int offset);
1.5 paf 51:
1.32 paf 52: /** @return column index from @a column_name. '<0' if no such column
53: if no such colum conditionally 'bark'
54: */
55: int column_name2index(const String& column, bool bark) const;
1.30 paf 56:
1.26 paf 57: /// @return item from @a column
58: const String *item(int column) const;
1.30 paf 59:
60: /// @return item from @a column. '0' if no such column
61: const String *item(const String& column) const {
1.32 paf 62: int index=column_name2index(column, false);
1.30 paf 63: return index>=0?item(index):0;
1.24 paf 64: }
1.23 paf 65:
66: /// saves to text file
67: void save(bool nameless_save, const String& file_spec);
1.2 paf 68:
1.26 paf 69: bool locate(int column, const String& value);
1.31 paf 70: bool locate(const String& column, const String& value);
1.24 paf 71:
1.27 paf 72: const Array& at(int index) const {
73: // force @c const result
74: return *const_cast<const Array *>(static_cast<Array *>(get(index)));
75: }
76:
1.12 paf 77: private:
1.21 paf 78:
79: // where this table came from, may be NULL
80: const String *forigin_string;
1.5 paf 81:
1.1 paf 82: // column name->number lookup table
83: Hash name2number;
84:
1.5 paf 85: // current row
86: int fcurrent;
87:
88: // columns
1.34 parser 89: const Array *fcolumns;
1.5 paf 90:
1.24 paf 91: bool valid(int index) const { return index>=0 && index<size(); }
1.2 paf 92:
1.1 paf 93: };
94:
95: #endif
E-mail: