source: branches/parallel/src/TableTraverse.h @ 2282

Last change on this file since 2282 was 2282, checked in by KohjiNakamura, 13 years ago

Comments in TableTraverse?.h were updated

File size: 3.8 KB
Line 
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
10namespace 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  // <src>casa::ObjCompare&lt;T&gt;</src>.
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 <src>table</src> with calling
74  // <src>visitor->visit()</src> for each record after calling
75  // <src>visitor->start()</src> and, finally, it calls
76  // <src>visitor->finish()</src>.</p>
77  // <p><src>columnNames</src> should be a NULL terminated array of column
78  // names which will be used to sort records to determine the order of visits.
79  // If <src>doSort</src> is False, <src>columnNames</src> is used only to
80  // specify <src>nCols</src> and <src>colValues</src> arguments for calling
81  // <src>visitor->visit()</src>.</p>
82  // <p><src>typeManagers</src> should be a NULL terminated array of
83  // <src>TypeManager</src> too.
84  // It's number of elements and order of elements should be same as
85  // <src>columnNames</src>.
86  // <src>TypeManagerImpl</src> is useful to create instances of
87  // <src>TypeManager</src>.</p>
88  // <p>If <src>doSort</src> is True, the order of visits is ascending order
89  // for each column. <src>columnNames[0]</src> is a primary sort key and
90  // <src>columnNames[1]</src> is a secondary sort key, ...</p>
91  void traverseTable(const casa::Table &table,
92                     const char *const columnNames[],
93                     const TypeManager *const typeManagers[],
94                     TableVisitor *visitor,
95                     casa::Bool doSort = casa::True);
96
97}
Note: See TracBrowser for help on using the repository browser.