20 #include <boost/iostreams/device/file.hpp> 21 #include <boost/iostreams/filtering_stream.hpp> 41 try_transpose_read_(false)
49 std::string fname = in_file;
50 std::string extension = fname.substr(fname.find_last_of(
".") + 1);
52 if (extension ==
"con") {
54 }
else if (extension ==
"yaml") {
57 THROW(ExcInputMessage() << EI_Message(
"Invalid extension of file " + fname +
".\nMust be 'con' or 'yaml'."));
60 std::ifstream in(fname.c_str());
62 THROW(ExcInputMessage() << EI_Message(
"Can not open main input file: '" + fname +
"'.\n"));
80 istringstream is(str);
82 }
catch (ExcNotJSONFormat &e) {
83 e << EI_File(
"STRING: "+str);
throw;
101 std::unique_ptr<PathBase> root_path_ptr(root_path);
106 }
catch (ExcInputError &e) {
108 e << EI_Format(
"JSON");
110 e << EI_Format(
"YAML");
130 FEAL_DEBUG_ASSERT(type != NULL).error(
"Can not dispatch, NULL pointer to TypeBase.");
149 return make_storage(p, static_cast<const Type::Tuple *>(type) );
152 return make_storage(p, static_cast<const Type::Record *>(type) );
155 return make_storage(p, static_cast<const Type::Array *>(type) );
158 return make_storage(p, static_cast<const Type::Integer *>(type) );
161 return make_storage(p, static_cast<const Type::Double *>(type) );
164 return make_storage(p, static_cast<const Type::Bool *>(type) );
167 return make_storage(p, static_cast<const Type::Selection *>(type) );
170 if (abstract_record_type != NULL )
return make_storage(p, abstract_record_type );
173 if (string_type != NULL )
return make_storage(p, string_type );
176 xprintf(
Err,
"Unknown descendant of TypeBase class, name: %s\n",
typeid(type).name());
185 std::set<string> keys_to_process;
187 std::set<string>::iterator set_it;
210 set_it = keys_to_process.find(
it->key_);
211 if (set_it != keys_to_process.end()) {
212 keys_to_process.erase(set_it);
218 if ( (
typeid(*storage) ==
typeid(
StorageNull)) &&
it->default_.has_value_at_declaration() ) {
222 storage_array->
new_item(
it->key_index, storage );
226 if (
it->default_.is_obligatory() ) {
227 THROW( ExcInputError() << EI_Specification(
"Missing obligatory key '"+
it->key_ +
"'.")
228 << EI_ErrorAddress(p.
as_string()) << EI_InputType(record->
desc()) );
229 }
else if (
it->default_.has_value_at_declaration() ) {
239 for( set_it = keys_to_process.begin(); set_it != keys_to_process.end(); ++set_it) {
243 return storage_array;
255 if ( auto_key_it != record->
end() ) {
259 if (
it == auto_key_it ) {
262 }
else if (
it->default_.has_value_at_declaration() ) {
267 FEAL_DEBUG_ASSERT(!
it->default_.is_obligatory())(
it->key_).error(
"Obligatory key in auto-convertible Record.");
273 return storage_array;
274 }
catch (ExcInputError &e ) {
275 THROW( ExcAutomaticConversionError() << EI_RecordName(record->
type_name()) << EI_InputErrorMessage(e.what()) );
281 << EI_InputType( record->
desc()) );
294 if ( descendant_name ==
"" ) {
296 THROW( ExcInputError() << EI_Specification(
"Missing key 'TYPE' in Abstract.") << EI_ErrorAddress(p.
as_string()) << EI_InputType(abstr_rec->
desc()) );
303 }
catch (Type::Selection::ExcSelectionKeyNotFound &exc) {
304 THROW( ExcInputError() << EI_Specification(
"Wrong value '" + descendant_name +
"' of the Selection.")
326 if (! default_child)
THROW(ExcInputError()
327 << EI_Specification(
"Auto conversion of Abstract not allowed.\n")
329 << EI_InputType(abstr_rec->
desc())
342 for(
int idx=0; idx < arr_size; idx++) {
348 return storage_array;
353 THROW( ExcInputError()
354 << EI_Specification(
"Do not fit the size " + ss.str() +
" of the Array.")
355 << EI_ErrorAddress(p.
as_string()) << EI_InputType(array->
desc()) );
374 }
catch (ExcInputError &e) {
399 THROW( ExcInputError() << EI_Specification(
"Result of transpose auto-conversion do not fit the size " + ss.str() +
" of the Array.")
400 << EI_ErrorAddress(p.
as_string()) << EI_InputType(array->
desc()) );
405 storage_array->
new_item(0, first_item_storage);
411 }
catch (ExcInputError &e) {
421 return storage_array;
423 THROW( ExcInputError()
425 << EI_ErrorAddress(p.
as_string()) << EI_InputType(array->
desc()) );
445 if ( p.
down(
it->key_index) ) {
448 if ( (
typeid(*storage) ==
typeid(
StorageNull)) &&
it->default_.has_value_at_declaration() ) {
452 storage_array->
new_item(
it->key_index, storage );
456 if (
it->default_.is_obligatory() ) {
459 THROW( ExcInputError()
461 + ss.str() +
" obligatory keys.")
463 << EI_InputType(tuple->
desc()) );
464 }
else if (
it->default_.has_value_at_declaration() ) {
476 return storage_array;
479 return make_storage(p, static_cast<const Type::Record *>(tuple) );
496 }
catch (ExcInputError & e) {
500 e << EI_InputType(selection->
desc());
502 }
catch (Type::Selection::ExcSelectionKeyNotFound &exc) {
503 THROW( ExcInputError() << EI_Specification(
"Wrong value '" + item_name +
"' of the Selection.")
504 << EI_ErrorAddress(p.
as_string()) << EI_JSON_Type(
"" ) << EI_InputType(selection->
desc()) );
521 catch (ExcInputError & e) {
525 e << EI_InputType(bool_type->
desc());
543 catch (ExcInputError & e) {
547 e << EI_InputType(int_type->
desc());
551 if ( int_type->
match(value) )
555 THROW( ExcInputError() << EI_Specification(
"Value out of bounds.") << EI_ErrorAddress(p.
as_string())
556 << EI_InputType(int_type->
desc()) );
575 catch (ExcInputError & e) {
579 e << EI_InputType(double_type->
desc());
583 if (double_type->
match(value)) {
586 THROW( ExcInputError() << EI_Specification(
"Value out of bounds.") << EI_ErrorAddress(p.
as_string())
587 << EI_InputType(double_type->
desc()) );
605 catch (ExcInputError & e) {
612 e << EI_InputType(string_type->
desc());
616 if (string_type->
match(value))
619 THROW( ExcInputError() << EI_Specification(
"Output file can not be given by absolute path: '" + value +
"'")
620 << EI_ErrorAddress(p.
as_string()) << EI_JSON_Type(
"") << EI_InputType(string_type->
desc()) );
633 }
catch (Input::Type::ExcWrongDefault & e) {
635 xprintf(
Msg,
"Wrong default value while reading an input stream:\n");
636 e << EI_KeyName(
"UNKNOWN KEY");
650 if ( arr_size == 0 ) {
651 THROW( ExcInputError() << EI_Specification(
"Empty array during transpose auto-conversion.")
652 << EI_ErrorAddress(p.
as_string()) << EI_InputType(type->
desc()) );
672 return storage_array;
674 THROW( ExcInputError()
675 << 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: ")
697 auto tmp_root_type =
static_cast<const typename T::InputType &
>(*root_type_);
698 return T( addr, tmp_root_type );
702 template ::Input::Record ReaderToStorage::get_root_interface<::Input::Record>()
const;
703 template ::Input::Array ReaderToStorage::get_root_interface<::Input::Array>()
const;
704 template ::Input::AbstractRecord ReaderToStorage::get_root_interface<::Input::AbstractRecord>()
const;
705 template ::Input::Tuple ReaderToStorage::get_root_interface<::Input::Tuple>()
const;
#define FEAL_DEBUG_ASSERT(expr)
Definition of assert for debug mode only.
#define FEAL_ASSERT(expr)
Definition of assert for debug and release mode.
Dedicated class for storing path to input and output files.
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.