8 #ifndef SCARAB_PARAM_NODE_HH_ 9 #define SCARAB_PARAM_NODE_HH_ 13 #include <boost/iterator/iterator_adaptor.hpp> 14 #include <boost/type_traits/is_convertible.hpp> 15 #include <boost/utility/enable_if.hpp> 27 template<
class x_key,
class x_value,
class x_iiterator >
28 class map_deref_iterator :
public boost::iterator_adaptor< map_deref_iterator< x_key, x_value, x_iiterator >, x_iiterator, x_value, boost::bidirectional_traversal_tag >
43 template<
class x_other_value,
class x_other_iiterator >
50 return this->base()->first;
54 friend class boost::iterator_core_access;
58 return *this->base()->second;
88 virtual bool is_null()
const;
89 virtual bool is_node()
const;
91 virtual bool has_subset(
const param& a_subset )
const;
93 unsigned size()
const;
96 bool has(
const std::string& a_name )
const;
97 unsigned count(
const std::string& a_name )
const;
101 std::string get_value(
const std::string& a_name,
const std::string& a_default )
const;
102 std::string get_value(
const std::string& a_name,
const char* a_default )
const;
105 template<
typename XValType >
106 XValType get_value(
const std::string& a_name, XValType a_default )
const;
110 const param& operator[](
const std::string& a_name )
const;
113 param& operator[](
const std::string& a_name );
117 bool add(
const std::string& a_name,
const param& a_value );
120 bool add(
const std::string& a_name,
param&& a_value );
123 bool add(
const std::string& a_name,
param_ptr_t a_value_ptr );
126 template< typename T, typename std::enable_if< std::is_convertible< T, param_value >::value, T >
::type* =
nullptr >
127 bool add(
const std::string& a_name, T a_value );
130 void replace(
const std::string& a_name,
const param& a_value );
132 void replace(
const std::string& a_name,
param&& a_value );
134 void replace(
const std::string& a_name,
param_ptr_t a_value_ptr );
136 template< typename T, typename std::enable_if< std::is_convertible< T, param_value >::value, T >::type* =
nullptr >
137 void replace(
const std::string& a_name, T a_value );
144 void erase(
const std::string& a_name );
149 const_iterator begin()
const;
152 const_iterator end()
const;
162 template<
typename XValType >
165 return has( a_name ) ? operator[]( a_name ).as_value().as< XValType >() : a_default;
171 return std::unique_ptr< param_node >(
new param_node( *
this ) );
176 return std::unique_ptr< param_node >(
new param_node( std::move(*
this) ) );
191 return f_contents.size();
195 return f_contents.empty();
200 return f_contents.count( a_name ) > 0;
205 return f_contents.count( a_name );
210 return has( a_name ) ? operator[]( a_name ).to_string() : a_default;
215 return get_value( a_name, std::string( a_default ) );
220 return *f_contents.at( a_name );
225 return *f_contents.at( a_name );
230 contents::iterator it = f_contents.find( a_name );
231 if( it == f_contents.end() )
241 contents::iterator it = f_contents.find( a_name );
242 if( it == f_contents.end() )
244 f_contents.insert(
contents_type( a_name, a_value.move_clone() ) );
252 contents::iterator it = f_contents.find( a_name );
253 if( it == f_contents.end() )
255 f_contents.insert(
contents_type( a_name, std::move(a_value_ptr) ) );
261 template< typename T, typename std::enable_if< std::is_convertible< T, param_value >::value, T >
::type* >
265 contents::iterator it = f_contents.find( a_name );
266 if( it == f_contents.end() )
276 f_contents[ a_name ] = a_value.
clone();
282 f_contents[ a_name ] = a_value.move_clone();
288 f_contents[ a_name ] = std::move(a_value_ptr);
292 template< typename T, typename std::enable_if< std::is_convertible< T, param_value >::value, T >
::type* >
302 contents::iterator it = f_contents.find( a_name );
303 if( it != f_contents.end() )
305 f_contents.erase( it );
312 contents::iterator it = f_contents.find( a_name );
313 if( it != f_contents.end() )
316 f_contents.erase( it );
330 return iterator( f_contents.begin() );
340 return iterator( f_contents.end() );
void replace(const std::string &a_name, const param &a_value)
Creates a copy of a_value; overwrites if the key exits.
unsigned count(const std::string &a_name) const
void erase(const std::string &a_name)
virtual bool is_null() const
virtual param_ptr_t move_clone()
std::string type(const x_type &a_param)
std::map< std::string, std::unique_ptr< param > > param_node_contents
contents::value_type contents_type
map_deref_iterator(const map_deref_iterator< x_key, x_other_value, x_other_iiterator > &other, typename boost::enable_if< boost::is_convertible< x_other_value, x_value >, enabler >::type=enabler())
param_node_iterator iterator
virtual bool is_node() const
bool has(const std::string &a_name) const
const x_key & name() const
virtual param_ptr_t clone() const
const param & operator[](const std::string &a_name) const
param_node_const_iterator const_iterator
SCARAB_API std::ostream & operator<<(std::ostream &out, const param_array &a_value)
map_deref_iterator(const x_iiterator &other)
std::unique_ptr< param > param_ptr_t
std::string get_value(const std::string &a_name, const std::string &a_default) const
std::string to_string(std::uint64_t x)
param_ptr_t remove(const std::string &a_name)
map_deref_iterator< std::string, param, param_node_contents::iterator > param_node_iterator
bool add(const std::string &a_name, const param &a_value)
param_node_contents contents
x_value & dereference() const
virtual param_ptr_t clone() const
map_deref_iterator< std::string, const param, param_node_contents::const_iterator > param_node_const_iterator