1 |
|
---|
2 | #include <casa/aips.h>
|
---|
3 | #include <tables/Tables/BaseTable.h>
|
---|
4 | #include <tables/Tables/Table.h>
|
---|
5 | #include <tables/Tables/PlainColumn.h>
|
---|
6 | #include <tables/Tables/DataManager.h>
|
---|
7 | #include <tables/Tables/ScalarColumn.h>
|
---|
8 | #include <tables/Tables/ArrayColumn.h>
|
---|
9 |
|
---|
10 | namespace asap {
|
---|
11 |
|
---|
12 | class TableVisitor {
|
---|
13 | public:
|
---|
14 | virtual ~TableVisitor() {}
|
---|
15 |
|
---|
16 | // This method is called just before the first <src>visit()<src> call.
|
---|
17 | virtual void start() {}
|
---|
18 |
|
---|
19 | // <p><src>isFirst</src> is True only when the first visit.</p>
|
---|
20 | // <p><src>recordNo</src> indicates which record is currently visited.
|
---|
21 | // <p><src>nCols</src> indicates a number of columns used to sort records.
|
---|
22 | // <src>nCols</src> is equal to a number of elements of
|
---|
23 | // <src>columnNames</src> argument of <src>traverseTable()</src>
|
---|
24 | // excluding the trailing NULL element.</p>
|
---|
25 | // <p><src>colValues</src> is an array of arrays which contains all
|
---|
26 | // column values for each column.
|
---|
27 | // For example, <src>colValues[0]</src> is an array which contains all
|
---|
28 | // values of the first column.
|
---|
29 | // The order of <src>colValues</src> is same as the one of
|
---|
30 | // <src>columnNames</src> argument of <src>traverseTable()</src>.</p>
|
---|
31 | // <p>Returning False causes stopping iteration,
|
---|
32 | // otherwise iterate over all records.</p>
|
---|
33 | // <p>If <src>visit()</src> throws an exception, the iteration stops and
|
---|
34 | // <src>finish()</src> will not be called.</p>
|
---|
35 | virtual casa::Bool visit(casa::Bool isFirst, casa::uInt recordNo,
|
---|
36 | casa::uInt nCols,
|
---|
37 | void const *const colValues[]) = 0;
|
---|
38 |
|
---|
39 | // This method is called immediately after all visits have done.
|
---|
40 | virtual void finish() {}
|
---|
41 | };
|
---|
42 |
|
---|
43 | // <src>TypeManager</src> describes a type to handle the type dynamically.
|
---|
44 | class TypeManager {
|
---|
45 | public:
|
---|
46 | virtual ~TypeManager() {}
|
---|
47 | virtual casa::BaseCompare *getComparator() const = 0;
|
---|
48 | virtual size_t sizeOf() const = 0;
|
---|
49 | virtual void *allocArray(size_t size) const = 0;
|
---|
50 | virtual void freeArray(void *array) const = 0;
|
---|
51 | };
|
---|
52 |
|
---|
53 | // This template is applicable to the type which can be applied to
|
---|
54 | // casa::ObjCompare<T>.
|
---|
55 | template<class T> class TypeManagerImpl: public TypeManager {
|
---|
56 | public:
|
---|
57 | virtual casa::BaseCompare *getComparator() const {
|
---|
58 | static casa::ObjCompare<T> comparator;
|
---|
59 | return &comparator;
|
---|
60 | }
|
---|
61 | virtual size_t sizeOf() const {
|
---|
62 | return sizeof(T);
|
---|
63 | }
|
---|
64 | virtual void *allocArray(size_t size) const {
|
---|
65 | return new T[size];
|
---|
66 | }
|
---|
67 | virtual void freeArray(void *array) const {
|
---|
68 | delete[] (T*)array;
|
---|
69 | }
|
---|
70 | };
|
---|
71 |
|
---|
72 |
|
---|
73 | // <p>This function iterates over 'table' and calls 'visitor->visit()'
|
---|
74 | // for each record and, finally, calls 'visitor->finish()'.</p>
|
---|
75 | // <p>'columnNames' should be a NULL terminated array of column names which
|
---|
76 | // will be used to sort records to determine the order of visits.
|
---|
77 | // if 'doSort' is False, 'columnNames' is used only to specify
|
---|
78 | // 'nCols' and 'colValues' arguments for calling 'visitor->visit()'.</p>
|
---|
79 | // <p>'typeManagers' should be a NULL terminated array of TypeManager.
|
---|
80 | // It's number of elements and order of elements should be same as
|
---|
81 | // 'columnNames'.
|
---|
82 | // TypeManagerImpl is useful to create instances of TypeManager.</p>
|
---|
83 | // <p>If 'doSort' is True, the order of visits is ascending order for each
|
---|
84 | // column. 'columnNames[0]' is a primary sort key and columnNames[1]
|
---|
85 | // is a secondary sort key, ...</p>
|
---|
86 | void traverseTable(const casa::Table &table,
|
---|
87 | const char *const columnNames[],
|
---|
88 | const TypeManager *const typeManagers[],
|
---|
89 | TableVisitor *visitor,
|
---|
90 | casa::Bool doSort = casa::True);
|
---|
91 |
|
---|
92 | }
|
---|