My Project  v0.0.16
Parameters.hpp
Go to the documentation of this file.
1 /*
2  * File: Parameters.hpp
3  * Author: ale
4  *
5  * Created on July 20, 2014, 9:50 AM
6  */
7 
8 #ifndef __mp7_parameters_hpp__
9 #define __mp7_parameters_hpp__
10 
11 // C++ Headers
12 #include <set>
13 
14 // Boost Headers
15 #include <boost/unordered_map.hpp>
16 #include <boost/any.hpp>
17 
18 namespace mp7 {
19 
20 class Parameters : private boost::unordered_map<std::string, boost::any> {
21  typedef boost::unordered_map<std::string, boost::any> parent;
22 public:
23  typedef boost::any Object;
24 
26  }
27 
28  virtual ~Parameters() {
29  }
30 
31  template<typename T>
32  void set(const std::string& aKey, const T& aValue) {
33  this->operator[](aKey) = aValue;
34  }
35 
36  template<typename T>
37  T get(const std::string& aKey) const {
38  const_iterator it = this->find(aKey);
39  //TODO runtime_error -> dedicated error
40  if (it == this->end()) throw std::runtime_error("Parameter not found");
41 
42  return boost::any_cast<T>(it->second);
43  }
44 
45  std::set<std::string> names() const {
46  std::set<std::string> names;
47  for( const_iterator it = begin(); it != end(); ++it)
48  names.insert(it->first);
49 
50  return names;
51  }
52 
53  void set(const std::string& aKey, const char* aValue ) {
54  this->parent::operator[](aKey) = std::string(aValue) ;
55  }
56 
57  Object& operator []( const std::string& aKey ){
58  return this->parent::operator[](aKey);
59  }
60 };
61 
62 
63 }
64 
65 #endif /* __mp7_parameters_hpp__ */
66 
std::set<std::string> names() const
Definition: Parameters.hpp:45
-test-ipbusaccess
Definition: AlignmentNode.hpp:15
Object& operator []( const std::string& aKey )
Definition: Parameters.hpp:57
virtual ~Parameters()
Definition: Parameters.hpp:28
Parameters()
Definition: Parameters.hpp:25
boost::any Object
Definition: Parameters.hpp:23
boost::unordered_map<std::string, boost::any> parent
Definition: Parameters.hpp:21