00001
00002
00003
00004
00005
00006
00007 #ifndef DATAMETHOD_H
00008 #define DATAMETHOD_H
00009
00010 #include <string>
00011
00012 #include "DataTypes.h"
00013 #include "Logger.h"
00014 #include "MyException.h"
00015 #include "Options.h"
00016 #include "StringOps.h"
00017 #include "TableData.hxx"
00018 #include "TableInfo.h"
00019
00022 class DataMethodException : public MyException
00023 {
00024 public:
00025 DataMethodException(const std::string& aMsg)
00026 : MyException("DataMethodException: ", aMsg) { }
00027 };
00028
00034 template<typename DataType>
00035 class DataMethod
00036 {
00037 public:
00041 DataMethod() { methodName = "Unspecified DataMethod"; }
00042
00044 virtual ~DataMethod() { }
00045
00048 const std::string& getName() const { return methodName; }
00049
00050
00052 void logInfo(const StringMap& aTarget)
00053 {
00054 std::string mess("Instantiated method '" + methodName + "' for targets: ");
00055 for (StringMap::const_iterator targetItr = aTarget.begin();
00056 targetItr != aTarget.end();
00057 ++targetItr)
00058 {
00059 mess += targetItr->second + " ";
00060 }
00061 Logger log;
00062 log.addMessage(mess);
00063 }
00064
00065
00066 bool useOtherTables(IntMap& sourceTbl, int tabNo)
00067 {
00068 for (unsigned n = 0; n < sourceTbl.size(); ++n)
00069 {
00070 if (tabNo != sourceTbl[n]) { return true; }
00071 }
00072 return false;
00073 }
00074
00075
00078
00079 void determineSourceAndTarget(const TableInfo& aInfo,
00080 const StringMap& aTarget)
00081 {
00082 Options options;
00083 logInfo(aTarget);
00084
00085 IntMap targetCol;
00086 StringMap targetUnits;
00087
00088 string qtag;
00089 for (StringMap::const_iterator targetItr = aTarget.begin();
00090 targetItr != aTarget.end();
00091 ++targetItr)
00092 {
00093
00094 targetCol[targetItr->first]
00095 = aInfo.getAttNo(targetItr->second);
00096 targetUnits[targetItr->first]
00097 = aInfo.getUnits(targetCol[targetItr->first]);
00098
00099 qtag = aInfo.getUsingValue(targetCol[targetItr->first]);
00100 }
00101
00102 StringMap source;
00103 StringOps::split(qtag, ',', source);
00104
00105 IntMap sourceTbl;
00106 IntMap sourceCol;
00107 StringMap sourceUnits;
00108
00109 for (unsigned n = 0; n < source.size(); ++n)
00110 {
00111
00112 sourceTbl[n] = options.getTableNum(aInfo.getTableName());
00113 sourceCol[n] = aInfo.getAttNo(source[n]);
00114 sourceUnits[n] = aInfo.getUnits(sourceCol[n]);
00115 }
00116
00117 setSource(sourceTbl, sourceCol, sourceUnits);
00118 setTarget(targetCol, targetUnits);
00119 }
00120
00121
00124
00125 bool determineDetectionSourceAndTarget(const TableInfo *aInfo, int tabNo,
00126 const StringMap& aTarget)
00127 {
00128 Options options;
00129 logInfo(aTarget);
00130
00131 IntMap targetCol;
00132 StringMap targetUnits;
00133
00134 string qtag;
00135 for (StringMap::const_iterator targetItr = aTarget.begin();
00136 targetItr != aTarget.end();
00137 ++targetItr)
00138 {
00139
00140 targetCol[targetItr->first]
00141 = aInfo[tabNo].getAttNo(targetItr->second);
00142 targetUnits[targetItr->first]
00143 = aInfo[tabNo].getUnits(targetCol[targetItr->first]);
00144
00145 qtag = aInfo[tabNo].getUsingValue(targetCol[targetItr->first]);
00146 }
00147
00148 StringMap source;
00149 StringOps::split(qtag, ',', source);
00150
00151 IntMap sourceTbl;
00152 IntMap sourceCol;
00153 StringMap sourceUnits;
00154
00155 for (unsigned n = 0; n < source.size(); ++n)
00156 {
00157
00158 if (source[n].find('.') != std::string::npos)
00159 {
00160 StringMap qtab;
00161 StringOps::split(source[n], '.', qtab);
00162 sourceTbl[n] = options.getTableNum(qtab[0]);
00163 sourceCol[n] = aInfo[sourceTbl[n]].getAttNo(qtab[1]);
00164 sourceUnits[n] = aInfo[sourceTbl[n]].getUnits(sourceCol[n]);
00165 } else {
00166 sourceTbl[n] = tabNo;
00167 sourceCol[n] = aInfo[tabNo].getAttNo(source[n]);
00168 sourceUnits[n] = aInfo[tabNo].getUnits(sourceCol[n]);
00169 }
00170 }
00171 setSource(sourceTbl, sourceCol, sourceUnits);
00172 setTarget(targetCol, targetUnits);
00173 bool useOtherTbl = useOtherTables(sourceTbl, tabNo);
00174 return useOtherTbl;
00175 }
00176
00177
00178
00179
00180
00181
00184 virtual void setSource(IntMap& tbls, IntMap& cols, StringMap units) = 0;
00185
00188 virtual void setTarget(IntMap& cols, StringMap units) = 0;
00189
00193 virtual void doit(TableData<DataType>& data, int row1, int row2) = 0;
00194 virtual void doit2(TableData<DataType>& inpData, TableData<DataType>& data, int row1, int row2) = 0;
00195
00196 protected:
00198 std::string methodName;
00199 };
00200
00204 template<typename DataType>
00205 class NothingToDo : public DataMethod<DataType>
00206 {
00207 public:
00209 NothingToDo()
00210 { DataMethod<DataType>::methodName = "NothingToDo"; }
00211
00213 void setSource(IntMap& tbls, IntMap& cols, StringMap units) {}
00214
00216 void setTarget(IntMap& cols, StringMap units) {}
00217
00219 void doit(TableData<DataType>& data, int row1, int row2) {}
00220
00222 void doit2(TableData<DataType>& inpData, TableData<DataType>& data, int row1, int row2) {}
00223
00224
00225 ~NothingToDo() {}
00226 };
00227
00228 #endif
00229
00230
00231
00232
00233
00234
00235
00236
00237