40 ASSERT_PTR(type).error(
"Can not dispatch, NULL pointer to TypeBase.");
48 StorageBase * storage = make_storage( *ref_path, type );
55 return make_sub_storage(p, static_cast<const Type::Tuple *>(type) );
58 return make_sub_storage(p, static_cast<const Type::Record *>(type) );
61 return make_sub_storage(p, static_cast<const Type::Array *>(type) );
64 if (abstract_record_type != NULL )
return make_sub_storage(p, abstract_record_type );
74 return make_sub_storage(p, static_cast<const Type::Integer *>(type) );
77 return make_sub_storage(p, static_cast<const Type::Double *>(type) );
80 return make_sub_storage(p, static_cast<const Type::Bool *>(type) );
83 return make_sub_storage(p, static_cast<const Type::Selection *>(type) );
86 if (string_type != NULL )
return make_sub_storage(p, string_type );
89 THROW( Type::ExcUnknownDescendant() << Type::EI_TypeName(
typeid(type).name()) );
99 if (record_name_from_tag ==
"include") {
100 return make_include_storage(p, record);
101 }
else if (record_name_from_tag ==
"include_csv") {
102 THROW( ExcForbiddenTag() << EI_Tag(
"include_csv")
103 << EI_Specification(
"can be used only with arrays.") << EI_Address(p.
as_string()) );
105 if ( record_name_from_tag !=
"" ) {
106 ASSERT(record_name_from_tag == record->
type_name())(record_name_from_tag)(record->
type_name()).error(
"Inconsistent tag of record.");
108 std::set<string> keys_to_process;
111 std::set<string>::iterator set_it;
134 set_it = keys_to_process.find(
it->key_);
135 if (set_it != keys_to_process.end()) {
136 keys_to_process.erase(set_it);
139 if ( !effectively_null && p.
down(
it->key_,
it->key_index) ) {
144 if ( obsolete_it !=
it->attributes.end()) {
145 WarningOut() <<
"Usage of the obsolete key: '" <<
it->key_ <<
"'\n" << obsolete_it -> second;
149 if ( (
typeid(*storage) ==
typeid(
StorageNull)) &&
it->default_.has_value_at_declaration() ) {
151 storage = make_storage_from_default(
it->default_.value(),
it->type_ );
153 storage_array->
new_item(
it->key_index, storage );
157 if (
it->default_.is_obligatory() ) {
158 this->generate_input_error(p, record,
"Missing obligatory key '"+
it->key_ +
"'.",
false);
159 }
else if (
it->default_.has_value_at_declaration() ) {
161 make_storage_from_default(
it->default_.value(),
it->type_ ) );
169 for( set_it = keys_to_process.begin(); set_it != keys_to_process.end(); ++set_it) {
171 <<
" '" << p.
as_string() <<
"'." << std::endl;
174 return storage_array;
177 return record_automatic_conversion(p, record);
193 if ( p.
down(
it->key_index) ) {
196 if ( (
typeid(*storage) ==
typeid(
StorageNull)) &&
it->default_.has_value_at_declaration() ) {
198 storage = make_storage_from_default(
it->default_.value(),
it->type_ );
200 storage_array->
new_item(
it->key_index, storage );
204 if (
it->default_.is_obligatory() ) {
208 this->generate_input_error(p, tuple, ss.str(),
false);
209 }
else if (
it->default_.has_value_at_declaration() ) {
211 make_storage_from_default(
it->default_.value(),
it->type_ ) );
219 if ( arr_size > (
int)tuple->
size() ) {
220 WarningOut().fmt(
"Unprocessed keys in tuple '{}', tuple has {} keys but the input is specified by {} values.\n",
224 return storage_array;
227 return make_sub_storage(p, static_cast<const Type::Record *>(tuple) );
234 if (record_tag ==
"") {
236 this->generate_input_error(p, abstr_rec,
"Can not determine type of the Abstract.",
true);
238 return abstract_automatic_conversion(p, abstr_rec);
240 }
else if (record_tag.substr(0,8) ==
"include:") {
241 string record_name = record_tag.substr(8);
243 return make_include_storage(p, &( abstr_rec->
get_descendant(record_name) ) );
244 }
catch (Type::Selection::ExcSelectionKeyNotFound &exc) {
245 this->generate_input_error(p, abstr_rec,
"Wrong value '" + record_tag +
"' of the Selection.",
false);
247 }
else if ((record_tag ==
"include") || (record_tag ==
"include_csv")) {
248 THROW( ExcForbiddenTag() << EI_Tag(record_tag)
249 << EI_Specification(
"can't be used with abstract type.") << EI_Address(p.
as_string()) );
252 return make_sub_storage(p, &( abstr_rec->
get_descendant(record_tag) ) );
253 }
catch (Type::Selection::ExcSelectionKeyNotFound &exc) {
254 this->generate_input_error(p, abstr_rec,
"Wrong value '" + record_tag +
"' of the Selection.",
false);
263 if ( auto_key_it != record->
end() ) {
267 if (
it == auto_key_it ) {
269 storage_array->
new_item(
it->key_index, make_storage(p,
it->type_.get()) );
270 }
else if (
it->default_.has_value_at_declaration() ) {
273 make_storage_from_default(
it->default_.value(),
it->type_ ) );
275 ASSERT(!
it->default_.is_obligatory())(
it->key_).error(
"Obligatory key in auto-convertible Record.");
281 return storage_array;
282 }
catch (ExcInputError &e ) {
283 THROW( ExcAutomaticConversionError() << EI_RecordName(record->
type_name())
284 << EI_InputErrorMessage(e.what()) );
299 this->generate_input_error(p, abstr_rec,
"Auto conversion of Abstract not allowed.\n",
false);
300 return make_sub_storage(p, default_child );
310 for(
int idx=0; idx < arr_size; idx++) {
313 storage_array->
new_item(idx, make_storage(p, &sub_type) );
316 return storage_array;
320 ss <<
"Do not fit the size " << arr_size <<
" of the Array.";
321 this->generate_input_error(p, array, ss.str(),
false);
331 }
catch (Input::Type::ExcWrongDefault & e) {
333 e << Type::EI_Desc(
"Wrong default value while reading an input stream:\n");
334 e << Type::EI_KeyName(
"UNKNOWN KEY");
336 }
catch (Input::Type::ExcWrongDefaultJSON & e) {
337 e << Type::EI_KeyName(
"UNKNOWN KEY");
346 std::string included_path;
349 if ( p.
down(
"file") ) {
350 included_path = get_included_file(p);
353 this->generate_input_error(p, type,
"Missing key 'file' defines including input file.",
false);
358 included_path = get_included_file(p);
361 FilePath fpath(included_path, FilePath::FileType::input_file);
362 ReaderToStorage include_reader(fpath, *(const_cast<Type::TypeBase *>(type)) );
372 catch (ExcInputError & e) {
374 e << EI_InputType(type->
desc());
387 catch (ExcInputError & e) {
389 e << EI_InputType(type->
desc());
402 catch (ExcInputError & e) {
404 e << EI_InputType(type->
desc());
416 }
catch (ExcInputError & e) {
418 e << EI_InputType(type->
desc());
430 catch (ExcInputError & e) {
432 e << EI_InputType(
"path to included file");
441 << EI_ErrorAddress(p.
as_string()) << EI_InputType(type->
desc()) );
443 THROW( ExcInputError() << EI_Specification(spec) << EI_JSON_Type(
"" )
444 << EI_ErrorAddress(p.
as_string()) << EI_InputType(type->
desc()) );
449 e << EI_Specification(
"The value should be '" + p.
get_node_type(value_type) +
"', but we found: ");
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
static constexpr bool value
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.