// // C++ Interface: TableTraverse // // Description: // // Copyright: See COPYING file that comes with this distribution // /* * $Id: TableTraverse.h 3106 2016-10-04 07:20:50Z TakeshiNakazato $ */ #ifndef ASAP_TABLETRAVERSE_H #define ASAP_TABLETRAVERSE_H #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 casacore::Bool visit(casacore::Bool isFirst, casacore::uInt recordNo, casacore::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 casacore::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 // casacore::ObjCompare<T>. template class TypeManagerImpl: public TypeManager { public: TypeManagerImpl(){} virtual casacore::BaseCompare *getComparator() const { static casacore::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 with calling // visitor->visit() for each record after calling // visitor->start() and, finally, it 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 too. // 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 casacore::Table &table, const char *const columnNames[], const TypeManager *const typeManagers[], TableVisitor *visitor, casacore::Bool doSort = casacore::True); } #endif