20 #include <boost/iostreams/device/file.hpp> 21 #include <boost/iostreams/filtering_stream.hpp> 43 try_transpose_read_(false),
52 std::string fname = in_file;
53 std::string extension = fname.substr(fname.find_last_of(
".") + 1);
55 if (extension ==
"con") {
57 }
else if (extension ==
"yaml") {
60 THROW(ExcInputMessage() << EI_Message(
"Invalid extension of file " + fname +
".\nMust be 'con' or 'yaml'."));
81 istringstream is(str);
83 }
catch (ExcNotJSONFormat &e) {
84 e << EI_File(
"STRING: "+str);
throw;
102 std::unique_ptr<PathBase> root_path_ptr(root_path);
107 }
catch (ExcInputError &e) {
109 e << EI_Format(
"JSON");
111 e << EI_Format(
"YAML");
131 ASSERT_PTR(type).error(
"Can not dispatch, NULL pointer to TypeBase.");
146 return make_storage(p, static_cast<const Type::Tuple *>(type) );
149 return make_storage(p, static_cast<const Type::Record *>(type) );
152 return make_storage(p, static_cast<const Type::Array *>(type) );
155 if (abstract_record_type != NULL )
return make_storage(p, abstract_record_type );
165 return make_storage(p, static_cast<const Type::Integer *>(type) );
168 return make_storage(p, static_cast<const Type::Double *>(type) );
171 return make_storage(p, static_cast<const Type::Bool *>(type) );
174 return make_storage(p, static_cast<const Type::Selection *>(type) );
177 if (string_type != NULL )
return make_storage(p, string_type );
180 THROW( Type::ExcUnknownDescendant() << Type::EI_TypeName(
typeid(type).name()) );
189 std::set<string> keys_to_process;
192 std::set<string>::iterator set_it;
215 set_it = keys_to_process.find(
it->key_);
216 if (set_it != keys_to_process.end()) {
217 keys_to_process.erase(set_it);
220 if ( !effectively_null && p.
down(
it->key_) ) {
225 if ( obsolete_it !=
it->attributes.end()) {
226 WarningOut() <<
"Usage of the obsolete key: '" <<
it->key_ <<
"'\n" << obsolete_it -> second;
230 if ( (
typeid(*storage) ==
typeid(
StorageNull)) &&
it->default_.has_value_at_declaration() ) {
234 storage_array->
new_item(
it->key_index, storage );
238 if (
it->default_.is_obligatory() ) {
239 THROW( ExcInputError() << EI_Specification(
"Missing obligatory key '"+
it->key_ +
"'.")
240 << EI_ErrorAddress(p.
as_string()) << EI_InputType(record->
desc()) );
241 }
else if (
it->default_.has_value_at_declaration() ) {
251 for( set_it = keys_to_process.begin(); set_it != keys_to_process.end(); ++set_it) {
253 <<
" '" << p.
as_string() <<
"'." << std::endl;
256 return storage_array;
268 if ( auto_key_it != record->
end() ) {
272 if (
it == auto_key_it ) {
275 }
else if (
it->default_.has_value_at_declaration() ) {
280 ASSERT(!
it->default_.is_obligatory())(
it->key_).error(
"Obligatory key in auto-convertible Record.");
286 return storage_array;
287 }
catch (ExcInputError &e ) {
288 THROW( ExcAutomaticConversionError() << EI_RecordName(record->
type_name()) << EI_InputErrorMessage(e.what()) );
294 << EI_InputType( record->
desc()) );
307 if ( descendant_name ==
"" ) {
309 THROW( ExcInputError() << EI_Specification(
"Missing key 'TYPE' in Abstract.") << EI_ErrorAddress(p.
as_string()) << EI_InputType(abstr_rec->
desc()) );
316 }
catch (Type::Selection::ExcSelectionKeyNotFound &exc) {
317 THROW( ExcInputError() << EI_Specification(
"Wrong value '" + descendant_name +
"' of the Selection.")
339 if (! default_child)
THROW(ExcInputError()
340 << EI_Specification(
"Auto conversion of Abstract not allowed.\n")
342 << EI_InputType(abstr_rec->
desc())
355 for(
int idx=0; idx < arr_size; idx++) {
361 return storage_array;
366 THROW( ExcInputError()
367 << EI_Specification(
"Do not fit the size " + ss.str() +
" of the Array.")
368 << EI_ErrorAddress(p.
as_string()) << EI_InputType(array->
desc()) );
387 }
catch (ExcInputError &e) {
412 THROW( ExcInputError() << EI_Specification(
"Result of transpose auto-conversion do not fit the size " + ss.str() +
" of the Array.")
413 << EI_ErrorAddress(p.
as_string()) << EI_InputType(array->
desc()) );
418 storage_array->
new_item(0, first_item_storage);
424 }
catch (ExcInputError &e) {
434 return storage_array;
436 THROW( ExcInputError()
438 << EI_ErrorAddress(p.
as_string()) << EI_InputType(array->
desc()) );
458 if ( p.
down(
it->key_index) ) {
461 if ( (
typeid(*storage) ==
typeid(
StorageNull)) &&
it->default_.has_value_at_declaration() ) {
465 storage_array->
new_item(
it->key_index, storage );
469 if (
it->default_.is_obligatory() ) {
472 THROW( ExcInputError()
474 + ss.str() +
" obligatory keys.")
476 << EI_InputType(tuple->
desc()) );
477 }
else if (
it->default_.has_value_at_declaration() ) {
487 if ( arr_size > (
int)tuple->
size() ) {
488 WarningOut().fmt(
"Unprocessed keys in tuple '{}', tuple has {} keys but the input is specified by {} values.\n",
492 return storage_array;
495 return make_storage(p, static_cast<const Type::Record *>(tuple) );
512 }
catch (ExcInputError & e) {
516 e << EI_InputType(selection->
desc());
518 }
catch (Type::Selection::ExcSelectionKeyNotFound &exc) {
519 THROW( ExcInputError() << EI_Specification(
"Wrong value '" + item_name +
"' of the Selection.")
520 << EI_ErrorAddress(p.
as_string()) << EI_JSON_Type(
"" ) << EI_InputType(selection->
desc()) );
537 catch (ExcInputError & e) {
541 e << EI_InputType(bool_type->
desc());
559 catch (ExcInputError & e) {
563 e << EI_InputType(int_type->
desc());
567 if ( int_type->
match(value) )
571 THROW( ExcInputError() << EI_Specification(
"Value out of bounds.") << EI_ErrorAddress(p.
as_string())
572 << EI_InputType(int_type->
desc()) );
591 catch (ExcInputError & e) {
595 e << EI_InputType(double_type->
desc());
599 if (double_type->
match(value)) {
602 THROW( ExcInputError() << EI_Specification(
"Value out of bounds.") << EI_ErrorAddress(p.
as_string())
603 << EI_InputType(double_type->
desc()) );
621 catch (ExcInputError & e) {
628 e << EI_InputType(string_type->
desc());
632 if (string_type->
match(value))
635 THROW( ExcInputError() << EI_Specification(
"Output file can not be given by absolute path: '" + value +
"'")
636 << EI_ErrorAddress(p.
as_string()) << EI_JSON_Type(
"") << EI_InputType(string_type->
desc()) );
649 }
catch (Input::Type::ExcWrongDefault & e) {
651 e << Type::EI_Desc(
"Wrong default value while reading an input stream:\n");
652 e << EI_KeyName(
"UNKNOWN KEY");
654 }
catch (Input::Type::ExcWrongDefaultJSON & e) {
655 e << EI_KeyName(
"UNKNOWN KEY");
669 if ( arr_size == 0 ) {
670 THROW( ExcInputError() << EI_Specification(
"Empty array during transpose auto-conversion.")
671 << EI_ErrorAddress(p.
as_string()) << EI_InputType(type->
desc()) );
691 return storage_array;
693 THROW( ExcInputError()
694 << EI_Specification(
"During transpose auto-conversion, the conversion to the single element array not allowed. Require type: '" + p.
get_node_type(
ValueTypes::array_type) +
"'\nFound on input: ")
716 auto tmp_root_type =
static_cast<const typename T::InputType &
>(*root_type_);
717 return T( addr, tmp_root_type );
721 template ::Input::Record ReaderToStorage::get_root_interface<::Input::Record>()
const;
722 template ::Input::Array ReaderToStorage::get_root_interface<::Input::Array>()
const;
723 template ::Input::AbstractRecord ReaderToStorage::get_root_interface<::Input::AbstractRecord>()
const;
724 template ::Input::Tuple ReaderToStorage::get_root_interface<::Input::Tuple>()
const;
std::string format(CStringRef format_str, ArgList args)
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
void open_stream(Stream &stream) const
Dedicated class for storing path to input and output files.
#define ASSERT_PTR(ptr)
Definition of assert macro checking non-null pointer (PTR)
#define WarningOut()
Macro defining 'warning' record of log.
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.