8 #define SCARAB_API_EXPORTS 19 using std::stringstream;
23 LOGGER( slog,
"param_yaml" );
37 YAML::Node root_node = YAML::LoadFile( a_filename );
40 catch( YAML::Exception& e )
42 LERROR( slog,
"YAML error: " << e.what() );
43 return std::unique_ptr< param >();
51 YAML::Node root_node = YAML::Load( a_string );
54 catch( YAML::Exception& e )
56 LERROR( slog,
"YAML error: " << e.what() );
57 return std::unique_ptr< param >();
69 if( a_node.IsScalar() )
73 if( a_node.IsSequence() )
82 catch( YAML::Exception& e )
84 LERROR(slog,
"YAML error in read_node_type: " << e.what());
85 throw error() <<
"YAML error: " << e.
what();
87 LDEBUG( slog,
"YAML unknown" );
88 throw error() <<
"Unknown YAML encountered";
89 return std::unique_ptr< param >();
96 std::unique_ptr< param_array > t_array_as_param(
new param_array() );
98 for( YAML::const_iterator counter = a_node.begin(); counter != a_node.end(); ++counter )
103 return t_array_as_param;
105 catch( YAML::Exception& e )
107 LERROR( slog,
"YAML error in sequence_handler: " << e.what() );
108 return std::unique_ptr< param_array >();
116 std::unique_ptr< param_node > t_map_as_param(
new param_node() );
118 for( YAML::const_iterator counter = a_node.begin(); counter != a_node.end(); ++counter )
123 return t_map_as_param;
125 catch( YAML::Exception& e )
127 LERROR( slog,
"YAML error in map_handler: " << e.what() );
128 return std::unique_ptr< param_node >();
139 return std::unique_ptr< param_value >(
new param_value( a_node.as<
unsigned >() ) );
141 catch(
const YAML::BadConversion& )
145 return std::unique_ptr< param_value >(
new param_value( a_node.as<
int >() ) );
147 catch(
const YAML::BadConversion& )
151 return std::unique_ptr< param_value >(
new param_value( a_node.as<
double >() ) );
153 catch(
const YAML::BadConversion& )
157 return std::unique_ptr< param_value >(
new param_value( a_node.as<
bool >() ) );
159 catch(
const YAML::BadConversion& )
161 return std::unique_ptr< param_value >(
new param_value( a_node.Scalar() ) );
167 catch ( YAML::Exception& e )
169 LERROR( slog,
"YAML error in scalar_handler: " << e.what() )
170 return std::unique_ptr< param_value >();
172 return std::unique_ptr< param_value >();
186 if( a_filename.empty() )
188 LERROR( slog,
"Filename cannot be an empty string" );
194 std::ofstream fout( a_filename.c_str() );
195 if (! fout.is_open() )
197 LERROR( slog,
"Unable to open file: " << a_filename );
212 std::stringstream t_out;
214 a_string = t_out.str();
225 else if( a_to_write.
is_node() )
237 LWARN( slog,
"Unknown param type encountered" );
259 for (
int count = 0; count != (int) array.
size(); ++count )
274 return t_node = value.
as_bool();
279 return t_node = value.
as_uint();
289 return t_node = value.
as_int();
297 LWARN( slog,
"Unkown value type encountered" );
virtual bool is_value() const
LOGGER(mtlog, "authentication")
virtual bool write_string(const param &a_to_write, std::string &a_string, const param_node &a_options=param_node())
virtual bool write_file(const param &a_to_write, const std::string &a_filename, const param_node &a_options=param_node())
Contains the logger class and macros, based on Kasper's KLogger class.
virtual bool is_null() const
REGISTER_PARAM_INPUT_CODEC(param_input_json, "json")
virtual bool is_array() const
YAML::Node param_value_handler(const param &a_to_write)
virtual ~param_output_yaml()
virtual bool is_node() const
std::unique_ptr< param > param_ptr_t
YAML::Node param_array_handler(const param &a_to_write)
REGISTER_PARAM_OUTPUT_CODEC(param_output_json, "json")
void push_back(const param &a_value)
YAML::Node check_param_type(const param &a_to_write)
std::string as_string() const
YAML::Node param_node_handler(const param &a_to_write)
virtual const char * what() const noexcept