Flow123d  master-7bf36fe
reader_internal.cc
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file reader_internal.cc
15  * @brief
16  */
17 
18 
19 #include "input/reader_internal.hh"
22 #include "input/input_type.hh"
23 
24 namespace Input {
25 
26 using namespace std;
27 
28 
29 /*******************************************************************
30  * implementation of ReaderInternal
31  */
32 
34 {}
35 
37 {
38  return this->make_storage(p, type);
39 }
40 
42 {
43  int arr_size;
44  if ( (arr_size = p.get_array_size()) != -1 ) {
45  return this->make_array_storage(p, array, arr_size);
46  } else if (p.get_record_tag() == "include") {
47  return make_include_storage(p, array);
48  } else if (p.get_record_tag().substr(0,11) == "include_csv") {
49  ReaderInternalCsvInclude reader_csv;
50  return reader_csv.read_storage(p, array);
51  } else {
52  ReaderInternalTranspose reader_transpose;
53  return reader_transpose.read_storage(p, array);
54  }
55 }
56 
58 {
59  string item_name = read_string_value(p, selection);
60  try {
61  int value = selection->name_to_int( item_name );
62  return new StorageInt( value );
63  } catch (Type::Selection::ExcSelectionKeyNotFound &exc) {
64  this->generate_input_error(p, selection, "Wrong value '" + item_name + "' of the Selection.", false);
65  }
66 
67  return NULL;
68 }
69 
71 {
72  return new StorageBool( read_bool_value(p, bool_type) );
73 }
74 
76 {
77  std::int64_t value = read_int_value(p, int_type);
78 
79  if ( int_type->match(value) )
80  {
81  return new StorageInt( value );
82  } else {
83  this->generate_input_error(p, int_type, "Value out of bounds.", false);
84  }
85  return NULL;
86 }
87 
89 {
90  double value = read_double_value(p, double_type);
91 
92  if (double_type->match(value)) {
93  return new StorageDouble( value );
94  } else {
95  this->generate_input_error(p, double_type, "Value out of bounds.", false);
96  }
97 
98  return NULL;
99 }
100 
102 {
103  string value = read_string_value(p, string_type);
104 
105  if (string_type->match(value))
106  return new StorageString( value );
107  else
108  THROW( ExcInputError() << EI_Specification("Output file can not be given by absolute path: '" + value + "'")
109  << EI_ErrorAddress(p.as_string()) << EI_JSON_Type("") << EI_InputType(string_type->desc()) );
110 
111  return NULL;
112 }
113 
114 
115 } // namespace Input
Input::StorageBase
Base class for nodes of a data storage tree.
Definition: storage.hh:68
Input::Type::Bool
Class for declaration of the input of type Bool.
Definition: type_base.hh:452
Input::int_type
@ int_type
Definition: reader_to_storage.hh:72
Input::ReaderInternal::ReaderInternal
ReaderInternal()
Constructor.
Definition: reader_internal.cc:33
Input
Abstract linear system class.
Definition: balance.hh:40
Input::Type::Integer
Class for declaration of the integral input data.
Definition: type_base.hh:483
Input::PathBase
Base abstract class used by ReaderToStorage class to iterate over the input tree.
Definition: path_base.hh:41
value
static constexpr bool value
Definition: json.hpp:87
Input::Type::Double
Class for declaration of the input data that are floating point numbers.
Definition: type_base.hh:534
Armor::array
Array< double > array
Definition: armor.hh:890
THROW
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
Definition: exceptions.hh:53
Input::StorageString
Definition: storage.hh:147
Input::bool_type
@ bool_type
Definition: reader_to_storage.hh:72
Input::PathBase::as_string
std::string as_string() const
Returns string address of current position.
Definition: path_base.cc:48
Input::PathBase::get_array_size
virtual int get_array_size() const =0
Get size of array (sequence type), if object is not array return -1.
Input::ReaderInternalTranspose::read_storage
StorageBase * read_storage(PathBase &p, const Type::Array *array)
Create storage of transposed subtree of given Array.
Definition: reader_internal_transpose.cc:35
reader_internal_transpose.hh
reader_internal.hh
Input::StorageInt
Definition: storage.hh:121
Input::Type::Selection::name_to_int
int name_to_int(const string &key) const
Converts given value name key to the value.
Definition: type_selection.cc:130
Input::PathBase::get_record_tag
virtual std::string get_record_tag() const =0
Gets value of the record tag, which determines its type.
reader_internal_csv.hh
Input::StorageBool
Definition: storage.hh:109
Input::Type::Selection
Template for classes storing finite set of named values.
Definition: type_selection.hh:65
Input::ReaderInternal::make_sub_storage
StorageBase * make_sub_storage(PathBase &p, const Type::Array *array) override
Create storage of Type::Array type.
Definition: reader_internal.cc:41
Input::Type::String::match
virtual bool match(const string &value) const
Definition: type_base.cc:620
input_type.hh
Input::Type::Double::match
bool match(double value) const
Returns true if the given integer value conforms to the Type::Double bounds.
Definition: type_base.cc:489
Input::Type::Array
Class for declaration of inputs sequences.
Definition: type_base.hh:339
Input::Type::String
Class for declaration of the input data that are in string format.
Definition: type_base.hh:582
Input::ReaderInternalCsvInclude
Creates storage of part of subtree defined in CSV file.
Definition: reader_internal_csv.hh:42
std
Definition: doxy_dummy_defs.hh:5
Input::Type::TypeBase::desc
string desc() const
Returns string with Type extensive documentation.
Definition: type_base.cc:99
Input::ReaderInternalTranspose
Creates storage of transposed subtree defined on input.
Definition: reader_internal_transpose.hh:41
Input::Type::TypeBase
Base of classes for declaring structure of the input data.
Definition: type_base.hh:92
Input::StorageDouble
Definition: storage.hh:134
Input::ReaderInternalCsvInclude::read_storage
StorageBase * read_storage(PathBase &p, const Type::Array *array)
Definition: reader_internal_csv.cc:38
Input::ReaderInternal::read_storage
StorageBase * read_storage(PathBase &p, const Type::TypeBase *type)
Create storage of given type.
Definition: reader_internal.cc:36