#include #include #include #include #include #include #include namespace asap { class TableVisitor { public: virtual ~TableVisitor() {} // This method is called just before the first visit() call. virtual void start() {} //

isFirst is True only when the first visit.

//

recordNo indicates which record is currently visited. //

nCols indicates a number of columns used to sort records. // nCols is equal to a number of elements of // columnNames argument of traverseTable() // excluding the trailing NULL element.

//

colValues is an array of arrays which contains all // column values for each column. // For example, colValues[0] is an array which contains all // values of the first column. // The order of colValues is same as the one of // columnNames argument of traverseTable().

//

Returning False causes stopping iteration, // otherwise iterate over all records.

//

If visit() throws an exception, the iteration stops and // finish() will not be called.

virtual casa::Bool visit(casa::Bool isFirst, casa::uInt recordNo, casa::uInt nCols, void const *const colValues[]) = 0; // This method is called immediately after all visits have done. virtual void finish() {} }; // TypeManager describes a type to handle the type dynamically. class TypeManager { public: virtual ~TypeManager() {} virtual casa::BaseCompare *getComparator() const = 0; virtual size_t sizeOf() const = 0; virtual void *allocArray(size_t size) const = 0; virtual void freeArray(void *array) const = 0; }; // This template is applicable to the type which can be applied to // casa::ObjCompare. template class TypeManagerImpl: public TypeManager { public: virtual casa::BaseCompare *getComparator() const { static casa::ObjCompare comparator; return &comparator; } virtual size_t sizeOf() const { return sizeof(T); } virtual void *allocArray(size_t size) const { return new T[size]; } virtual void freeArray(void *array) const { delete[] (T*)array; } }; //

This function iterates over 'table' and calls 'visitor->visit()' // for each record and, finally, calls 'visitor->finish()'.

//

'columnNames' should be a NULL terminated array of column names which // will be used to sort records to determine the order of visits. // if 'doSort' is False, 'columnNames' is used only to specify // 'nCols' and 'colValues' arguments for calling 'visitor->visit()'.

//

'typeManagers' should be a NULL terminated array of TypeManager. // It's number of elements and order of elements should be same as // 'columnNames'. // TypeManagerImpl is useful to create instances of TypeManager.

//

If 'doSort' is True, the order of visits is ascending order for each // column. 'columnNames[0]' is a primary sort key and columnNames[1] // is a secondary sort key, ...

void traverseTable(const casa::Table &table, const char *const columnNames[], const TypeManager *const typeManagers[], TableVisitor *visitor, casa::Bool doSort = casa::True); }