FactoryParams.hh
Go to the documentation of this file.
1 #if !defined(h_3e645482_ae6a_43e5_8f81_abbc4200212d)
2 #define h_3e645482_ae6a_43e5_8f81_abbc4200212d
3 
4 #include "Base/GCException.h"
5 #include <map>
6 #include <string>
7 #include <sstream>
8 #include <stdexcept>
9 #include "Portability.hh"
10 
12 class FactoryParams;
13 namespace details
14 {
16  {
17  public:
18  base_validator_data(const char* tag, const FactoryParams* params) : tag_(tag), params_(params){}
19 
20  protected:
21  const char* tag_;
23 
24  template<typename T>
25  void assign(const std::string& param_value, T& value) const
26  {
27  assign_impl(param_value, value);
28  }
29 
30  template<typename T>
31  void assign_impl(const std::string& param_value, T& value) const
32  {
33  std::stringstream s;
34  s << param_value;
35  s >> value;
36  }
37 
38  void assign_impl(const std::string& param_value, std::string& value) const
39  {
40  value = param_value;
41  }
42 
43  void throw_error(const char* param_name) const
44  {
45  std::stringstream s;
46  s << "Property '" << param_name << "' required to configure " << tag_;
47  //throw std::runtime_error(s.str());
48  throw RUNTIME_EXCEPTION("%s", s.str().c_str());
49  }
50  };
51 
54  {
55  public:
56  required_params_validator(const char* tag, const FactoryParams* params) : base_validator_data(tag, params) {}
57 
58  template<typename T>
59  optional_params_validator optional(const char* param, T& value) const;
60 
61  template<typename T>
62  const required_params_validator& operator()(const char* param, T& value) const;
63  };
64 
66  {
67  public:
68  optional_params_validator(const char* tag, const FactoryParams* params) : base_validator_data(tag, params) {}
69 
70  template<typename T>
71  required_params_validator required(const char* param, T& value) const { required_params_validator v(tag_, params_); v(param, value); return v; }
72 
73  template<typename T>
74  const optional_params_validator& operator()(const char* param, T& value) const;
75  };
76 
77  template<typename T>
78  optional_params_validator required_params_validator::optional(const char* param, T& value) const { optional_params_validator v(tag_, params_); v(param, value); return v; }
79 
81  {
82  public:
83  parameter_validator(const char* tag, const FactoryParams* params) : base_validator_data(tag, params) {}
84 
85  template<typename T>
86  required_params_validator required(const char* param, T& value) const { required_params_validator v(tag_, params_); v(param, value); return v; }
87 
88  template<typename T>
89  optional_params_validator optional(const char* param, T& value) const { optional_params_validator v(tag_, params_); v(param, value); return v; }
90  };
91 }
92 
94 {
95  typedef std::map<std::string, std::string> storage_t;
96 
97  storage_t storage_;
98 
99 public:
100  typedef storage_t::const_iterator const_iterator;
101 
102  const std::string& operator[](const std::string& v) const;
103  std::string& operator[](const std::string& v) { return storage_[v]; }
104  details::parameter_validator get_for(const char* tag) const { return details::parameter_validator(tag, this); }
105  const_iterator find(const std::string& t) const;
106  const_iterator begin() const { return storage_.begin(); }
107  const_iterator end() const { return storage_.end(); }
108 
109 private:
110  /*typedef std::map<std::string, std::string> storage_t;
111 
112  storage_t storage_; */
113 };
114 
115 namespace details
116 {
117  template<typename T>
118  const required_params_validator& required_params_validator::operator()(const char* param, T& value) const
119  {
121  if (i != params_->end())
122  assign(i->second, value);
123  else
124  throw_error(param);
125 
126  return *this;
127  }
128 
129  template<typename T>
130  const optional_params_validator& optional_params_validator::operator()(const char* param, T& value) const
131  {
133  if (i != params_->end())
134  assign(i->second, value);
135 
136  return *this;
137  }
138 }
140 
141 #endif // h_3e645482_ae6a_43e5_8f81_abbc4200212d
optional_params_validator optional(const char *param, T &value) const
std::string & operator[](const std::string &v)
#define LOG4CPP_NS_END
Definition: Portability.hh:50
required_params_validator required(const char *param, T &value) const
const_iterator end() const
required_params_validator required(const char *param, T &value) const
void assign(const std::string &param_value, T &value) const
virtual bool operator()() const
Get node value.
Definition: IBoolean.h:75
optional_params_validator optional(const char *param, T &value) const
const FactoryParams * params_
void assign_impl(const std::string &param_value, T &value) const
#define RUNTIME_EXCEPTION
Fires a runtime exception, e.g. throw RUNTIME_EXCEPTION("buh!")
Definition: GCException.h:247
std::map< std::string, std::string > storage_t
void assign_impl(const std::string &param_value, std::string &value) const
required_params_validator(const char *tag, const FactoryParams *params)
#define LOG4CPP_EXPORT
Definition: Export.hh:21
storage_t::const_iterator const_iterator
const_iterator find(const std::string &t) const
base_validator_data(const char *tag, const FactoryParams *params)
optional_params_validator(const char *tag, const FactoryParams *params)
void throw_error(const char *param_name) const
const required_params_validator & operator()(const char *param, T &value) const
const optional_params_validator & operator()(const char *param, T &value) const
storage_t storage_
const_iterator begin() const
details::parameter_validator get_for(const char *tag) const
parameter_validator(const char *tag, const FactoryParams *params)
#define LOG4CPP_NS_BEGIN
Definition: Portability.hh:49


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Wed Mar 17 2021 02:48:40