00001
00002
00003
00004
00005
00006
00007 #ifndef TABLE_H
00008 #define TABLE_H
00009
00010 #include <string>
00011 #include <cmath>
00012
00013 #include "DataTypes.h"
00014 #include "SchemaException.h"
00015 #include "TableData.hxx"
00016 #include "TableInfo.h"
00017
00018 template<typename DataType>
00019 class Table
00020 {
00021 public:
00023 Table(TableData<DataType>* aDataPtr, TableInfo* aInfoPtr)
00024 : mDataPtr(aDataPtr),
00025 mInfoPtr(aInfoPtr),
00026 mChecked(false),
00027 mHasNaNs(false) { }
00028
00030 ~Table() { }
00031
00039 void checkData(bool aThrowExceptions = false);
00040
00042 bool checkRange();
00043
00044 bool checked() const { return mChecked; }
00045 bool hasNaNs() const { return mHasNaNs; }
00046
00047 const TableData<DataType>* inData() const { return mDataPtr; }
00048 const TableInfo* inSchema() const { return mInfoPtr; }
00049
00052 void testDump();
00053
00056
00057 template <typename ADataType>
00058 void valueOf(const std::string& aName, unsigned aRow,
00059 ADataType& aValue) const
00060 {
00061 int colNum = inSchema()->getAttNo(aName);
00062 if (colNum == TableInfo::ColNotFound)
00063 {
00064 throw SchemaException("Cannot find attribute " + aName +
00065 " in schema table " + inSchema()->getTableName());
00066 }
00067 inData()->value(static_cast<unsigned>(colNum), aRow, aValue);
00068 }
00069
00070 protected:
00071 TableData<DataType>* mDataPtr;
00072 TableInfo* mInfoPtr;
00073 bool mChecked;
00074 bool mHasNaNs;
00075
00078 void bigintTest(TableData<Metadata>& aData, int aCol);
00079
00081 void bigintTest(TableData<Numeric>& aData, int aCol) { }
00082
00085 void varcharTest(TableData<Metadata>& aData,
00086 int aCol,
00087 int aRow,
00088 unsigned aLength);
00089
00091 void varcharTest(TableData<Numeric>& aData,
00092 int aCol,
00093 int aRow,
00094 unsigned aLength) { }
00095
00097 void datetimeTest(TableData<Metadata>& aData,
00098 int aCol,
00099 int aRow);
00100
00102 void datetimeTest(TableData<Numeric>& aData,
00103 int aCol,
00104 int aRow) { }
00105
00107 bool isNaN(Metadata value) const { return value == Metadata("nan") ||
00108 value == Metadata("inf") ||
00109 value == Metadata("-inf"); }
00110
00112 bool isInf(Metadata value) const { return isNaN(value); }
00113
00115 bool isInf(Numeric value) const { return std::isinf(value); }
00116
00118 bool isNaN(Numeric value) const { return value != value; }
00119
00120
00121 };
00122
00123 #include "Table.hxx"
00124
00125 #endif
00126
00127
00128
00129
00130
00131
00132