parameters_bag.h
Go to the documentation of this file.
00001 
00057 /*
00058  * parameters_bag.h
00059  *
00060  *  Created on: Nov 11, 2011
00061  *      Author: goa-jh
00062  */
00063 
00064 #ifndef PARAMETERS_BAG_H_
00065 #define PARAMETERS_BAG_H_
00066 
00067 class ParameterBag
00068 {
00069 
00070   std::map<std::string, int> params_int_;
00071   std::map<std::string, double> params_double_;
00072   std::map<std::string, std::string> params_string_;
00073 
00074 public:
00075 
00076   template <typename T>
00077   struct ParameterBagShortcut {
00078     std::string name;
00079     ParameterBag *p;
00080 
00081     ParameterBagShortcut setMax(T v) {
00082       if(p->params_int_.find(name)!=p->params_int_.end())
00083         p->params_int_[name+"_max"] = v;
00084       if(p->params_double_.find(name)!=p->params_double_.end())
00085         p->params_double_[name+"_max"] = v;
00086       return *this;
00087     }
00088 
00089     ParameterBagShortcut setMin(T v) {
00090       if(p->params_int_.find(name)!=p->params_int_.end())
00091         p->params_int_[name+"_min"] = v;
00092       if(p->params_double_.find(name)!=p->params_double_.end())
00093         p->params_double_[name+"_min"] = v;
00094       return *this;
00095     }
00096 
00097     ParameterBagShortcut setStep(T v) {
00098       if(p->params_int_.find(name)!=p->params_int_.end())
00099         p->params_int_[name+"_step"] = v;
00100       if(p->params_double_.find(name)!=p->params_double_.end())
00101         p->params_double_[name+"_step"] = v;
00102       return *this;
00103     }
00104 
00105   };
00106 
00107   const std::map<std::string, int> &getInts() const {return params_int_;}
00108   const std::map<std::string, double> &getDoubles() const {return params_double_;}
00109   const std::map<std::string, std::string> &getStrings() const {return params_string_;}
00110 
00111   ParameterBagShortcut<int> createParam(ros::NodeHandle &n, const std::string &name, int v) {
00112     n.param("registration_nodelet/"+name,v,v);
00113     params_int_[name] = v;
00114     n.param("registration_nodelet/"+name+"_max",v,v);
00115     params_int_[name+"_max"] = v;
00116     n.param("registration_nodelet/"+name+"_min",v,v);
00117     params_int_[name+"_min"] = v;
00118     n.param("registration_nodelet/"+name+"_step",v,1);
00119     params_int_[name+"_step"] = v;
00120 
00121     ParameterBagShortcut<int> r;
00122     r.name = name;
00123     r.p = this;
00124     return r;
00125   }
00126 
00127   ParameterBagShortcut<double> createParam(ros::NodeHandle &n, const std::string &name, double v) {
00128     n.param("registration_nodelet/"+name,v,v);
00129     params_double_[name] = v;
00130     n.param("registration_nodelet/"+name+"_max",v,v);
00131     params_double_[name+"_max"] = v;
00132     n.param("registration_nodelet/"+name+"_min",v,v);
00133     params_double_[name+"_min"] = v;
00134     n.param("registration_nodelet/"+name+"_step",v,1.);
00135     params_double_[name+"_step"] = v;
00136 
00137     ParameterBagShortcut<double> r;
00138     r.name = name;
00139     r.p = this;
00140     return r;
00141   }
00142 
00143   void createParam(ros::NodeHandle &n, const std::string &name, std::string v) {
00144     n.param("registration_nodelet/"+name,v,v);
00145     params_string_[name] = v;
00146   }
00147 
00148   void setParam(const std::string &name, int v) {params_int_[name] = v;}
00149   void setParam(const std::string &name, const std::string &v) {params_string_[name] = v;}
00150   void setParam(const std::string &name, double v) {params_double_[name] = v;}
00151 
00152   bool getParam(const std::string &name, int &val) {
00153     if(params_int_.find(name)==params_int_.end()) return false;
00154     val=params_int_[name];
00155     return true;
00156   }
00157   bool getParam(const std::string &name, double &val) {
00158     if(params_double_.find(name)==params_double_.end()) return false;
00159     val=params_double_[name];
00160     return true;
00161   }
00162   bool getParam(const std::string &name, std::string &val) {
00163     if(params_string_.find(name)==params_string_.end()) return false;
00164 
00165     val=params_string_[name];
00166     return true;
00167   }
00168 
00169   bool getMax(const std::string &name, int &val) {return getParam(name+"_max",val);}
00170   bool getMax(const std::string &name, double &val) {return getParam(name+"_max",val);}
00171   bool getMin(const std::string &name, int &val) {return getParam(name+"_min",val);}
00172   bool getMin(const std::string &name, double &val) {return getParam(name+"_min",val);}
00173   bool getStep(const std::string &name, int &val) {return getParam(name+"_step",val);}
00174   bool getStep(const std::string &name, double &val) {return getParam(name+"_step",val);}
00175 };
00176 
00177 class ParameterBucket : public ParameterBag
00178 {
00179   ros::NodeHandle n;
00180 public:
00181   ParameterBucket(ros::NodeHandle &n):n(n) {}
00182   ParameterBucket() {}
00183 
00184   void setNodeHandle(ros::NodeHandle &_n) {n=_n;}
00185 
00186   bool addParameter(const std::string &name) {
00187     if(!n.hasParam("registration_nodelet/"+name)) return false;
00188 
00189     bool ret=false;
00190     int i;
00191     if(n.getParam("registration_nodelet/"+name,i)) {
00192       createParam(n,name,i);
00193     }
00194 
00195     double f;
00196     if(n.getParam("/"+name,f)) {
00197       createParam(n,name,(double)f);
00198     }
00199 
00200     std::string s;
00201     if(n.getParam("registration_nodelet/"+name,s)) {
00202       createParam(n,name,s);
00203     }
00204 
00205     return ret;
00206   }
00207 };
00208 
00209 
00210 #endif /* PARAMETERS_BAG_H_ */


cob_3d_registration
Author(s): Joshua Hampp
autogenerated on Wed Aug 26 2015 11:02:36