Flow123d  3.9.1-0844c3d
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_ */
Armor::vec
ArmaVec< double, N > vec
Definition: armor.hh:885
Input::Type::FinishStatus
FinishStatus
Definition: type_base.hh:74
Input::Type::Instance::content_hash
TypeHash content_hash() const override
Implements TypeBase::content_hash.
Definition: type_generic.cc:95
Input
Abstract linear system class.
Definition: balance.hh:40
Input::Type::Instance::close
const Instance & close() const
Used for set Instance to TypeRepository.
Definition: type_generic.cc:108
Input::Type::Instance::finish
FinishStatus finish(FinishStatus finish_type=FinishStatus::regular_) override
Finish declaration of the Instance type. Call finish of stored generic_type_.
Definition: type_generic.cc:113
Input::Type::Instance::generic_type_
TypeBase & generic_type_
Reference to generic types (contains some descendants of type Parameter).
Definition: type_generic.hh:118
Input::Type::Instance::Instance
Instance(TypeBase &generic_type, std::vector< TypeBase::ParameterPair > parameters)
Constructor.
Definition: type_generic.cc:91
Input::Type::TypeBase::MakeInstanceReturnType
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::vector
Definition: doxy_dummy_defs.hh:7
Input::Type::TYPEDEF_ERR_INFO
TYPEDEF_ERR_INFO(EI_KeyName, const string)
Input::Type::Parameter::Parameter
Parameter(const string &parameter_name)
Constructor.
Definition: type_generic.cc:36
type_base.hh
exceptions.hh
Input::Type::Instance::created_instance_
MakeInstanceReturnType created_instance_
Stores returned type created in first call of make_instance method.
Definition: type_generic.hh:128
Input::Type::Parameter::class_name
string class_name() const override
Override Type::TypeBase::class_name.
Definition: type_generic.cc:49
Input::Type::regular_
@ regular_
Definition: type_base.hh:77
Input::Type::Instance::make_instance
MakeInstanceReturnType make_instance(std::vector< ParameterPair > vec=std::vector< ParameterPair >()) override
Implements TypeBase::make_instance.
Definition: type_generic.cc:122
Input::Type::Instance
Helper class that stores data of generic types.
Definition: type_generic.hh:89
Input::Type::Parameter::make_instance
MakeInstanceReturnType make_instance(std::vector< ParameterPair > vec=std::vector< ParameterPair >()) override
Implements TypeBase::make_instance.
Definition: type_generic.cc:63
Input::Type::Parameter::content_hash
TypeHash content_hash() const override
Implements TypeBase::content_hash.
Definition: type_generic.cc:54
Input::Type::Parameter::finish
FinishStatus finish(FinishStatus finish_type=FinishStatus::regular_) override
Implements TypeBase::finish.
Definition: type_generic.cc:79
Input::Type::DECLARE_EXCEPTION
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)
Input::Type::Parameter::name_
const string name_
name of parameter
Definition: type_generic.hh:81
Input::Type::Parameter::type_name
string type_name() const override
Implements Type::TypeBase::type_name.
Definition: type_generic.cc:44
Input::Type::Parameter
Class for representing parametric types in IST.
Definition: type_generic.hh:53
Input::Type::TypeBase
Base of classes for declaring structure of the input data.
Definition: type_base.hh:92
Input::Type::Instance::parameters_
std::vector< TypeBase::ParameterPair > parameters_
Stores pairs of (name, Input::Type), that are used for replace of parameters in generic types.
Definition: type_generic.hh:121
Input::Type::TypeBase::TypeHash
std::size_t TypeHash
Type returned by content_hash methods.
Definition: type_base.hh:95