DataMethod.hxx

Go to the documentation of this file.
00001 
00002 
00003 
00004 //-----------------------------------------------------------------------------
00005 // CVS: $Revision: 6507 $, $Date: 2009-12-14 17:10:06 +0000 (Mon, 14 Dec 2009) $, $Author: EckhardSutorius $
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 sqlQtag = "", qtag = "";
00089     string usingValue = "";
00090 
00091     for (StringMap::const_iterator targetItr = aTarget.begin();
00092                                    targetItr != aTarget.end();
00093                                    ++targetItr)
00094     {
00095       // @@TODO: Check against TableInfo::ColNotFound
00096       targetCol[targetItr->first]
00097         = aInfo.getAttNo(targetItr->second);
00098       targetUnits[targetItr->first]
00099         = aInfo.getUnits(targetCol[targetItr->first]);
00100       usingValue = aInfo.getUsingValue(targetCol[targetItr->first]);
00101       if (usingValue.length() > 0 && sqlQtag != usingValue)
00102       {
00103         if (sqlQtag.length() > 0)
00104           sqlQtag.append(",");
00105         sqlQtag.append(usingValue);
00106       }
00107     }
00108 
00109     StringMap source;
00110     StringOps::split(sqlQtag, ',', source);
00111 
00112     for (unsigned n = 0; n < source.size(); ++n)
00113     {
00114       if (!StringOps::hasSubstr(qtag, source[n]))
00115       {
00116         if (qtag.length() > 0)
00117           qtag.append(",");
00118         qtag.append(source[n]);
00119       }
00120     }
00121 
00122     IntMap sourceTbl;
00123     IntMap sourceCol;
00124     StringMap sourceUnits;
00125 
00126     for (unsigned n = 0; n < source.size(); ++n)
00127     {
00128       // @@TODO: Check against TableInfo::ColNotFound
00129       sourceTbl[n]   = options.getTableNum(aInfo.getTableName());
00130       sourceCol[n]   = aInfo.getAttNo(source[n]);
00131       sourceUnits[n] = aInfo.getUnits(sourceCol[n]);
00132     }
00133 
00134     setSource(sourceTbl, sourceCol, sourceUnits);
00135     setTarget(targetCol, targetUnits);
00136   }
00137 
00138   //---------------------------------------------------------------------------
00141 
00142   bool determineDetectionSourceAndTarget(const TableInfo *aInfo, int tabNo,
00143                                          const StringMap& aTarget)
00144   {
00145     Options options;
00146     logInfo(aTarget);
00147 
00148     IntMap targetCol;
00149     StringMap targetUnits;
00150 
00151     string sqlQtag = "", qtag = "";
00152     string usingValue = "";
00153     
00154     for (StringMap::const_iterator targetItr = aTarget.begin();
00155                                    targetItr != aTarget.end();
00156                                    ++targetItr)
00157     {
00158       // @@TODO: Check against TableInfo::ColNotFound
00159       targetCol[targetItr->first]
00160         = aInfo[tabNo].getAttNo(targetItr->second);
00161       targetUnits[targetItr->first]
00162         = aInfo[tabNo].getUnits(targetCol[targetItr->first]);
00163       usingValue = aInfo[tabNo].getUsingValue(targetCol[targetItr->first]);
00164       if (usingValue.length() > 0 && sqlQtag != usingValue)
00165       {
00166         if (sqlQtag.length() > 0)
00167           sqlQtag.append(",");
00168         sqlQtag.append(usingValue);
00169       }
00170     }
00171 
00172     StringMap source;
00173     StringOps::split(sqlQtag, ',', source);
00174     
00175     for (unsigned n = 0; n < source.size(); ++n)
00176     {
00177       if (!StringOps::hasSubstr(qtag, source[n]))
00178       {
00179         if (qtag.length() > 0)
00180           qtag.append(",");
00181         qtag.append(source[n]);
00182       }
00183     }
00184     
00185     IntMap sourceTbl;
00186     IntMap sourceCol;
00187     StringMap sourceUnits;
00188     
00189     for (unsigned n = 0; n < source.size(); ++n)
00190     {
00191       // @@TODO: Check against TableInfo::ColNotFound
00192       if (source[n].find('.') != std::string::npos)
00193       {
00194         StringMap qtab;
00195         StringOps::split(source[n], '.', qtab);
00196         sourceTbl[n]   = options.getTableNum(qtab[0]);
00197         sourceCol[n]   = aInfo[sourceTbl[n]].getAttNo(qtab[1]);
00198         sourceUnits[n] = aInfo[sourceTbl[n]].getUnits(sourceCol[n]);
00199       } else {
00200         sourceTbl[n]   = tabNo;
00201         sourceCol[n]   = aInfo[tabNo].getAttNo(source[n]);
00202         sourceUnits[n] = aInfo[tabNo].getUnits(sourceCol[n]);
00203       }
00204     }
00205     setSource(sourceTbl, sourceCol, sourceUnits);
00206     setTarget(targetCol, targetUnits);
00207     bool useOtherTbl = useOtherTables(sourceTbl, tabNo);
00208     return useOtherTbl;
00209   }
00210 
00211   //---------------------------------------------------------------------------
00212   // Here we define 3 pure virtual functions that provides the
00213   // standard interface for a data method. The actual implementation
00214   // for a given method is coded up in the appropriate derived class
00215 
00218   virtual void setSource(IntMap& tbls, IntMap& cols, StringMap units) = 0;
00219 
00222   virtual void setTarget(IntMap& cols, StringMap units) = 0;
00223 
00227   virtual void doit(TableData<DataType>& data, int row1, int row2) = 0;
00228   virtual void doit2(TableData<DataType>& inpData, TableData<DataType>& data, int row1, int row2) = 0;
00229 
00230 protected:
00232   std::string methodName;
00233 };
00234 //-----------------------------------------------------------------------------
00238 template<typename DataType>
00239 class NothingToDo : public DataMethod<DataType>
00240 {
00241 public:
00243   NothingToDo()
00244     { DataMethod<DataType>::methodName = "NothingToDo"; }
00245 
00247   void setSource(IntMap& tbls, IntMap& cols, StringMap units) {}
00248 
00250   void setTarget(IntMap& cols, StringMap units) {}
00251 
00253   void doit(TableData<DataType>& data, int row1, int row2) {}
00254 
00256   void doit2(TableData<DataType>& inpData, TableData<DataType>& data, int row1, int row2) {}
00257 
00258   // explicit Destructor
00259   ~NothingToDo() {}
00260 };
00261 //-----------------------------------------------------------------------------
00262 #endif
00263 //-----------------------------------------------------------------------------
00264 // Change log:
00265 //
00266 // 27-May-2004,  IAB: Original version.
00267 // 15-Mar-2006,  RSC: Moved logMethodInfo() from MakeCSV.hxx to become a method
00268 //                    of this class
00269 // 16-Mar-2006,  RSC: Made function checkArguments() in DataMethodFactory.hxx a
00270 //                    method of DataMethod called determineSourceAndTarget()
00271 //  7-Apr-2008, ETWS: Upgraded to use new detection table layout.
Generated on Mon Oct 4 10:38:34 2010 for WfcamSrc by  doxygen 1.6.3