Flow123d  jenkins-Flow123d-linux-release-multijob-282
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
Input::Type::Selection Class Reference

Template for classes storing finite set of named values. More...

#include <type_selection.hh>

Inheritance diagram for Input::Type::Selection:
Inheritance graph
[legend]
Collaboration diagram for Input::Type::Selection:
Collaboration graph
[legend]

Classes

struct  Key
 
class  SelectionData
 

Public Types

typedef std::vector< struct
Key >::const_iterator 
keys_const_iterator
 

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 ()
 
 Selection (const Selection &other)
 
 Selection (const string &name, const std::string &description="")
 
Selectionadd_value (const int value, const std::string &key, const std::string &description="")
 
const Selectionclose () const
 
std::size_t content_hash () const override
 
virtual bool is_finished () const
 Implements TypeBase::is_finished. More...
 
virtual string type_name () const
 Implements TypeBase::type_name. More...
 
virtual string full_type_name () const
 Implements TypeBase::full_type_name. More...
 
virtual bool operator== (const TypeBase &other) const
 Implements TypeBase::operator== compare also Selection names. More...
 
keys_const_iterator begin () const
 
keys_const_iterator end () const
 
keys_const_iterator key_iterator (const string &key) const
 
int name_to_int (const string &key) const
 
string int_to_name (const int &value) const
 
Selectioncopy_values (const Selection &sel)
 
int from_default (const string &str) const
 
virtual bool valid_default (const string &str) const
 Implements Type::TypeBase::valid_defaults. More...
 
bool has_name (const string &key) const
 
bool has_value (const int &val) const
 
unsigned int size () const
 
bool finish ()
 
- Public Member Functions inherited from Input::Type::TypeBase
string desc () const
 
bool operator!= (const TypeBase &other) const
 Comparison of types. More...
 
virtual ~TypeBase ()
 

Private Member Functions

void finished_check () const
 
string key_list () const
 

Private Attributes

boost::shared_ptr< SelectionDatadata_
 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 registered lazy types. More...
 
- Protected Types inherited from Input::Type::TypeBase
typedef string KeyHash
 
typedef std::vector
< boost::shared_ptr< TypeBase > > 
LazyTypeVector
 
typedef std::set< const
TypeBase * > 
LazyObjectsSet
 
- Protected Member Functions inherited from Input::Type::TypeBase
 TypeBase ()
 
 TypeBase (const TypeBase &other)
 
- 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)
 
static LazyTypeVectorlazy_type_list ()
 
static LazyObjectsSetlazy_object_set ()
 
static bool was_constructed (const TypeBase *ptr)
 

Detailed Description

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::AbstractRecord the Selection class is only proxy to the actual data.

Usage:

enum Colors { blue, white };
Selection colors("Colors");
colors.add_value(blue, "blue");
colors.add_value(white,"white","White color"); // with optional item description
colors.finish();

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 50 of file type_selection.hh.

Member Typedef Documentation

Public typedef of constant iterator into array of keys

Definition at line 77 of file type_selection.hh.

Constructor & Destructor Documentation

Input::Type::Selection::Selection ( )

Default constructor. Empty selection.

Definition at line 16 of file type_selection.cc.

Input::Type::Selection::Selection ( const Selection other)

Copy constructor.

Definition at line 24 of file type_selection.cc.

Input::Type::Selection::Selection ( const string &  name,
const std::string &  description = "" 
)

Creates a handle pointing to the new SelectionData.

Member Function Documentation

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

Here is the caller graph for this function:

Selection::keys_const_iterator Input::Type::Selection::begin ( ) const
inline

Container-like access to the keys of the Record. Returns iterator to the first key.

Definition at line 266 of file type_selection.hh.

Here is the caller graph for this function:

const Selection & Input::Type::Selection::close ( ) const

Close the Selection, no more values can be added.

Definition at line 50 of file type_selection.cc.

Here is the caller graph for this function:

std::size_t Input::Type::Selection::content_hash ( ) const
overridevirtual

Hash of the type specification. Provides unique id computed from its content (definition) so that same types have same hash.

Implements Input::Type::TypeBase.

Definition at line 57 of file type_selection.cc.

Here is the caller graph for this function:

Selection & Input::Type::Selection::copy_values ( const Selection sel)

Definition at line 123 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   
)
Selection::keys_const_iterator Input::Type::Selection::end ( ) const
inline

Container-like access to the keys of the Record. Returns iterator to the last key.

Definition at line 274 of file type_selection.hh.

Here is the caller graph for this function:

bool Input::Type::Selection::finish ( )
inlinevirtual

Finish method. Finalize construction of "Lazy types": Record, Selection, AbstractRecord, and Array. These input types are typically defined by means of static variables, whose order of initialization is not known a priori. Since e.g. a Record can link to other input types through its keys, these input types cannot be accessed directly at the initialization phase. The remaining part of initialization can be done later, typically from main(), by calling the method finish().

Finish try to convert all raw pointers pointing to lazy types into smart pointers to valid objects. If there are still raw pointers to not constructed objects the method returns false.

Reimplemented from Input::Type::TypeBase.

Definition at line 173 of file type_selection.hh.

void Input::Type::Selection::finished_check ( ) const
inlineprivate

Assertion for finished Selection (methods are called in correct order).

Definition at line 260 of file type_selection.hh.

Here is the caller graph for this function:

int Input::Type::Selection::from_default ( const string &  str) const

Same as Selection::name_to_int, but throws different exception, when string comes from default value.

Definition at line 137 of file type_selection.cc.

string Input::Type::Selection::full_type_name ( ) const
virtual

Implements TypeBase::full_type_name.

Reimplemented from Input::Type::Scalar.

Definition at line 90 of file type_selection.cc.

Here is the caller graph for this function:

bool Input::Type::Selection::has_name ( const string &  key) const
inline

Just check if there is a particular name in the Selection.

Definition at line 234 of file type_selection.hh.

Here is the caller graph for this function:

bool Input::Type::Selection::has_value ( const int &  val) const
inline

Check if there is a particular value in the Selection.

Definition at line 242 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 113 of file type_selection.cc.

Here is the caller graph for this function:

bool Input::Type::Selection::is_finished ( ) const
virtual

Implements TypeBase::is_finished.

Reimplemented from Input::Type::TypeBase.

Definition at line 80 of file type_selection.cc.

Here is the caller graph for this function:

Selection::keys_const_iterator Input::Type::Selection::key_iterator ( const string &  key) const
inline

Returns iterator to the key struct for given key string.

Definition at line 281 of file type_selection.hh.

string Input::Type::Selection::key_list ( ) const
private

Used in error messaged, where we can not use desc(), which can lead to infinite loop due to TYPE selection of AbstractRecord.

Definition at line 147 of file type_selection.cc.

Here is the caller graph for this function:

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

Here is the caller graph for this function:

bool Input::Type::Selection::operator== ( const TypeBase other) const
virtual

Implements TypeBase::operator== compare also Selection names.

Reimplemented from Input::Type::TypeBase.

Definition at line 96 of file type_selection.cc.

unsigned int Input::Type::Selection::size ( ) const
inline

Returns number of values in the Selection.

Definition at line 249 of file type_selection.hh.

Here is the caller graph for this function:

string Input::Type::Selection::type_name ( ) const
virtual

Implements TypeBase::type_name.

Reimplemented from Input::Type::TypeBase.

Definition at line 85 of file type_selection.cc.

Here is the caller graph for this function:

Input::Type::Selection::TYPEDEF_ERR_INFO ( EI_Selection  ,
const Selection   
)
Input::Type::Selection::TYPEDEF_ERR_INFO ( EI_Value  ,
const int   
)
bool Input::Type::Selection::valid_default ( const string &  str) const
virtual

Implements Type::TypeBase::valid_defaults.

Implements Input::Type::TypeBase.

Definition at line 73 of file type_selection.cc.

Friends And Related Function Documentation

friend class OutputBase
friend

Definition at line 51 of file type_selection.hh.

Member Data Documentation

boost::shared_ptr<SelectionData> Input::Type::Selection::data_
private

Handle to actual Selection data.

Definition at line 222 of file type_selection.hh.


The documentation for this class was generated from the following files: