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 >();
137 return std::unique_ptr< param_value >(
new param_value( a_node.Scalar() ) );
139 catch ( YAML::Exception& e )
141 LERROR( slog,
"YAML error in scalar_handler: " << e.what() )
142 return std::unique_ptr< param_value >();
157 if( a_filename.empty() )
159 LERROR( slog,
"Filename cannot be an empty string" );
163 FILE* file = fopen( a_filename.c_str(),
"w" );
167 LERROR( slog,
"Unable to open file: " << a_filename );
173 std::ofstream fout( a_filename.c_str() );
184 std::stringstream t_out;
186 a_string = t_out.str();
197 else if( a_to_write.
is_node() )
209 LWARN( slog,
"Unknown param type encountered" );
231 for (
int count = 0; count != (int) array.
size(); ++count )
246 return t_node = value.
as_bool();
251 return t_node = value.
as_uint();
261 return t_node = value.
as_int();
269 LWARN( slog,
"Unkown value type encountered" );
virtual bool is_node() const
REGISTER_PARAM_INPUT_CODEC(param_input_json,"json")
REGISTER_PARAM_OUTPUT_CODEC(param_output_json,"json")
virtual bool is_value() const
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())
virtual const char * what() const
Contains the logger class and macros, based on Kasper's KLogger class.
std::string as_string() const
YAML::Node param_value_handler(const param &a_to_write)
virtual bool is_null() const
virtual ~param_output_yaml()
std::unique_ptr< param > param_ptr_t
YAML::Node param_array_handler(const param &a_to_write)
void push_back(const param &a_value)
YAML::Node check_param_type(const param &a_to_write)
virtual bool is_array() const
YAML::Node param_node_handler(const param &a_to_write)
LOGGER(mtlog,"authentication")