Annotation of parser3/src/include/pa_table.h, revision 1.28
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.28 ! paf 8: $Id: pa_table.h,v 1.27 2001/03/29 20:53:03 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"
18: #include "pa_request.h"
1.1 paf 19:
1.16 paf 20: /**
1.19 paf 21: VTable backend.
1.16 paf 22:
23: holds:
1.14 paf 24: - column names[if any]
25: - data rows
26: - current row pointer
27:
28: uses String for column names and data items
29:
1.28 ! paf 30: hence most of tables are "named", no need to uptimize nameless onces.
! 31: rows and strings stored are read-only. once stored they can be removed,
! 32: but not altered. that's handy for quick copying & co. see table:join
1.14 paf 33: */
1.1 paf 34: class Table : public Array {
35: public:
36:
1.11 paf 37: Table(Pool& apool,
1.21 paf 38: const String *aorigin,
1.2 paf 39: Array *acolumns,
40: int initial_rows=CR_INITIAL_ROWS_DEFAULT);
41:
1.21 paf 42: /// where this table came from, may be NULL
43: const String *origin_string() { return forigin_string; }
44:
1.14 paf 45: /// column names
1.5 paf 46: const Array *columns() { return fcolumns; }
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.25 paf 51: int current() { return fcurrent; }
52: void shift(int offset);
1.5 paf 53:
1.26 paf 54: /// @return item from @a column
55: const String *item(int column) const;
56: /// @return item from @a column
1.24 paf 57: const String *item(const String& column) const {
58: return item(column_name2index(column));
59: }
1.23 paf 60:
61: /// saves to text file
62: void save(bool nameless_save, const String& file_spec);
1.2 paf 63:
1.26 paf 64: bool locate(int column, const String& value);
65: bool locate(const String& column, const String& value) {
66: return locate(column_name2index(column), value);
67: }
1.24 paf 68:
1.27 paf 69: const Array& at(int index) const {
70: // force @c const result
71: return *const_cast<const Array *>(static_cast<Array *>(get(index)));
72: }
73:
1.12 paf 74: private:
1.21 paf 75:
76: // where this table came from, may be NULL
77: const String *forigin_string;
1.5 paf 78:
1.1 paf 79: // column name->number lookup table
80: Hash name2number;
81:
1.5 paf 82: // current row
83: int fcurrent;
84:
85: // columns
86: Array *fcolumns;
87:
1.24 paf 88: bool valid(int index) const { return index>=0 && index<size(); }
89:
90: /// @return column index from @a column_name
1.25 paf 91: int column_name2index(const String& column) const;
1.12 paf 92:
1.2 paf 93:
1.1 paf 94: };
95:
96: #endif
E-mail: