All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
52  class optional_params_validator;
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 
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
details::parameter_validator
Definition: FactoryParams.hh:80
details::base_validator_data::tag_
const char * tag_
Definition: FactoryParams.hh:21
details::base_validator_data::params_
const FactoryParams * params_
Definition: FactoryParams.hh:22
details::parameter_validator::optional
optional_params_validator optional(const char *param, T &value) const
Definition: FactoryParams.hh:89
Portability.hh
FactoryParams::storage_t
std::map< std::string, std::string > storage_t
Definition: FactoryParams.hh:95
details::base_validator_data::throw_error
void throw_error(const char *param_name) const
Definition: FactoryParams.hh:43
details::optional_params_validator::optional_params_validator
optional_params_validator(const char *tag, const FactoryParams *params)
Definition: FactoryParams.hh:68
details::required_params_validator
Definition: FactoryParams.hh:53
FactoryParams::storage_
storage_t storage_
Definition: FactoryParams.hh:97
details::base_validator_data
Definition: FactoryParams.hh:15
details::required_params_validator::optional
optional_params_validator optional(const char *param, T &value) const
Definition: FactoryParams.hh:78
details::base_validator_data::assign_impl
void assign_impl(const std::string &param_value, std::string &value) const
Definition: FactoryParams.hh:38
details::optional_params_validator::operator()
const optional_params_validator & operator()(const char *param, T &value) const
Definition: FactoryParams.hh:130
details
Definition: FactoryParams.hh:13
details::optional_params_validator
Definition: FactoryParams.hh:65
FactoryParams
Definition: FactoryParams.hh:93
details::parameter_validator::required
required_params_validator required(const char *param, T &value) const
Definition: FactoryParams.hh:86
details::required_params_validator::required_params_validator
required_params_validator(const char *tag, const FactoryParams *params)
Definition: FactoryParams.hh:56
LOG4CPP_NS_BEGIN
#define LOG4CPP_NS_BEGIN
Definition: Portability.hh:49
FactoryParams::operator[]
std::string & operator[](const std::string &v)
Definition: FactoryParams.hh:103
LOG4CPP_NS_END
#define LOG4CPP_NS_END
Definition: Portability.hh:50
details::base_validator_data::base_validator_data
base_validator_data(const char *tag, const FactoryParams *params)
Definition: FactoryParams.hh:18
LOG4CPP_EXPORT
#define LOG4CPP_EXPORT
Definition: Export.hh:21
FactoryParams::end
const_iterator end() const
Definition: FactoryParams.hh:107
details::parameter_validator::parameter_validator
parameter_validator(const char *tag, const FactoryParams *params)
Definition: FactoryParams.hh:83
FactoryParams::begin
const_iterator begin() const
Definition: FactoryParams.hh:106
FactoryParams::find
const_iterator find(const std::string &t) const
details::base_validator_data::assign
void assign(const std::string &param_value, T &value) const
Definition: FactoryParams.hh:25
FactoryParams::get_for
details::parameter_validator get_for(const char *tag) const
Definition: FactoryParams.hh:104
details::optional_params_validator::required
required_params_validator required(const char *param, T &value) const
Definition: FactoryParams.hh:71
RUNTIME_EXCEPTION
#define RUNTIME_EXCEPTION
Fires a runtime exception, e.g. throw RUNTIME_EXCEPTION("buh!")
Definition: GCException.h:247
GCException.h
FactoryParams::const_iterator
storage_t::const_iterator const_iterator
Definition: FactoryParams.hh:100
details::required_params_validator::operator()
const required_params_validator & operator()(const char *param, T &value) const
Definition: FactoryParams.hh:118
details::base_validator_data::assign_impl
void assign_impl(const std::string &param_value, T &value) const
Definition: FactoryParams.hh:31


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Wed Dec 4 2024 03:10:11