8 #ifndef SCARAB_PARAM_HH_ 9 #define SCARAB_PARAM_HH_ 37 virtual param* clone()
const;
39 virtual bool is_null()
const;
40 virtual bool is_value()
const;
41 virtual bool is_array()
const;
42 virtual bool is_node()
const;
44 virtual bool has_subset(
const param& a_subset )
const;
61 const param& operator[](
unsigned a_index )
const;
64 param& operator[](
unsigned a_index );
68 const param& operator[](
const std::string& a_name )
const;
71 param& operator[](
const std::string& a_name );
73 virtual std::string to_string()
const;
101 virtual param* clone()
const;
105 virtual bool is_null()
const;
106 virtual bool is_value()
const;
108 virtual bool has_subset(
const param& a_subset )
const;
110 std::string
type()
const;
111 bool is_bool()
const;
112 bool is_uint()
const;
114 bool is_double()
const;
115 bool is_string()
const;
117 bool as_bool()
const;
118 uint64_t as_uint()
const;
119 int64_t as_int()
const;
120 double as_double()
const;
121 const std::string& as_string()
const;
122 path as_path()
const;
124 template<
typename XValType >
125 XValType
get()
const;
127 void set(
bool a_value );
128 void set( uint8_t a_value );
129 void set( uint16_t a_value );
130 void set( uint32_t a_value );
131 void set( uint64_t a_value );
132 void set( int8_t a_value );
133 void set( int16_t a_value );
134 void set( int32_t a_value );
135 void set( int64_t a_value );
136 void set(
float a_value );
137 void set(
double a_value );
138 void set(
const std::string& a_value );
139 void set(
const char* a_value );
146 virtual std::string to_string()
const;
191 virtual param* clone()
const;
193 virtual bool is_null()
const;
194 virtual bool is_array()
const;
196 virtual bool has_subset(
const param& a_subset )
const;
198 unsigned size()
const;
203 void resize(
unsigned a_size );
207 std::string get_value(
unsigned a_index )
const;
210 template<
typename XValType >
211 XValType get_value(
unsigned a_index )
const;
215 std::string get_value(
unsigned a_index,
const std::string& a_default )
const;
216 std::string get_value(
unsigned a_index,
const char* a_default )
const;
219 template<
typename XValType >
220 XValType get_value(
unsigned a_index, XValType a_default )
const;
224 const param* at(
unsigned a_index )
const;
227 param* at(
unsigned a_index );
231 const param_value* value_at(
unsigned a_index )
const;
238 const param_array* array_at(
unsigned a_index )
const;
245 const param_node* node_at(
unsigned a_index )
const;
252 const param& operator[](
unsigned a_index )
const;
255 param& operator[](
unsigned a_index );
257 const param* front()
const;
260 const param* back()
const;
264 void assign(
unsigned a_index,
const param& a_value );
266 void assign(
unsigned a_index,
param* a_value_ptr );
268 void push_back(
const param& a_value );
269 void push_back(
param* a_value_ptr );
271 void push_front(
const param& a_value );
272 void push_front(
param* a_value_ptr );
276 void erase(
unsigned a_index );
277 param*
remove(
unsigned a_index );
281 const_iterator begin()
const;
284 const_iterator end()
const;
286 reverse_iterator rbegin();
287 const_reverse_iterator rbegin()
const;
289 reverse_iterator rend();
290 const_reverse_iterator rend()
const;
292 virtual std::string to_string()
const;
314 virtual param* clone()
const;
316 virtual bool is_null()
const;
317 virtual bool is_node()
const;
319 virtual bool has_subset(
const param& a_subset )
const;
321 unsigned size()
const;
324 bool has(
const std::string& a_name )
const;
325 unsigned count(
const std::string& a_name )
const;
329 std::string get_value(
const std::string& a_name )
const;
332 template<
typename XValType >
333 XValType get_value(
const std::string& a_name )
const;
337 std::string get_value(
const std::string& a_name,
const std::string& a_default )
const;
338 std::string get_value(
const std::string& a_name,
const char* a_default )
const;
341 template<
typename XValType >
342 XValType get_value(
const std::string& a_name, XValType a_default )
const;
346 const param* at(
const std::string& a_name )
const;
349 param* at(
const std::string& a_name );
351 const param_value* value_at(
const std::string& a_name )
const;
352 param_value* value_at(
const std::string& a_name );
354 const param_array* array_at(
const std::string& a_name )
const;
355 param_array* array_at(
const std::string& a_name );
357 const param_node* node_at(
const std::string& a_name )
const;
358 param_node* node_at(
const std::string& a_name );
362 const param& operator[](
const std::string& a_name )
const;
365 param& operator[](
const std::string& a_name );
368 bool add(
const std::string& a_name,
const param& a_value );
370 bool add(
const std::string& a_name,
param* a_value_ptr );
373 void replace(
const std::string& a_name,
const param& a_value );
375 void replace(
const std::string& a_name,
param* a_value_ptr );
382 void erase(
const std::string& a_name );
383 param*
remove(
const std::string& a_name );
387 const_iterator begin()
const;
390 const_iterator end()
const;
392 virtual std::string to_string()
const;
402 return new param( *
this );
473 return as_array()[ a_index ];
478 return as_array()[ a_index ];
483 return as_node()[ a_name ];
488 return as_node()[ a_name ];
493 return std::string();
503 inline bool param_value::get< bool >()
const 509 inline uint64_t param_value::get< uint64_t >()
const 515 inline int64_t param_value::get< int64_t >()
const 521 inline double param_value::get< double >()
const 538 template<
typename XValType >
541 if( f_value_type == k_bool )
return static_cast< XValType
>( as_bool() );
542 else if( f_value_type == k_uint )
return static_cast< XValType
>( as_uint() );
543 else if( f_value_type == k_int )
return static_cast< XValType
>( as_int() );
544 else if( f_value_type == k_double )
return static_cast< XValType
>( as_double() );
545 else if( f_value_type == k_string )
547 std::stringstream t_conv;
548 t_conv << *f_value.f_string;
575 return f_value_type == k_bool;
580 return f_value_type == k_uint;
585 return f_value_type == k_int;
590 return f_value_type == k_double;
595 return f_value_type == k_string;
600 if( f_value_type == k_string )
delete f_value.f_string;
601 f_value_type = k_bool;
602 f_value.f_bool = a_value;
608 if( f_value_type == k_string )
delete f_value.f_string;
609 f_value_type = k_uint;
610 f_value.f_uint = a_value;
616 if( f_value_type == k_string )
delete f_value.f_string;
617 f_value_type = k_uint;
618 f_value.f_uint = a_value;
624 if( f_value_type == k_string )
delete f_value.f_string;
625 f_value_type = k_uint;
626 f_value.f_uint = a_value;
632 if( f_value_type == k_string )
delete f_value.f_string;
633 f_value_type = k_uint;
634 f_value.f_uint = a_value;
640 if( f_value_type == k_string )
delete f_value.f_string;
641 f_value_type = k_int;
642 f_value.f_int = a_value;
648 if( f_value_type == k_string )
delete f_value.f_string;
649 f_value_type = k_int;
650 f_value.f_int = a_value;
656 if( f_value_type == k_string )
delete f_value.f_string;
657 f_value_type = k_int;
658 f_value.f_int = a_value;
664 if( f_value_type == k_string )
delete f_value.f_string;
665 f_value_type = k_int;
666 f_value.f_int = a_value;
672 if( f_value_type == k_string )
delete f_value.f_string;
673 f_value_type = k_double;
674 f_value.f_double = a_value;
680 if( f_value_type == k_string )
delete f_value.f_string;
681 f_value_type = k_double;
682 f_value.f_double = a_value;
688 if( f_value_type == k_string )
delete f_value.f_string;
689 f_value_type = k_string;
690 f_value.f_string =
new std::string( a_value );
696 if( f_value_type == k_string )
delete f_value.f_string;
697 f_value_type = k_string;
698 f_value.f_string =
new std::string( a_value );
713 template<
typename XValType >
717 if( value == NULL )
throw error() <<
"No value is present at index <" << a_index <<
">";
718 return value->
get< XValType >();
721 template<
typename XValType >
725 if( value == NULL )
return a_default;
726 return value->
get< XValType >();
746 return f_contents.size();
750 return f_contents.empty();
756 if( value == NULL )
throw scarab::error() <<
"No value at <" << a_index <<
"> is present at this node";
763 if( value == NULL )
return a_default;
769 return get_value( a_index, std::string( a_default ) );
774 if( a_index >= f_contents.size() )
return NULL;
775 return f_contents[ a_index ];
779 if( a_index >= f_contents.size() )
return NULL;
780 return f_contents[ a_index ];
785 if( a_index >= f_contents.size() )
return NULL;
786 return &f_contents[ a_index ]->
as_value();
790 if( a_index >= f_contents.size() )
return NULL;
791 return &f_contents[ a_index ]->
as_value();
796 if( a_index >= f_contents.size() )
return NULL;
797 return &f_contents[ a_index ]->
as_array();
801 if( a_index >= f_contents.size() )
return NULL;
802 return &f_contents[ a_index ]->
as_array();
807 if( a_index >= f_contents.size() )
return NULL;
808 return &f_contents[ a_index ]->
as_node();
812 if( a_index >= f_contents.size() )
return NULL;
813 return &f_contents[ a_index ]->
as_node();
818 return *f_contents[ a_index ];
822 return *f_contents[ a_index ];
827 return f_contents.front();
831 return f_contents.front();
836 return f_contents.back();
840 return f_contents.back();
847 f_contents[ a_index ] = a_value.
clone();
854 f_contents[ a_index ] = a_value_ptr;
860 f_contents.push_back( a_value.
clone() );
865 f_contents.push_back( a_value_ptr );
871 f_contents.push_front( a_value.
clone() );
876 f_contents.push_front( a_value_ptr );
891 delete f_contents[ a_index ];
892 f_contents[ a_index ] = NULL;
897 param* t_current = f_contents[ a_index ];
898 f_contents[ a_index ] = NULL;
903 for(
unsigned ind = 0; ind < f_contents.size(); ++ind )
905 delete f_contents[ ind ];
913 return f_contents.begin();
917 return f_contents.begin();
922 return f_contents.end();
926 return f_contents.end();
931 return f_contents.rbegin();
935 return f_contents.rbegin();
940 return f_contents.rend();
944 return f_contents.rend();
954 template<
typename XValType >
958 if( value == NULL )
throw error() <<
"No value with name <" << a_name <<
"> is present at this node";
959 return value->
get< XValType >();
962 template<
typename XValType >
966 if( value == NULL )
return a_default;
967 return value->
get< XValType >();
988 return f_contents.size();
992 return f_contents.empty();
998 return f_contents.count( a_name ) > 0;
1003 return f_contents.count( a_name );
1009 if( value == NULL )
throw error() <<
"No value with name <" << a_name <<
"> is present at this node:\n" << *
this;
1016 if( value == NULL )
return a_default;
1022 return get_value( a_name, std::string( a_default ) );
1028 if( it == f_contents.end() )
1037 iterator it = f_contents.find( a_name );
1038 if( it == f_contents.end() )
1048 if( it == f_contents.end() )
1057 iterator it = f_contents.find( a_name );
1058 if( it == f_contents.end() )
1068 if( it == f_contents.end() )
1077 iterator it = f_contents.find( a_name );
1078 if( it == f_contents.end() )
1088 if( it == f_contents.end() )
1092 return &it->second->
as_node();
1097 iterator it = f_contents.find( a_name );
1098 if( it == f_contents.end() )
1102 return &it->second->
as_node();
1108 if( it == f_contents.end() )
1110 throw error() <<
"No value present corresponding to name <" << a_name <<
">\n";
1112 return *(it->second);
1117 return *f_contents[ a_name ];
1122 iterator it = f_contents.find( a_name );
1123 if( it == f_contents.end() )
1133 iterator it = f_contents.find( a_name );
1134 if( it == f_contents.end() )
1145 f_contents[ a_name ] = a_value.
clone();
1152 f_contents[ a_name ] = a_value;
1158 iterator it = f_contents.find( a_name );
1159 if( it != f_contents.end() )
1162 f_contents.erase( it );
1169 iterator it = f_contents.find( a_name );
1170 if( it != f_contents.end() )
1172 param* removed = it->second;
1173 f_contents.erase( it );
1181 for(
iterator it = f_contents.begin(); it != f_contents.end(); ++it )
1191 return f_contents.begin();
1196 return f_contents.begin();
1201 return f_contents.end();
1206 return f_contents.end();
virtual bool is_node() const
const param * back() const
void replace(const std::string &a_name, const param &a_value)
creates a copy of a_value
const param_node * node_at(unsigned a_index) const
unsigned count(const std::string &a_name) const
void erase(const std::string &a_name)
virtual std::string to_string() const
const param_node * node_at(const std::string &a_name) const
void push_front(const param &a_value)
virtual bool is_value() const
std::deque< param * > contents
std::map< std::string, param * > contents
virtual bool is_null() const
virtual std::string to_string() const
SCARAB_API std::ostream & operator<<(std::ostream &out, const param &a_value)
virtual param * clone() const
virtual bool is_array() const
std::string type(const x_type &a_param)
static unsigned s_indent_level
virtual param * clone() const
contents::value_type contents_type
std::string get_value(unsigned a_index) const
const param_value * value_at(const std::string &a_name) const
virtual bool is_null() const
const param_value & operator()() const
Assumes that the parameter is a value, and returns a reference to itself.
virtual bool is_value() const
virtual bool is_node() const
std::string param_value::get< std::string >() const
const param_array * array_at(unsigned a_index) const
contents::const_reverse_iterator const_reverse_iterator
std::string get_value(const std::string &a_name) const
bool has(const std::string &a_name) const
contents::const_iterator const_iterator
const param & operator[](unsigned a_index) const
void append(const param_array &an_array)
const param_value * value_at(unsigned a_index) const
const param & operator[](const std::string &a_name) const
param * remove(unsigned a_index)
const param * at(unsigned a_index) const
virtual bool is_null() const
const param * front() const
param * remove(const std::string &a_name)
reverse_iterator rbegin()
const param & operator[](unsigned a_index) const
const param * at(const std::string &a_name) const
scarab::path param_value::get< scarab::path >() const
virtual bool is_null() const
const param_array * array_at(const std::string &a_name) const
void erase(unsigned a_index)
void assign(unsigned a_index, const param &a_value)
contents::reverse_iterator reverse_iterator
contents::iterator iterator
virtual param * clone() const
contents::const_iterator const_iterator
void push_back(const param &a_value)
bool add(const std::string &a_name, const param &a_value)
creates a copy of a_value
contents::value_type contents_type
contents::iterator iterator
virtual bool is_array() const
virtual param * clone() const