ConfDataStructures.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: ConfDataStructures.hpp 2956 2011-10-30 09:48:24Z yanweignss $"
00002 
00008 #ifndef GPSTK_CONFDATASTRUCTURES_HPP
00009 #define GPSTK_CONFDATASTRUCTURES_HPP
00010 
00011 //============================================================================
00012 //
00013 //  This file is part of GPSTk, the GPS Toolkit.
00014 //
00015 //  The GPSTk is free software; you can redistribute it and/or modify
00016 //  it under the terms of the GNU Lesser General Public License as published
00017 //  by the Free Software Foundation; either version 2.1 of the License, or
00018 //  any later version.
00019 //
00020 //  The GPSTk is distributed in the hope that it will be useful,
00021 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 //  GNU Lesser General Public License for more details.
00024 //
00025 //  You should have received a copy of the GNU Lesser General Public
00026 //  License along with GPSTk; if not, write to the Free Software Foundation,
00027 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028 //
00029 //  Wei Yan - Chinese Academy of Sciences . 2011
00030 //
00031 //============================================================================
00032 
00033 #include "DataStructures.hpp"
00034 #include "MemoryUtils.hpp"
00035 #include "DayTime.hpp"
00036 #include "Triple.hpp"
00037 #include "ConfData.hpp"
00038 
00039 namespace gpstk
00040 {
00041 
00116 #define bind_f2(name,data) \
00117    {std::vector<std::string> t = StringUtils::split(#data,".->"); \
00118    bindConfig(name,data,std::string(*t.rbegin()),"","");}
00119 
00120 #define bind_f3(name,data,valc) \
00121    {std::vector<std::string> t = StringUtils::split(#data,".->"); \
00122    bindConfig(name,data,std::string(*t.rbegin()),"",valc);}
00123 
00124 #define bind_f4(name,data,varc,valc) \
00125    {std::vector<std::string> t = StringUtils::split(#data,".->"); \
00126    bindConfig(name,data,std::string(*t.rbegin()),varc,valc);}
00127 
00128 
00131    template <class HEADER_CLASS, class BODY_CLASS>
00132    struct gnssConfData : public gnssData< HEADER_CLASS, std::vector< BODY_CLASS > >
00133    {
00134       typedef std::vector< BODY_CLASS > BodyVec;
00135       
00136       gnssConfData()
00137          : config(
00138               ConfCallBack< gnssConfData<HEADER_CLASS,BODY_CLASS> >
00139               (*this,
00140                &gnssConfData<HEADER_CLASS,BODY_CLASS>::defineBodyLoad) ) 
00141       {
00142          config.setVariableWidth(20);
00143          config.setValuePrecision(6);
00144       }
00145       
00146       void setVariableWidth(const int width = 0)
00147       { config.setVariableWidth(width);}
00148 
00149       void setValuePrecision(const int precision = 6)
00150       { config.setValuePrecision(precision);}
00151 
00152       gnssConfData& init()
00153       { config.clear(); return (*this); }
00154       
00155 
00156       gnssConfData& load(const std::string& fileName)
00157       {
00158          init();
00159          defineHeader();
00160          config.load(fileName);
00161 
00162          return (*this);
00163       }
00164 
00165       gnssConfData& save(const std::string& fileName)
00166       {
00167          init();
00168          defineHeader();
00169          defineBodySave();
00170          config.save(fileName);
00171          
00172          return (*this);
00173       }
00174 
00175       gnssConfData& keepOnly(const std::string& name)
00176       {
00177          BODY_CLASS toKeep;;
00178          for(BodyVec::iterator it=body.begin();
00179              it!=body.end();
00180              ++it)
00181          {
00182             if(StringUtils::upperCase(it->name)==StringUtils::upperCase(name))
00183             {
00184                toKeep = *it;
00185             }
00186          }
00187 
00188          body.clear();
00189          if(toKeep.name==name) body.push_back(toKeep);
00190 
00191          return (*this);
00192       }
00193 
00194    protected:
00195 
00196       template<class DataType>
00197       gnssConfData& bindConfig(const std::string& section,
00198          DataType& data,
00199          const std::string& var,
00200          const std::string& varComment="",
00201          const std::string& valComment="")
00202       {
00203          ConfDataItemAbstract* pitem = 
00204             new ConfDataItem<DataType>(data,       var, "",
00205             varComment, valComment);
00206 
00207          itemPool.add(pitem); 
00208 
00209          string name = section;
00210          if(name=="") name = ConfData< gnssConfData<HEADER_CLASS,BODY_CLASS> >::Default;
00211 
00212          config.add_section(name);
00213          config.append_section(pitem,name);
00214 
00215          return (*this);
00216       }
00217 
00218       // The following method have to be overrided
00219       virtual void defineHeader() {}
00220       virtual void defineBody(BODY_CLASS& item){}
00221 
00222       void defineBodySave()
00223       {
00224          for(BodyVec::iterator it=body.begin();
00225              it!=body.end();
00226              ++it)
00227          { defineBody(*it); }
00228       }
00229 
00230       void defineBodyLoad(const std::string& name)
00231       {
00232          BODY_CLASS temp;
00233          temp.name = name;
00234 
00235          body.push_back(temp);
00236 
00237          defineBody(*body.rbegin());
00238       }
00239 
00240          // An graceful way to handle the pointers
00241       AutoReleasePool< ConfDataItemAbstract,
00242                        ReleasePolicy<ConfDataItemAbstract> > itemPool;
00243 
00244       ConfData< gnssConfData<HEADER_CLASS,BODY_CLASS> > config;
00245    };
00246       
00247 }   // End of namespace gpstk
00248 
00249 
00250 #endif  //GPSTK_CONFDATASTRUCTURES_HPP
00251 

Generated on Tue May 22 03:30:57 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1