Flow123d  3.9.1-0844c3d
type_tuple.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_tuple.hh
15  * @brief
16  */
17 
18 #ifndef TYPE_TUPLE_HH_
19 #define TYPE_TUPLE_HH_
20 
21 #include "system/exceptions.hh"
22 #include "type_record.hh"
23 #include "type_base.hh"
24 
25 #include <string>
26 
27 namespace Input {
28 
29 namespace Type {
30 
31 /**
32  * @brief Tuple type proxy class.
33  *
34  * Class is used for small data items, which are repeated several times. Declaration is same
35  * as for the Record. Allows two possibilities of declaration:
36  * - same as the Record notation (using named keys)
37  * - list of values in the order how the keys are defined
38  *
39  * In declaration, obligatory keys must be given as first, optional and default at read time
40  * keys follows. Correct order is checked in @p finish method. Auto conversion is allowed
41  * for the first key.
42  *
43  * Tuple type can't be descendant of Abstract.
44  */
45 class Tuple : public Record {
46 public:
47  /*
48  * Exceptions specific to this class.
49  */
50  TYPEDEF_ERR_INFO( EI_TupleName, const string);
51  DECLARE_EXCEPTION( ExcTupleWrongKeysOrder, << "Incorrect order of obligatory and non-obligatory keys in Tuple: " << EI_TupleName::qval );
52 
53 
54  /// Default constructor. Empty handle.
55  Tuple();
56 
57  /**
58  * @brief Copy constructor.
59  *
60  * We allow only copies of non-empty tuples.
61  */
62  Tuple(const Tuple & other);
63 
64 
65  /**
66  * @brief Basic constructor.
67  *
68  * You have to provide \p type_name of the new declared Record type and its \p description.
69  */
70  Tuple(const string & type_name_in, const string & description);
71 
72  /**
73  * Implements @p TypeBase::content_hash.
74  *
75  * Hash is calculated by type name, description, hash of keys and attributes.
76  */
77  TypeHash content_hash() const override;
78 
79  /// Override @p Type::TypeBase::class_name.
80  string class_name() const override;
81 
82  /**
83  * @brief Override Record::allow_auto_conversion
84  *
85  * Forbids setting of auto conversion key. Tuple type can have auto convertible the first key.
86  */
87  Tuple &allow_auto_conversion(const string &from_key) override;
88 
89  /// Class comparison and Tuple type name comparison.
90  bool operator==(const TypeBase &other) const override;
91 
92  /**
93  * @brief Close the Tuple for further declarations of keys.
94  *
95  * @see Record::close
96  */
97  const Tuple &close() const;
98 
99  /**
100  * @brief Finish declaration of the Tuple type.
101  *
102  * Completes Tuple (check auto convertible key, parameters of generic types etc).
103  */
104  FinishStatus finish(FinishStatus finish_type = FinishStatus::regular_) override;
105 
106  /**
107  * @brief Override Record::derive_from
108  *
109  * Deriving of Tuple type is forbidden. Type is determined for small simple data.
110  */
111  Tuple &derive_from(Abstract &parent) override;
112 
113  /**
114  * @brief Return count of obligatory keys.
115  *
116  * Needs in exceptions.
117  */
118  unsigned int obligatory_keys_count() const;
119 
120  /// Implements @p TypeBase::make_instance.
122 
123  /// Overrides Record::deep_copy
124  Tuple deep_copy() const;
125 
126  /// Overrides Record::root_of_generic_subtree
127  Tuple &root_of_generic_subtree() override;
128 
129  /// Overrides Record::declare_key(const string &, std::shared_ptr<TypeBase>, const Default &, const string &)
130  Tuple &declare_key(const string &key, std::shared_ptr<TypeBase> type,
131  const Default &default_value, const string &description,
133 
134  /// Overrides Record::declare_key(const string &, const KeyType &, const Default &, const string &)
135  template <class KeyType>
136  Tuple &declare_key(const string &key, const KeyType &type,
137  const Default &default_value, const string &description,
139 
140 
141  /// Overrides Record::declare_key(const string &, const KeyType &, const string &)
142  template <class KeyType>
143  Tuple &declare_key(const string &key, const KeyType &type,
144  const string &description,
146 
147 };
148 
149 } // closing namespace Type
150 } // closing namespace Input
151 
152 #endif /* TYPE_TUPLE_HH_ */
Input::Type::Tuple::derive_from
Tuple & derive_from(Abstract &parent) override
Override Record::derive_from.
Definition: type_tuple.cc:132
Armor::vec
ArmaVec< double, N > vec
Definition: armor.hh:885
Input::Type::FinishStatus
FinishStatus
Definition: type_base.hh:74
Input::Type::Tuple::make_instance
MakeInstanceReturnType make_instance(std::vector< ParameterPair > vec=std::vector< ParameterPair >()) override
Implements TypeBase::make_instance.
Definition: type_tuple.cc:148
Input
Abstract linear system class.
Definition: balance.hh:40
Input::Type::Tuple::root_of_generic_subtree
Tuple & root_of_generic_subtree() override
Overrides Record::root_of_generic_subtree.
Definition: type_tuple.cc:167
Input::Type::Tuple::TYPEDEF_ERR_INFO
TYPEDEF_ERR_INFO(EI_TupleName, const string)
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
Input::Type::Tuple::deep_copy
Tuple deep_copy() const
Overrides Record::deep_copy.
Definition: type_tuple.cc:155
std::vector
Definition: doxy_dummy_defs.hh:7
Input::Type::Tuple
Tuple type proxy class.
Definition: type_tuple.hh:45
type_base.hh
exceptions.hh
type_record.hh
Input::Type::Default
Class Input::Type::Default specifies default value of keys of a Input::Type::Record.
Definition: type_record.hh:61
Input::Type::Tuple::Tuple
Tuple()
Default constructor. Empty handle.
Definition: type_tuple.cc:29
Input::Type::Tuple::close
const Tuple & close() const
Close the Tuple for further declarations of keys.
Definition: type_tuple.cc:70
Input::Type::regular_
@ regular_
Definition: type_base.hh:77
Input::Type::Abstract
Class for declaration of polymorphic Record.
Definition: type_abstract.hh:62
Input::Type::Tuple::declare_key
Tuple & declare_key(const string &key, std::shared_ptr< TypeBase > type, const Default &default_value, const string &description, TypeBase::attribute_map key_attributes=TypeBase::attribute_map())
Overrides Record::declare_key(const string &, std::shared_ptr<TypeBase>, const Default &,...
Definition: type_tuple.cc:173
std::map< std::string, json_string >
Input::Type::Tuple::class_name
string class_name() const override
Override Type::TypeBase::class_name.
Definition: type_tuple.cc:52
Input::Type::Tuple::operator==
bool operator==(const TypeBase &other) const override
Class comparison and Tuple type name comparison.
Definition: type_tuple.cc:64
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
Input::Type::Tuple::obligatory_keys_count
unsigned int obligatory_keys_count() const
Return count of obligatory keys.
Definition: type_tuple.cc:139
Input::Type::Tuple::content_hash
TypeHash content_hash() const override
Definition: type_tuple.cc:43
Input::Type::Tuple::finish
FinishStatus finish(FinishStatus finish_type=FinishStatus::regular_) override
Finish declaration of the Tuple type.
Definition: type_tuple.cc:90
Input::Type::Tuple::allow_auto_conversion
Tuple & allow_auto_conversion(const string &from_key) override
Override Record::allow_auto_conversion.
Definition: type_tuple.cc:57
Input::Type::TypeBase
Base of classes for declaring structure of the input data.
Definition: type_base.hh:92
Input::Type::TypeBase::TypeHash
std::size_t TypeHash
Type returned by content_hash methods.
Definition: type_base.hh:95
Input::Type::Tuple::DECLARE_EXCEPTION
DECLARE_EXCEPTION(ExcTupleWrongKeysOrder,<< "Incorrect order of obligatory and non-obligatory keys in Tuple: "<< EI_TupleName::qval)