Scarab  v2.2.0
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 
63  {
64  if( this->is_value() ) return *static_cast< param_value* >( this );
65  throw error() << "Param object is not a value";
66  }
67 
69  {
70  if( this->is_array() ) return *static_cast< param_array* >( this );
71  throw error() << "Param object is not an array";
72  }
73 
75  {
76  if( this->is_node() ) return *static_cast< param_node* >( this );
77  throw error() << "Param object is not a node";
78  }
79 
80  inline const param_value& param::as_value() const
81  {
82  if( this->is_value() ) return *static_cast< const param_value* >( this );
83  throw error() << "Param object is not a value";
84  }
85 
86  inline const param_array& param::as_array() const
87  {
88  if( this->is_array() ) return *static_cast< const param_array* >( this );
89  throw error() << "Param object is not an array";
90  }
91 
92  inline const param_node& param::as_node() const
93  {
94  if( this->is_node() ) return *static_cast< const param_node* >( this );
95  throw error() << "Param object is not a node";
96  }
97 
98  inline const param_value& param::operator()() const
99  {
100  return as_value();
101  }
102 
104  {
105  return as_value();
106  }
107 
108  inline const param& param::operator[]( unsigned a_index ) const
109  {
110  return as_array()[ a_index ];
111  }
112 
113  inline param& param::operator[]( unsigned a_index )
114  {
115  return as_array()[ a_index ];
116  }
117 
118  inline const param& param::operator[]( const std::string& a_name ) const
119  {
120  return as_node()[ a_name ];
121  }
122 
123  inline param& param::operator[]( const std::string& a_name )
124  {
125  return as_node()[ a_name ];
126  }
127 
128  inline std::string param::get_value( const std::string& a_name, const std::string& a_default ) const
129  {
130  return as_node().get_value( a_name, a_default );
131  }
132 
133  inline std::string param::get_value( const std::string& a_name, const char* a_default ) const
134  {
135  return as_node().get_value( a_name, a_default );
136  }
137 
138  template< typename XValType >
139  inline XValType param::get_value( const std::string& a_name, XValType a_default ) const
140  {
141  return as_node().get_value( a_name, a_default );
142  }
143 
144  inline std::string param::get_value( unsigned a_index, const std::string& a_default ) const
145  {
146  return as_array().get_value( a_index, a_default );
147  }
148 
149  inline std::string param::get_value( unsigned a_index, const char* a_default ) const
150  {
151  return as_array().get_value( a_index, a_default );
152  }
153 
154  template< typename XValType >
155  inline XValType param::get_value( unsigned a_index, XValType a_default ) const
156  {
157  return as_array().get_value( a_index, a_default );
158  }
159 
160  inline std::string param::to_string() const
161  {
162  return std::string();
163  }
164 
165 } /* namespace scarab */
166 
167 #endif /* SCARAB_PARAM_BASE_IMPL_HH_ */
virtual bool is_node() const
param & operator=(const param &rhs)
std::string get_value(unsigned a_index, const std::string &a_default) const
Definition: param_array.hh:172
virtual bool is_value() const
virtual std::string to_string() const
std::string get_value(const std::string &a_name, const std::string &a_default) const
const param_value & operator()() const
Assumes that the parameter is a value, and returns a reference to itself.
param_value & as_value()
const param & operator[](unsigned a_index) const
virtual bool is_null() const
std::unique_ptr< param > param_ptr_t
Definition: param_base.hh:23
param_node & as_node()
virtual param_ptr_t move_clone()
std::string get_value(const std::string &a_name, const std::string &a_default) const
Definition: param_node.hh:206
param_array & as_array()
virtual param_ptr_t clone() const
virtual bool is_array() const