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