8 #define SCARAB_API_EXPORTS 14 LOGGER( plog,
"param_helpers" );
24 throw error() <<
"No address for keyword argument with value <" << *a_value <<
">";
28 std::string t_top_addr = an_addr.substr( 0, t_div_pos );
32 if( t_new_param->is_node() )
35 std::string t_next_addr = t_div_pos == an_addr.npos ?
"" : an_addr.substr( t_div_pos+1 );
36 add_next( *t_new_param, t_top_addr, t_next_addr, std::move(a_value) );
40 throw error() <<
"Top param type must be a node; this address is invalid: <" << an_addr <<
">";
52 if( a_next_addr.empty() )
55 t_child = std::move(a_value);
61 std::string t_top_addr = a_next_addr.substr( 0, t_div_pos );
63 std::string t_next_addr = t_div_pos == a_next_addr.npos ?
"" : a_next_addr.substr( t_div_pos+1 );
64 add_next( *t_child, t_top_addr, t_next_addr, std::move(a_value) );
70 unsigned index = std::stoul( an_addr_in_parent );
72 if( index > t_parent_array.
size() ) t_parent_array.
resize( index+1 );
75 a_parent.
as_array().
assign( std::stoul( an_addr_in_parent ), std::move(t_child) );
82 a_parent.
as_node().
replace( an_addr_in_parent, std::move(t_child) );
87 throw error() <<
"Invalid param type: only nodes and arrays accepted";
95 if( an_addr.empty() )
return std::unique_ptr< param_value >( (
new param_value() ) );
99 for(
const char& ch : an_addr )
101 if( ! std::isdigit( ch ) )
return std::unique_ptr< param_node >(
new param_node() );
104 return std::unique_ptr< param_array >(
new param_array() );
110 if( a_value.empty() )
112 LTRACE( plog,
"Parsed value as NULL" );
113 return std::unique_ptr< param >(
new param() );
116 else if( a_value ==
"true" )
118 LTRACE( plog,
"Parsing value (" << a_value <<
") as bool(true)" );
119 return std::unique_ptr< param_value >(
new param_value(
true ) );
121 else if( a_value ==
"false" )
123 LTRACE( plog,
"Parsing value (" << a_value <<
") as bool(false)" );
124 return std::unique_ptr< param_value >(
new param_value(
false ) );
132 std::stringstream t_conv_double( a_value );
133 if( a_value.find(
'.' ) == a_value.rfind(
'.' ) &&
134 a_value.find(
'-' ) == a_value.rfind(
'-' ) &&
135 ! (t_conv_double >> t_double).fail() )
138 if( a_value.find(
'.' ) != std::string::npos ||
139 a_value.find(
'e' ) != std::string::npos ||
140 a_value.find(
'E' ) != std::string::npos )
143 LTRACE( plog,
"Parsing value (" << a_value <<
") as double(" << t_double <<
")" );
144 return std::unique_ptr< param_value >(
new param_value( t_double ) );
146 else if( a_value[ 0 ] ==
'-' )
149 LTRACE( plog,
"Parsing value (" << a_value <<
") as int(" << (int64_t)t_double <<
")" );
150 return std::unique_ptr< param_value >(
new param_value( (int64_t)t_double ) );
155 LTRACE( plog,
"Parsing value (" << a_value <<
") as uint(" << (uint64_t)t_double <<
")" );
156 return std::unique_ptr< param_value >(
new param_value( (uint64_t)t_double ) );
162 LTRACE( plog,
"Parsing value (" << a_value <<
") as a string" );
163 return std::unique_ptr< param_value >(
new param_value( a_value ) );
void replace(const std::string &a_name, const param &a_value)
Creates a copy of a_value; overwrites if the key exits.
LOGGER(plog, "param_helpers")
static void add_next(param &a_parent, const std::string &an_addr_in_parent, const std::string &a_next_addr, param_ptr_t a_value=param_ptr_t())
static param_ptr_t parse_address(const std::string &an_addr, param_ptr_t a_value=param_ptr_t())
Converts an address into a nested param structure, and optionally attaches a value.
static const char f_node_separator
Contains the logger class and macros, based on Kasper's KLogger class.
virtual bool is_array() const
virtual bool is_node() const
std::unique_ptr< param > param_ptr_t
static param_ptr_t parse_value(const std::string &a_value)
Attempts to determine whether a value encoded as a string is an int, and unsigned int...
void assign(unsigned a_index, const param &a_value)
static param_ptr_t new_param_from_addr(const std::string &an_addr)
void resize(unsigned a_size)