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

Last change on this file since 2338 was 2284, checked in by KohjiNakamura, 13 years ago
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1//
2// C++ Interface: TableTraverse
3//
4// Description:
5//
6// Copyright: See COPYING file that comes with this distribution
7//
8
9/*
10 * $Id: TableTraverse.h 2284 2011-08-30 00:34:46Z KohjiNakamura $
11 */
12
13#ifndef ASAP_TABLETRAVERSE_H
14#define ASAP_TABLETRAVERSE_H
15
16#include <casa/aips.h>
17#include <tables/Tables/BaseTable.h>
18#include <tables/Tables/Table.h>
19
20namespace asap {
21
22 class TableVisitor {
23 public:
24 virtual ~TableVisitor() {}
25
26 // This method is called just before the first <src>visit()<src> call.
27 virtual void start() {}
28
29 // <p><src>isFirst</src> is True only when the first visit.</p>
30 // <p><src>recordNo</src> indicates which record is currently visited.
31 // <p><src>nCols</src> indicates a number of columns used to sort records.
32 // <src>nCols</src> is equal to a number of elements of
33 // <src>columnNames</src> argument of <src>traverseTable()</src>
34 // excluding the trailing NULL element.</p>
35 // <p><src>colValues</src> is an array of arrays which contains all
36 // column values for each column.
37 // For example, <src>colValues[0]</src> is an array which contains all
38 // values of the first column.
39 // The order of <src>colValues</src> is same as the one of
40 // <src>columnNames</src> argument of <src>traverseTable()</src>.</p>
41 // <p>Returning False causes stopping iteration,
42 // otherwise iterate over all records.</p>
43 // <p>If <src>visit()</src> throws an exception, the iteration stops and
44 // <src>finish()</src> will not be called.</p>
45 virtual casa::Bool visit(casa::Bool isFirst, casa::uInt recordNo,
46 casa::uInt nCols,
47 void const *const colValues[]) = 0;
48
49 // This method is called immediately after all visits have done.
50 virtual void finish() {}
51 };
52
53 // <src>TypeManager</src> describes a type to handle the type dynamically.
54 class TypeManager {
55 public:
56 virtual ~TypeManager() {}
57 virtual casa::BaseCompare *getComparator() const = 0;
58 virtual size_t sizeOf() const = 0;
59 virtual void *allocArray(size_t size) const = 0;
60 virtual void freeArray(void *array) const = 0;
61 };
62
63 // This template is applicable to the type which can be applied to
64 // <src>casa::ObjCompare&lt;T&gt;</src>.
65 template<class T> class TypeManagerImpl: public TypeManager {
66 public:
67 virtual casa::BaseCompare *getComparator() const {
68 static casa::ObjCompare<T> comparator;
69 return &comparator;
70 }
71 virtual size_t sizeOf() const {
72 return sizeof(T);
73 }
74 virtual void *allocArray(size_t size) const {
75 return new T[size];
76 }
77 virtual void freeArray(void *array) const {
78 delete[] (T*)array;
79 }
80 };
81
82
83 // <p>This function iterates over <src>table</src> with calling
84 // <src>visitor->visit()</src> for each record after calling
85 // <src>visitor->start()</src> and, finally, it calls
86 // <src>visitor->finish()</src>.</p>
87 // <p><src>columnNames</src> should be a NULL terminated array of column
88 // names which will be used to sort records to determine the order of visits.
89 // If <src>doSort</src> is False, <src>columnNames</src> is used only to
90 // specify <src>nCols</src> and <src>colValues</src> arguments for calling
91 // <src>visitor->visit()</src>.</p>
92 // <p><src>typeManagers</src> should be a NULL terminated array of
93 // <src>TypeManager</src> too.
94 // It's number of elements and order of elements should be same as
95 // <src>columnNames</src>.
96 // <src>TypeManagerImpl</src> is useful to create instances of
97 // <src>TypeManager</src>.</p>
98 // <p>If <src>doSort</src> is True, the order of visits is ascending order
99 // for each column. <src>columnNames[0]</src> is a primary sort key and
100 // <src>columnNames[1]</src> is a secondary sort key, ...</p>
101 void traverseTable(const casa::Table &table,
102 const char *const columnNames[],
103 const TypeManager *const typeManagers[],
104 TableVisitor *visitor,
105 casa::Bool doSort = casa::True);
106
107}
108
109#endif
Note: See TracBrowser for help on using the repository browser.