Flow123d  release_3.0.0-906-g65cc372
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
Base of classes for declaring structure of the input data.
Definition: type_base.hh:99
Base class for nodes of a data storage tree.
Definition: storage.hh:68
ReaderInternal()
Constructor.
string desc() const
Returns string with Type extensive documentation.
Definition: type_base.cc:100
Class for declaration of the input of type Bool.
Definition: type_base.hh:459
Base abstract class used by ReaderToStorage class to iterate over the input tree. ...
Definition: path_base.hh:41
Abstract linear system class.
Definition: balance.hh:35
int name_to_int(const string &key) const
Converts given value name key to the value.
std::string as_string() const
Returns string address of current position.
Definition: path_base.cc:48
virtual int get_array_size() const =0
Get size of array (sequence type), if object is not array return -1.
Class for declaration of the integral input data.
Definition: type_base.hh:490
Class for declaration of inputs sequences.
Definition: type_base.hh:346
static constexpr bool value
Definition: json.hpp:87
virtual std::string get_record_tag() const =0
Gets value of the record tag, which determines its type.
Class for declaration of the input data that are floating point numbers.
Definition: type_base.hh:541
bool match(std::int64_t value) const
Check valid value of Integer.
Definition: type_base.cc:449
Creates storage of transposed subtree defined on input.
bool match(double value) const
Returns true if the given integer value conforms to the Type::Double bounds.
Definition: type_base.cc:491
StorageBase * read_storage(PathBase &p, const Type::Array *array)
StorageBase * make_sub_storage(PathBase &p, const Type::Array *array) override
Create storage of Type::Array type.
virtual bool match(const string &value) const
Particular descendants can check validity of the string.
Definition: type_base.cc:622
Creates storage of part of subtree defined in CSV file.
StorageBase * read_storage(PathBase &p, const Type::Array *array)
Create storage of transposed subtree of given Array.
Class for declaration of the input data that are in string format.
Definition: type_base.hh:589
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
Definition: exceptions.hh:53
Template for classes storing finite set of named values.
StorageBase * read_storage(PathBase &p, const Type::TypeBase *type)
Create storage of given type.