Scarab  v2.0.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::clone() const
21  {
22  //std::cout << "param::clone()" << std::endl;
23  return new param( *this );
24  }
25 
26  inline bool param::is_null() const
27  {
28  return true;
29  }
30 
31  inline bool param::is_value() const
32  {
33  return false;
34  }
35 
36  inline bool param::is_array() const
37  {
38  return false;
39  }
40 
41  inline bool param::is_node() const
42  {
43  return false;
44  }
45 
47  {
48  if( this->is_value() ) return *static_cast< param_value* >( this);
49  throw error() << "Param object is not a value";
50  }
51 
53  {
54  if( this->is_value() ) return *static_cast< param_array* >( this);
55  throw error() << "Param object is not an array";
56  }
57 
59  {
60  if( this->is_value() ) return *static_cast< param_node* >( this);
61  throw error() << "Param object is not a node";
62  }
63 
64  inline const param_value& param::as_value() const
65  {
66  if( this->is_value() ) return *static_cast< const param_value* >( this);
67  throw error() << "Param object is not a value";
68  }
69 
70  inline const param_array& param::as_array() const
71  {
72  if( this->is_value() ) return *static_cast< const param_array* >( this);
73  throw error() << "Param object is not an array";
74  }
75 
76  inline const param_node& param::as_node() const
77  {
78  if( this->is_value() ) return *static_cast< const param_node* >( this);
79  throw error() << "Param object is not a node";
80  }
81 
82  inline const param_value& param::operator()() const
83  {
84  return as_value();
85  }
86 
88  {
89  return as_value();
90  }
91 
92  inline const param& param::operator[]( unsigned a_index ) const
93  {
94  return as_array()[ a_index ];
95  }
96 
97  inline param& param::operator[]( unsigned a_index )
98  {
99  return as_array()[ a_index ];
100  }
101 
102  inline const param& param::operator[]( const std::string& a_name ) const
103  {
104  return as_node()[ a_name ];
105  }
106 
107  inline param& param::operator[]( const std::string& a_name )
108  {
109  return as_node()[ a_name ];
110  }
111 
112  inline std::string param::to_string() const
113  {
114  return std::string();
115  }
116 
117 } /* namespace scarab */
118 
119 #endif /* SCARAB_PARAM_BASE_IMPL_HH_ */
virtual bool is_node() const
virtual bool is_value() const
virtual std::string to_string() 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
param_node & as_node()
param_array & as_array()
virtual bool is_array() const
virtual param * clone() const