|
Flow123d
last_with_con_2.0.0-2-g938dee8
|
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="") |
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... | |
| 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... | |
| bool | finish (bool is_generic=false) 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 | lazy_finish () |
| Finishes all types registered in type repositories. More... | |
| static std::string | hash_str (TypeHash hash) |
| Format given hash for output. More... | |
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 63 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 86 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 35 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 56 of file type_selection.cc.
| Selection & Input::Type::Selection::add_value | ( | const int | value, |
| const std::string & | key, | ||
| const std::string & | description = "" |
||
| ) |
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 49 of file type_selection.cc.

|
inline |
Container-like access to the keys of the Selection.
Returns iterator to the first key.
Definition at line 283 of file type_selection.hh.

|
inlineoverridevirtual |
Override Type::TypeBase::class_name.
Reimplemented from Input::Type::TypeBase.
Definition at line 129 of file type_selection.hh.
| const Selection & Input::Type::Selection::close | ( | ) | const |
Close the Selection, no more values can be added.
Definition at line 62 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 71 of file type_selection.cc.

Copy all keys and values from sel.
Definition at line 129 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 291 of file type_selection.hh.

|
inlineoverridevirtual |
Finish declaration of the Selection type.
Reimplemented from Input::Type::TypeBase.
Definition at line 178 of file type_selection.hh.
|
inlineprivate |
Assertion for finished Selection (methods are called in correct order).
Definition at line 277 of file type_selection.hh.

|
inline |
Just check if there is a particular name in the Selection.
Definition at line 253 of file type_selection.hh.

|
inline |
Check if there is a particular value in the Selection.
Definition at line 261 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 119 of file type_selection.cc.

|
overridevirtual |
Implements TypeBase::is_closed.
Reimplemented from Input::Type::TypeBase.
Definition at line 92 of file type_selection.cc.

|
overridevirtual |
Implements TypeBase::is_finished.
Reimplemented from Input::Type::TypeBase.
Definition at line 87 of file type_selection.cc.

|
inline |
Returns iterator to the key struct for given key string.
Definition at line 298 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 143 of file type_selection.cc.

|
override |
| 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 108 of file type_selection.cc.

|
overridevirtual |
Implements TypeBase::operator== compare also Selection names.
Reimplemented from Input::Type::TypeBase.
Definition at line 102 of file type_selection.cc.

|
inline |
Returns number of values in the Selection.
Definition at line 268 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 96 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 64 of file type_selection.hh.
|
private |
Handle to actual Selection data.
Definition at line 241 of file type_selection.hh.
1.8.11