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