Scarab  v2.4.4
Project 8 C++ Utility Library
param_base_impl.hh
Go to the documentation of this file.
1 /*
2  * param_base_impl.hh
3  *
4  * Created on: Jan 14, 2014
5  * Author: nsoblath
6  */
7 
8 #ifndef SCARAB_PARAM_BASE_IMPL_HH_
9 #define SCARAB_PARAM_BASE_IMPL_HH_
10 
11 #include "param_base.hh"
12 
13 #include "param_array.hh"
14 #include "param_node.hh"
15 #include "param_value.hh"
16 
17 namespace scarab
18 {
19 
20  inline param& param::operator=( const param& )
21  {
22  return *this;
23  }
24 
26  {
27  return *this;
28  }
29 
30  inline param_ptr_t param::clone() const
31  {
32  //std::cout << "param::clone()" << std::endl;
33  return param_ptr_t( new param( *this ) );
34  }
35 
37  {
38  //std::cout << "param::clone()" << std::endl;
39  return param_ptr_t( new param( std::move(*this) ) );
40  }
41 
42  inline bool param::is_null() const
43  {
44  return true;
45  }
46 
47  inline bool param::is_value() const
48  {
49  return false;
50  }
51 
52  inline bool param::is_array() const
53  {
54  return false;
55  }
56 
57  inline bool param::is_node() const
58  {
59  return false;
60  }
61 
62  inline bool param::has_subset( const param& /*a_subset*/ ) const
63  {
64  // this version of has_subset should only ever be called if a_subset is a null param (i.e. not one of the derived classes)
65  return true;
66  }
67 
69  {
70  if( this->is_value() ) return *static_cast< param_value* >( this );
71  throw error() << "Param object is not a value";
72  }
73 
75  {
76  if( this->is_array() ) return *static_cast< param_array* >( this );
77  throw error() << "Param object is not an array";
78  }
79 
81  {
82  if( this->is_node() ) return *static_cast< param_node* >( this );
83  throw error() << "Param object is not a node";
84  }
85 
86  inline const param_value& param::as_value() const
87  {
88  if( this->is_value() ) return *static_cast< const param_value* >( this );
89  throw error() << "Param object is not a value";
90  }
91 
92  inline const param_array& param::as_array() const
93  {
94  if( this->is_array() ) return *static_cast< const param_array* >( this );
95  throw error() << "Param object is not an array";
96  }
97 
98  inline const param_node& param::as_node() const
99  {
100  if( this->is_node() ) return *static_cast< const param_node* >( this );
101  throw error() << "Param object is not a node";
102  }
103 
104  inline const param_value& param::operator()() const
105  {
106  return as_value();
107  }
108 
110  {
111  return as_value();
112  }
113 
114  inline const param& param::operator[]( unsigned a_index ) const
115  {
116  return as_array()[ a_index ];
117  }
118 
119  inline param& param::operator[]( unsigned a_index )
120  {
121  return as_array()[ a_index ];
122  }
123 
124  inline const param& param::operator[]( const std::string& a_name ) const
125  {
126  return as_node()[ a_name ];
127  }
128 
129  inline param& param::operator[]( const std::string& a_name )
130  {
131  return as_node()[ a_name ];
132  }
133 
134  inline std::string param::get_value( const std::string& a_name, const std::string& a_default ) const
135  {
136  return as_node().get_value( a_name, a_default );
137  }
138 
139  inline std::string param::get_value( const std::string& a_name, const char* a_default ) const
140  {
141  return as_node().get_value( a_name, a_default );
142  }
143 
144  template< typename XValType >
145  inline XValType param::get_value( const std::string& a_name, XValType a_default ) const
146  {
147  return as_node().get_value( a_name, a_default );
148  }
149 
150  inline std::string param::get_value( unsigned a_index, const std::string& a_default ) const
151  {
152  return as_array().get_value( a_index, a_default );
153  }
154 
155  inline std::string param::get_value( unsigned a_index, const char* a_default ) const
156  {
157  return as_array().get_value( a_index, a_default );
158  }
159 
160  template< typename XValType >
161  inline XValType param::get_value( unsigned a_index, XValType a_default ) const
162  {
163  return as_array().get_value( a_index, a_default );
164  }
165 
166  inline std::string param::to_string() const
167  {
168  return std::string();
169  }
170 
171 } /* namespace scarab */
172 
173 #endif /* SCARAB_PARAM_BASE_IMPL_HH_ */
param & operator=(const param &rhs)
virtual bool has_subset(const param &a_subset) const
virtual bool is_value() const
virtual param_ptr_t clone() const
const param & operator[](unsigned a_index) const
const param_value & operator()() const
Assumes that the parameter is a value, and returns a reference to itself.
std::string get_value(const std::string &a_name, const std::string &a_default) const
Definition: param_node.hh:208
virtual bool is_null() const
param_value & as_value()
virtual bool is_array() const
std::string get_value(unsigned a_index, const std::string &a_default) const
Definition: param_array.hh:171
virtual bool is_node() const
std::unique_ptr< param > param_ptr_t
Definition: param_base.hh:23
param_node & as_node()
virtual param_ptr_t move_clone()
param_array & as_array()
virtual std::string to_string() const
std::string get_value(const std::string &a_name, const std::string &a_default) const