Annotation of parser3/src/include/pa_table.h, revision 1.34
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.34 ! parser 8: $Id: pa_table.h,v 1.33 2001/05/17 10:22:24 parser Exp $
1.1 paf 9: */
10:
11: #ifndef PA_TABLE_H
12: #define PA_TABLE_H
13:
1.33 parser 14: #include "pa_config_includes.h"
1.1 paf 15: #include "pa_types.h"
16: #include "pa_array.h"
17: #include "pa_hash.h"
1.2 paf 18: #include "pa_string.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.34 ! parser 39: const Array *acolumns,
1.2 paf 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.32 paf 54: /** @return column index from @a column_name. '<0' if no such column
55: if no such colum conditionally 'bark'
56: */
57: int column_name2index(const String& column, bool bark) const;
1.30 paf 58:
1.26 paf 59: /// @return item from @a column
60: const String *item(int column) const;
1.30 paf 61:
62: /// @return item from @a column. '0' if no such column
63: const String *item(const String& column) const {
1.32 paf 64: int index=column_name2index(column, false);
1.30 paf 65: return index>=0?item(index):0;
1.24 paf 66: }
1.23 paf 67:
68: /// saves to text file
69: void save(bool nameless_save, const String& file_spec);
1.2 paf 70:
1.26 paf 71: bool locate(int column, const String& value);
1.31 paf 72: bool locate(const String& column, const String& value);
1.24 paf 73:
1.27 paf 74: const Array& at(int index) const {
75: // force @c const result
76: return *const_cast<const Array *>(static_cast<Array *>(get(index)));
77: }
78:
1.12 paf 79: private:
1.21 paf 80:
81: // where this table came from, may be NULL
82: const String *forigin_string;
1.5 paf 83:
1.1 paf 84: // column name->number lookup table
85: Hash name2number;
86:
1.5 paf 87: // current row
88: int fcurrent;
89:
90: // columns
1.34 ! parser 91: const Array *fcolumns;
1.5 paf 92:
1.24 paf 93: bool valid(int index) const { return index>=0 && index<size(); }
1.2 paf 94:
1.1 paf 95: };
96:
97: #endif
E-mail: