FactoryParams.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2002, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
3  * Copyright 2002, Bastiaan Bakker. All rights reserved.
4  *
5  * See the COPYING file for the terms of usage and distribution.
6  */
7 
8 #if !defined(h_3e645482_ae6a_43e5_8f81_abbc4200212d)
9 #define h_3e645482_ae6a_43e5_8f81_abbc4200212d
10 
11 #include <map>
12 #include <string>
13 #include <sstream>
14 #include <stdexcept>
15 #include "Portability.hh"
16 
17 namespace log4cpp
18 {
19  class FactoryParams;
20  namespace details
21  {
23  {
24  public:
25  base_validator_data(const char* tag, const FactoryParams* params) : tag_(tag), params_(params){}
26 
27  protected:
28  const char* tag_;
30 
31  template<typename T>
32  void assign(const std::string& param_value, T& value) const
33  {
34  assign_impl(param_value, value);
35  }
36 
37  template<typename T>
38  void assign_impl(const std::string& param_value, T& value) const
39  {
40  std::stringstream s;
41  s << param_value;
42  s >> value;
43  }
44 
45  void assign_impl(const std::string& param_value, std::string& value) const
46  {
47  value = param_value;
48  }
49 
50  void throw_error(const char* param_name) const
51  {
52  std::stringstream s;
53  s << "Property '" << param_name << "' required to configure " << tag_;
54  throw std::runtime_error(s.str());
55  }
56  };
57 
58  class parameter_validator;
59  }
60 
62  {
63  typedef std::map<std::string, std::string> storage_t;
64 
65  storage_t storage_;
66 
67  public:
68  typedef storage_t::const_iterator const_iterator;
69 
70  const std::string& operator[](const std::string& v) const;
71  std::string& operator[](const std::string& v) { return storage_[v]; }
72  details::parameter_validator get_for(const char* tag) const;
73  const_iterator find(const std::string& t) const;
74  const_iterator begin() const { return storage_.begin(); }
75  const_iterator end() const { return storage_.end(); }
76  };
77 
78  namespace details
79  {
80  class optional_params_validator;
82  {
83  public:
84  required_params_validator(const char* tag, const FactoryParams* params) : base_validator_data(tag, params) {}
85 
86 #if defined(_MSC_VER) && _MSC_VER < 1300
87  template<typename T>
88  optional_params_validator optional(const char* param, T& value) const { optional_params_validator v(tag_, params_); v(param, value); return v; }
89 #else
90  template<typename T>
91  optional_params_validator optional(const char* param, T& value) const;
92 #endif
93 
94  template<typename T>
95  const required_params_validator& operator()(const char* param, T& value) const
96  {
98  if (i != params_->end())
99  assign(i->second, value);
100  else
101  throw_error(param);
102 
103  return *this;
104  }
105 
106  };
107 
109  {
110  public:
111  optional_params_validator(const char* tag, const FactoryParams* params) : base_validator_data(tag, params) {}
112 
113  template<typename T>
114  required_params_validator required(const char* param, T& value) const { required_params_validator v(tag_, params_); v(param, value); return v; }
115 
116  template<typename T>
117  const optional_params_validator& operator()(const char* param, T& value) const
118  {
120  if (i != params_->end())
121  assign(i->second, value);
122 
123  return *this;
124 
125  }
126  };
127 
129  {
130  public:
131  parameter_validator(const char* tag, const FactoryParams* params) : base_validator_data(tag, params) {}
132 
133  template<typename T>
134  required_params_validator required(const char* param, T& value) const { required_params_validator v(tag_, params_); v(param, value); return v; }
135 
136  template<typename T>
137  optional_params_validator optional(const char* param, T& value) const { optional_params_validator v(tag_, params_); v(param, value); return v; }
138  };
139 
140 #if !(defined(_MSC_VER) && _MSC_VER < 1300)
141  template<typename T>
143  required_params_validator::optional(const char* param, T& value) const
144  {
146  v(param, value);
147  return v;
148  }
149 #endif
150  }
151 
153  {
154  return details::parameter_validator(tag, this);
155  }
156 }
157 
158 #endif // h_3e645482_ae6a_43e5_8f81_abbc4200212d
optional_params_validator optional(const char *param, T &value) const
std::map< std::string, std::string > storage_t
std::string & operator[](const std::string &v)
optional_params_validator(const char *tag, const FactoryParams *params)
required_params_validator required(const char *param, T &value) const
required_params_validator required(const char *param, T &value) const
storage_t::const_iterator const_iterator
const required_params_validator & operator()(const char *param, T &value) const
const optional_params_validator & operator()(const char *param, T &value) const
void assign_impl(const std::string &param_value, std::string &value) const
#define LOG4CPP_EXPORT
Definition: Export.hh:26
const_iterator begin() const
const_iterator end() const
base_validator_data(const char *tag, const FactoryParams *params)
parameter_validator(const char *tag, const FactoryParams *params)
void assign(const std::string &param_value, T &value) const
void throw_error(const char *param_name) const
details::parameter_validator get_for(const char *tag) const
const_iterator find(const std::string &t) const
optional_params_validator optional(const char *param, T &value) const
required_params_validator(const char *tag, const FactoryParams *params)
void assign_impl(const std::string &param_value, T &value) const


log4cpp
Author(s): Stephen Roderick, Bastiaan Bakker, Cedric Le Goater, Steve Ostlind, Marcel Harkema, Walter Stroebel, Glenn Scott and Tony Cheung
autogenerated on Sun Jun 23 2019 19:14:17