CommandSwitchFunctions.hh

Go to the documentation of this file.
00001 //Copyright 2013 Ben Loer
00002 //This file is part of the ConfigHandler library
00003 //It is released under the terms of the GNU General Public License v3
00004 
00011 #ifndef COMMANDSWITCHFUNCTIONS_h
00012 #define COMMANDSWITCHFUNCTIONS_h
00013 #include <sstream>
00014 #include <string>
00015 #include "VParameterNode.hh"
00016 #include "ConfigHandler.hh"
00017  
00022 namespace CommandSwitch{
00023   
00026   
00030   template<class T> class DefaultRead{
00031     T& param;
00032   public:
00033     DefaultRead(T& t) : param(t) {}
00034     int operator()(const char* newval)
00035     { 
00036       std::istringstream s(newval);
00037       if(s >> param || s.eof())
00038         return 0;
00039       return -1;
00040     }
00041   };
00042   //specialize for string
00043   template<> class DefaultRead<std::string>{
00044     std::string& param;
00045   public:
00046     DefaultRead(std::string& s) : param(s) {}
00047     int operator()(const char* newval) { param = newval; return 0; }
00048   };
00049    
00053   class LoadConfigFile{
00054     VParameterNode *l;
00055   public:
00056     LoadConfigFile(VParameterNode* par) : l(par) {}
00057     int operator()(const char* file)
00058     { 
00059       std::string filepath = ConfigHandler::GetInstance()->FindConfigFile(file);
00060       if(filepath=="")
00061         return 1;
00062       return l->ReadFromFile(filepath.c_str()); 
00063     }
00064   };
00065   
00069   template<class T> class SetValue{
00070     T& param;
00071     const T value;
00072   public:
00073     SetValue(T& par, const T& val) : param(par), value(val) {}
00074     int operator()(const char*)
00075     {
00076       param = value;
00077       return 0;
00078     }
00079   };
00080   
00084   template<class T> class Increment{
00085     T& param;
00086   public:
00087     Increment(T& t) : param(t) {}
00088     int operator()(const char*){ ++param; return 0;}
00089   };
00090 
00094   template<class T> class Decrement{
00095     T& param;
00096   public:
00097     Decrement(T& t) : param(t) {}
00098     int operator()(const char*){ --param; return 0;}
00099   };
00100   
00104   template<class T> class AddVal{
00105     T& param;
00106   public:
00107     AddVal(T& t) : param(t) {}
00108     int operator()(const char* val){ 
00109       std::istringstream s(val);
00110       T valT;
00111       if( !(val >> valT) )
00112         return -1;
00113       param = param + valT;
00114       return 0;
00115     }
00116   };
00117   
00121   class Toggle{
00122     bool& param;
00123   public:
00124     Toggle(bool& b) : param(b) {}
00125     int operator()(const char*){ param = !param; return 0; }
00126   };
00128 }
00129 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on 20 Jun 2014 for daqman by  doxygen 1.6.1