Flow123d
release_3.0.0-959-g7b476d2
|
Template for classes storing finite set of named values. More...
#include <type_selection.hh>
Classes | |
struct | Key |
Structure for description of one key in selection. More... | |
class | SelectionData |
Internal data class. More... | |
Public Types | |
typedef std::vector< struct Key >::const_iterator | keys_const_iterator |
Public typedef of constant iterator into array of keys. More... | |
Public Types inherited from Input::Type::TypeBase | |
typedef std::size_t | TypeHash |
Type returned by content_hash methods. More... | |
typedef std::string | json_string |
String stored in JSON format. More... | |
typedef std::map< std::string, json_string > | attribute_map |
Defines map of Input::Type attributes. More... | |
typedef std::pair< std::string, std::shared_ptr< TypeBase > > | ParameterPair |
Defines pairs of (name, Input::Type), that are used for replace of parameters in generic types. More... | |
typedef std::vector< ParameterPair > | ParameterVector |
Define vector of parameters passed to the overloaded make_instance method. More... | |
typedef std::map< std::string, TypeHash > | ParameterMap |
Defines map of used parameters. More... | |
typedef std::pair< std::shared_ptr< TypeBase >, ParameterMap > | MakeInstanceReturnType |
Return type of make_instance methods, contains instance of generic type and map of used parameters. More... | |
Public Member Functions | |
TYPEDEF_ERR_INFO (EI_Selection, const Selection) | |
TYPEDEF_ERR_INFO (EI_Value, const int) | |
DECLARE_EXCEPTION (ExcSelectionKeyNotFound,<< "Key "<< EI_KeyName::qval<<" not found in Selection:\n"<< EI_Selection::val) | |
DECLARE_EXCEPTION (ExcSelectionValueNotFound,<< "Value "<< EI_Value::val<<" not found in Selection:\n"<< EI_Selection::val) | |
Selection () | |
Default constructor. Empty selection. More... | |
Selection (const Selection &other) | |
Copy constructor. More... | |
Selection (const string &name, const std::string &description="") | |
Creates a handle pointing to the new SelectionData. More... | |
Selection & | add_value (const int value, const std::string &key, const std::string &description="", TypeBase::attribute_map attributes=TypeBase::attribute_map()) |
Adds one new value with name given by key to the Selection. More... | |
Selection & | add_attribute (std::string key, TypeBase::json_string value) |
const Selection & | close () const |
Close the Selection, no more values can be added. More... | |
TypeHash | content_hash () const override |
Implements TypeBase::content_hash . More... | |
FinishStatus | finish_status () const override |
Implements TypeBase::finish_status . More... | |
bool | is_finished () const override |
Implements TypeBase::is_finished . More... | |
string | type_name () const override |
Implements Type::TypeBase::type_name . More... | |
string | class_name () const override |
Override Type::TypeBase::class_name . More... | |
bool | operator== (const TypeBase &other) const override |
Implements TypeBase::operator== compare also Selection names. More... | |
keys_const_iterator | begin () const |
Container-like access to the keys of the Selection. More... | |
keys_const_iterator | end () const |
Container-like access to the keys of the Selection. More... | |
keys_const_iterator | key_iterator (const string &key) const |
Returns iterator to the key struct for given key string. More... | |
int | name_to_int (const string &key) const |
Converts given value name key to the value. More... | |
string | int_to_name (const int &value) const |
Returns value name for the given value . More... | |
Selection & | copy_values (const Selection &sel) |
Copy all keys and values from sel . More... | |
bool | has_name (const string &key) const |
Just check if there is a particular name in the Selection. More... | |
bool | has_value (const int &val) const |
Check if there is a particular value in the Selection. More... | |
unsigned int | size () const |
Returns number of values in the Selection. More... | |
FinishStatus | finish (FinishStatus finish_type=FinishStatus::regular_) override |
Finish declaration of the Selection type. More... | |
bool | is_closed () const override |
Implements TypeBase::is_closed . More... | |
MakeInstanceReturnType | make_instance (std::vector< ParameterPair > vec=std::vector< ParameterPair >()) override |
Public Member Functions inherited from Input::Type::TypeBase | |
string | desc () const |
Returns string with Type extensive documentation. More... | |
bool | operator!= (const TypeBase &other) const |
Comparison of types. More... | |
virtual | ~TypeBase () |
Destructor. More... | |
std::string | hash_str () const |
Format the hash of this type. More... | |
virtual MakeInstanceReturnType | make_instance (ParameterVector vec=ParameterVector())=0 |
bool | is_root_of_generic_subtree () |
Indicates if type is marked with flag root_of_generic_subtree_ . More... | |
Private Member Functions | |
void | finished_check () const |
Assertion for finished Selection (methods are called in correct order). More... | |
string | key_list () const |
Create string from values of keys. More... | |
Private Attributes | |
std::shared_ptr< SelectionData > | data_ |
Handle to actual Selection data. More... | |
Friends | |
class | OutputBase |
Additional Inherited Members | |
Static Public Member Functions inherited from Input::Type::TypeBase | |
static void | delete_unfinished_types () |
Finishes and marks all types registered in type repositories and unused in IST. More... | |
static std::string | hash_str (TypeHash hash) |
Format given hash for output. More... | |
Static Public Attributes inherited from Input::Type::TypeBase | |
static const TypeHash | none_hash = std::numeric_limits<TypeHash>::max() |
Protected Types inherited from Input::Type::TypeBase | |
typedef string | KeyHash |
The type of hash values used in associative array that translates key names to indices in Record and Selection. More... | |
Protected Member Functions inherited from Input::Type::TypeBase | |
TypeBase () | |
The default constructor. More... | |
TypeBase (const TypeBase &other) | |
Copy constructor. More... | |
void | add_attribute_ (std::string name, json_string val) |
Add attribute of given name to attribute map. More... | |
bool | validate_json (json_string str) const |
Check if str is valid JSON string. More... | |
json_string | print_parameter_map_to_json (ParameterMap parameter_map) const |
Create JSON output from parameter_map formatted as value of attribute. More... | |
json_string | print_parameter_map_keys_to_json (ParameterMap param_map) const |
void | set_generic_attributes (ParameterMap param_map) |
void | copy_attributes (attribute_map other_attributes) |
Static Protected Member Functions inherited from Input::Type::TypeBase | |
static KeyHash | key_hash (const string &str) |
Hash function. More... | |
static bool | is_valid_identifier (const string &key) |
Check that a key is valid identifier. More... | |
Protected Attributes inherited from Input::Type::TypeBase | |
std::shared_ptr< attribute_map > | attributes_ |
map of type attributes (e. g. input_type, name etc.) More... | |
bool | root_of_generic_subtree_ |
flag is true if type should be root of generic subtree More... | |
TypeHash | generic_type_hash_ |
hash string of generic type if type is derived, or empty string More... | |
ParameterMap | parameter_map_ |
map of parameters if type is part of generic subtree More... | |
Template for classes storing finite set of named values.
The primary purpose of this class is initialization of enum variables. Since C++ provides no reflection, in particular no access to enum identifiers as strings, you has to construct the Selection object consistent with an enum you want to initialize.
Similarly to Type::Record and Type::Abstract the Selection class is only proxy to the actual data.
Usage:
TODO: We can not guarantee full compatibility of the Selection with corresponding Enum type the Selection can have fewer values since we can not get number of values in the Enum. Therefore we either have to move under C++11, where enum classes may provide elementary reflection or have Selection of simple ints.
Definition at line 65 of file type_selection.hh.
typedef std::vector<struct Key>::const_iterator Input::Type::Selection::keys_const_iterator |
Public typedef of constant iterator into array of keys.
Definition at line 89 of file type_selection.hh.
Input::Type::Selection::Selection | ( | ) |
Default constructor. Empty selection.
Definition at line 27 of file type_selection.cc.
Input::Type::Selection::Selection | ( | const Selection & | other | ) |
Copy constructor.
Definition at line 36 of file type_selection.cc.
Input::Type::Selection::Selection | ( | const string & | name, |
const std::string & | description = "" |
||
) |
Creates a handle pointing to the new SelectionData.
Selection & Input::Type::Selection::add_attribute | ( | std::string | key, |
TypeBase::json_string | value | ||
) |
Definition at line 59 of file type_selection.cc.
Selection & Input::Type::Selection::add_value | ( | const int | value, |
const std::string & | key, | ||
const std::string & | description = "" , |
||
TypeBase::attribute_map | attributes = TypeBase::attribute_map() |
||
) |
Adds one new value
with name given by key
to the Selection.
The description
of meaning of the value could be provided.
Definition at line 50 of file type_selection.cc.
|
inline |
Container-like access to the keys of the Selection.
Returns iterator to the first key.
Definition at line 291 of file type_selection.hh.
|
overridevirtual |
Override Type::TypeBase::class_name
.
Reimplemented from Input::Type::TypeBase.
Definition at line 119 of file type_selection.cc.
const Selection & Input::Type::Selection::close | ( | ) | const |
Close the Selection, no more values can be added.
Definition at line 65 of file type_selection.cc.
|
overridevirtual |
Implements TypeBase::content_hash
.
Hash is calculated by type name, description, hash of keys and attributes.
Implements Input::Type::TypeBase.
Definition at line 84 of file type_selection.cc.
Copy all keys and values from sel
.
Definition at line 151 of file type_selection.cc.
Input::Type::Selection::DECLARE_EXCEPTION | ( | ExcSelectionKeyNotFound | , |
<< "Key "<< EI_KeyName::qval<<" not found in Selection:\n"<< EI_Selection::val | |||
) |
Input::Type::Selection::DECLARE_EXCEPTION | ( | ExcSelectionValueNotFound | , |
<< "Value "<< EI_Value::val<<" not found in Selection:\n"<< EI_Selection::val | |||
) |
|
inline |
Container-like access to the keys of the Selection.
Returns iterator to the last key.
Definition at line 299 of file type_selection.hh.
|
overridevirtual |
Finish declaration of the Selection type.
Reimplemented from Input::Type::TypeBase.
Definition at line 71 of file type_selection.cc.
|
overridevirtual |
Implements TypeBase::finish_status
.
Reimplemented from Input::Type::TypeBase.
Definition at line 100 of file type_selection.cc.
|
inlineprivate |
Assertion for finished Selection (methods are called in correct order).
Definition at line 285 of file type_selection.hh.
|
inline |
Just check if there is a particular name in the Selection.
Definition at line 261 of file type_selection.hh.
|
inline |
Check if there is a particular value in the Selection.
Definition at line 269 of file type_selection.hh.
string Input::Type::Selection::int_to_name | ( | const int & | value | ) | const |
Returns value name for the given value
.
Throws exception if the value does not exist.
Definition at line 141 of file type_selection.cc.
|
overridevirtual |
Implements TypeBase::is_closed
.
Reimplemented from Input::Type::TypeBase.
Definition at line 110 of file type_selection.cc.
|
overridevirtual |
Implements TypeBase::is_finished
.
Reimplemented from Input::Type::TypeBase.
Definition at line 105 of file type_selection.cc.
|
inline |
Returns iterator to the key struct for given key string.
Definition at line 306 of file type_selection.hh.
|
private |
Create string from values of keys.
Used in error messaged, where we can not use desc(), which can lead to infinite loop due to TYPE selection of Abstract.
Definition at line 165 of file type_selection.cc.
|
override |
Definition at line 174 of file type_selection.cc.
int Input::Type::Selection::name_to_int | ( | const string & | key | ) | const |
Converts given value name key
to the value.
Throws exception if the value name does not exist.
Definition at line 130 of file type_selection.cc.
|
overridevirtual |
Implements TypeBase::operator==
compare also Selection names.
Reimplemented from Input::Type::TypeBase.
Definition at line 124 of file type_selection.cc.
|
inline |
Returns number of values in the Selection.
Definition at line 276 of file type_selection.hh.
|
overridevirtual |
Implements Type::TypeBase::type_name
.
Name corresponds to data->type_name_
.
Reimplemented from Input::Type::TypeBase.
Definition at line 114 of file type_selection.cc.
Input::Type::Selection::TYPEDEF_ERR_INFO | ( | EI_Selection | , |
const Selection | |||
) |
Input::Type::Selection::TYPEDEF_ERR_INFO | ( | EI_Value | , |
const int | |||
) |
|
friend |
Definition at line 66 of file type_selection.hh.
|
private |
Handle to actual Selection data.
Definition at line 249 of file type_selection.hh.