Flow123d  master-f44eb46
type_generic.hh
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 type_generic.hh
15  * @brief
16  */
17 
18 #ifndef TYPE_GENERIC_HH_
19 #define TYPE_GENERIC_HH_
20 
21 
22 #include <string> // for string
23 #include <vector> // for vector
24 #include "system/exceptions.hh" // for ExcStream, operator<<, DECLARE_E...
25 #include "input/type_base.hh"
26 
27 
28 
29 namespace Input {
30 
31 namespace Type {
32 
33 // Declaration of exception
34 TYPEDEF_ERR_INFO(EI_Object, std::string);
35 TYPEDEF_ERR_INFO(EI_ParameterList, std::string);
36 
37 DECLARE_EXCEPTION(ExcParamaterNotSubsituted,
38  << "No input type substitution for input type parameter " << EI_Object::qval
39  << " found during creation of instance with parameter list: " << EI_ParameterList::val << ".");
40 DECLARE_EXCEPTION(ExcParamaterInIst,
41  << "Parameter " << EI_Object::qval << " appears in the IST. Check where Instance is missing.");
42 DECLARE_EXCEPTION(ExcGenericWithoutInstance,
43  << "Root of generic subtree " << EI_Object::qval << " used without Instance.\n Used in type: " << EI_TypeName::qval);
44 
45 
46 
47 /**
48  * @brief Class for representing parametric types in IST.
49  *
50  * Instances of this class are used only in generic types and during generation
51  * of Record are replaced by types of IST (Integer, String, Selection etc.)
52  */
53 class Parameter : public TypeBase {
54 public:
55  /// Constructor.
56  Parameter(const string & parameter_name);
57 
58  /// Copy constructor.
59  Parameter(const Parameter & other);
60 
61  /**
62  * @brief Implements @p Type::TypeBase::type_name.
63  *
64  * Parameter type name getter.
65  */
66  string type_name() const override;
67  /// Override @p Type::TypeBase::class_name.
68  string class_name() const override;
69 
70  /// Implements @p TypeBase::content_hash.
71  TypeHash content_hash() const override;
72 
73  /// Implements @p TypeBase::make_instance.
75 
76  /// Implements @p TypeBase::finish.
78 
79 protected:
80  /// name of parameter
81  const string name_;
82 };
83 
84 
85 
86 /**
87  * @brief Helper class that stores data of generic types.
88  */
89 class Instance : public TypeBase {
90 public:
91  /// Constructor.
92  Instance(TypeBase &generic_type, std::vector<TypeBase::ParameterPair> parameters);
93 
94  /**
95  * @brief Implements @p TypeBase::content_hash.
96  *
97  * Hash is calculated by hash of generic type and hash of parameters.
98  */
99  TypeHash content_hash() const override;
100 
101  /// Used for set Instance to TypeRepository
102  const Instance &close() const;
103 
104  /// Finish declaration of the Instance type. Call finish of stored @p generic_type_
105  FinishStatus finish(FinishStatus finish_type = FinishStatus::regular_) override;
106 
107  /**
108  * @brief Implements @p TypeBase::make_instance.
109  *
110  * In first call creates instance and stores its to @p created_instance_.
111  *
112  * At each successive call returns this stored type.
113  */
115 
116 protected:
117  /// Reference to generic types (contains some descendants of type @p Parameter).
119 
120  /// Stores pairs of (name, Input::Type), that are used for replace of parameters in generic types.
122 
123  /**
124  * @brief Stores returned type created in first call of @p make_instance method.
125  *
126  * At each successive call of make_instance returns this stored type.
127  */
129 };
130 
131 
132 
133 } // closing namespace Type
134 } // closing namespace Input
135 
136 
137 
138 #endif /* TYPE_GENERIC_HH_ */
Helper class that stores data of generic types.
Definition: type_generic.hh:89
TypeBase & generic_type_
Reference to generic types (contains some descendants of type Parameter).
MakeInstanceReturnType make_instance(std::vector< ParameterPair > vec=std::vector< ParameterPair >()) override
Implements TypeBase::make_instance.
MakeInstanceReturnType created_instance_
Stores returned type created in first call of make_instance method.
Instance(TypeBase &generic_type, std::vector< TypeBase::ParameterPair > parameters)
Constructor.
Definition: type_generic.cc:91
std::vector< TypeBase::ParameterPair > parameters_
Stores pairs of (name, Input::Type), that are used for replace of parameters in generic types.
const Instance & close() const
Used for set Instance to TypeRepository.
TypeHash content_hash() const override
Implements TypeBase::content_hash.
Definition: type_generic.cc:95
FinishStatus finish(FinishStatus finish_type=FinishStatus::regular_) override
Finish declaration of the Instance type. Call finish of stored generic_type_.
Class for representing parametric types in IST.
Definition: type_generic.hh:53
Parameter(const string &parameter_name)
Constructor.
Definition: type_generic.cc:36
const string name_
name of parameter
Definition: type_generic.hh:81
FinishStatus finish(FinishStatus finish_type=FinishStatus::regular_) override
Implements TypeBase::finish.
Definition: type_generic.cc:79
TypeHash content_hash() const override
Implements TypeBase::content_hash.
Definition: type_generic.cc:54
MakeInstanceReturnType make_instance(std::vector< ParameterPair > vec=std::vector< ParameterPair >()) override
Implements TypeBase::make_instance.
Definition: type_generic.cc:63
string type_name() const override
Implements Type::TypeBase::type_name.
Definition: type_generic.cc:44
string class_name() const override
Override Type::TypeBase::class_name.
Definition: type_generic.cc:49
Base of classes for declaring structure of the input data.
Definition: type_base.hh:92
std::pair< std::shared_ptr< TypeBase >, ParameterMap > MakeInstanceReturnType
Return type of make_instance methods, contains instance of generic type and map of used parameters.
Definition: type_base.hh:111
std::size_t TypeHash
Type returned by content_hash methods.
Definition: type_base.hh:95
ArmaVec< double, N > vec
Definition: armor.hh:885
DECLARE_EXCEPTION(ExcWrongDefaultJSON,<< "Consistency Error: Not valid JSON of Default value "<< EI_DefaultStr::qval<< " of type "<< EI_TypeName::qval<< ";\n"<< "During declaration of the key: "<< EI_KeyName::qval)
TYPEDEF_ERR_INFO(EI_KeyName, const string)
Abstract linear system class.
Definition: balance.hh:40