Annotation of parser3/src/include/pa_table.h, revision 1.31
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.31 ! paf 8: $Id: pa_table.h,v 1.30 2001/05/07 08:29:42 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.30 paf 53: /// @return column index from @a column_name. '<0' if no such column
54: int column_name2index(const String& column) const;
55:
1.26 paf 56: /// @return item from @a column
57: const String *item(int column) const;
1.30 paf 58:
59: /// @return item from @a column. '0' if no such column
60: const String *item(const String& column) const {
61: int index=column_name2index(column);
62: return index>=0?item(index):0;
1.24 paf 63: }
1.23 paf 64:
65: /// saves to text file
66: void save(bool nameless_save, const String& file_spec);
1.2 paf 67:
1.26 paf 68: bool locate(int column, const String& value);
1.31 ! paf 69: bool locate(const String& column, const String& value);
1.24 paf 70:
1.27 paf 71: const Array& at(int index) const {
72: // force @c const result
73: return *const_cast<const Array *>(static_cast<Array *>(get(index)));
74: }
75:
1.12 paf 76: private:
1.21 paf 77:
78: // where this table came from, may be NULL
79: const String *forigin_string;
1.5 paf 80:
1.1 paf 81: // column name->number lookup table
82: Hash name2number;
83:
1.5 paf 84: // current row
85: int fcurrent;
86:
87: // columns
88: Array *fcolumns;
89:
1.24 paf 90: bool valid(int index) const { return index>=0 && index<size(); }
1.2 paf 91:
1.1 paf 92: };
93:
94: #endif
E-mail: