Flow123d  release_2.2.0-914-gf1a3a4f
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Input::Type::Record Class Reference

Record type proxy class. More...

#include <type_record.hh>

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

Classes

struct  Key
 Structure for description of one key in record. More...
 
class  RecordData
 Internal data class. More...
 

Public Types

typedef std::vector< struct Key >::const_iterator KeyIter
 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_stringattribute_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< ParameterPairParameterVector
 Define vector of parameters passed to the overloaded make_instance method. More...
 
typedef std::map< std::string, TypeHashParameterMap
 Defines map of used parameters. More...
 
typedef std::pair< std::shared_ptr< TypeBase >, ParameterMapMakeInstanceReturnType
 Return type of make_instance methods, contains instance of generic type and map of used parameters. More...
 

Public Member Functions

 TYPEDEF_ERR_INFO (EI_Record, Record)
 
 TYPEDEF_ERR_INFO (EI_RecordName, const string)
 
 DECLARE_EXCEPTION (ExcRecordKeyNotFound,<< "Key "<< EI_KeyName::qval<<" not found in Record:\n"<< EI_Record::val)
 
 Record ()
 Default constructor. Empty handle. More...
 
 Record (const Record &other)
 Copy constructor. More...
 
 Record (const string &type_name_in, const string &description)
 Basic constructor. More...
 
virtual TypeHash content_hash () const override
 Implements TypeBase::content_hash. More...
 
virtual Recordderive_from (Abstract &parent)
 Method to derive new Record from an AbstractRecord parent. More...
 
Recordcopy_keys (const Record &other)
 Copy keys from other record. More...
 
virtual Recordallow_auto_conversion (const string &from_key)
 Allows shorter input of the Record providing only value of the from_key given as the parameter. More...
 
Recorddeclare_key (const string &key, std::shared_ptr< TypeBase > type, const Default &default_value, const string &description, TypeBase::attribute_map key_attributes=TypeBase::attribute_map())
 Declares a new key of the Record. More...
 
template<class KeyType >
Recorddeclare_key (const string &key, const KeyType &type, const Default &default_value, const string &description, TypeBase::attribute_map key_attributes=TypeBase::attribute_map())
 Declares a new key of the Record. More...
 
template<class KeyType >
Recorddeclare_key (const string &key, const KeyType &type, const string &description, TypeBase::attribute_map key_attributes=TypeBase::attribute_map())
 Declares a new key of the Record. More...
 
Recordclose () const
 Close the Record for further declarations of keys. More...
 
FinishStatus finish_status () const override
 Implements TypeBase::finish_status. More...
 
bool is_finished () const override
 Implements TypeBase::is_finished. More...
 
bool is_closed () const override
 Returns true if data_ is closed. More...
 
string type_name () const override
 Implements Type::TypeBase::type_name. More...
 
virtual string class_name () const override
 Override Type::TypeBase::class_name. More...
 
bool operator== (const TypeBase &other) const override
 Class comparison and Record type name comparision. More...
 
unsigned int key_index (const string &key) const
 Interface to mapping key -> index in record. More...
 
KeyIter key_iterator (const string &key) const
 Returns iterator to the key struct for given key string. More...
 
KeyIter auto_conversion_key_iter () const
 Returns iterator to auto-conversion key. More...
 
bool has_key_iterator (const string &key, KeyIter &it) const
 Returns iterator to the key struct for given key string. More...
 
KeyIter begin () const
 Container-like access to the keys of the Record. More...
 
KeyIter end () const
 Container-like access to the keys of the Record. More...
 
bool has_key (const string &key) const
 Returns true if the Record contains key with given name. More...
 
unsigned int size () const
 Returns number of keys in the Record. More...
 
FinishStatus finish (FinishStatus finish_type=FinishStatus::regular_) override
 Finish declaration of the Record type. More...
 
Recordadd_attribute (std::string key, TypeBase::json_string value)
 Add TYPE key as obligatory. More...
 
virtual MakeInstanceReturnType make_instance (std::vector< ParameterPair > vec=std::vector< ParameterPair >()) override
 Implements TypeBase::make_instance. More...
 
Record deep_copy () const
 Create deep copy of Record (copy all data stored in shared pointers etc.) More...
 
virtual Recordroot_of_generic_subtree ()
 
- 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...
 

Protected Member Functions

void finished_check () const
 Assertion for finished Type::Record. More...
 
void make_copy_keys (Record &origin)
 Auxiliary method that actually makes the copy of keys. More...
 
void set_instance_data (Record &rec, ParameterMap &parameter_map, std::vector< ParameterPair > vec)
 Declares a TYPE key of the Record. 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)
 

Protected Attributes

std::shared_ptr< RecordDatadata_
 Data handle. More...
 
- Protected Attributes inherited from Input::Type::TypeBase
std::shared_ptr< attribute_mapattributes_
 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...
 

Friends

class OutputBase
 
class Abstract
 

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...
 
- 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...
 
- 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...
 

Detailed Description

Record type proxy class.


To keep consistency, we have to prevent copies of the actual Record data. Therefore this class is just a proxy that can be freely (and cheaply) copied.

Definition at line 182 of file type_record.hh.

Member Typedef Documentation

typedef std::vector<struct Key>::const_iterator Input::Type::Record::KeyIter

Public typedef of constant iterator into array of keys.

Definition at line 216 of file type_record.hh.

Constructor & Destructor Documentation

Input::Type::Record::Record ( )

Default constructor. Empty handle.

Definition at line 99 of file type_record.cc.

Here is the caller graph for this function:

Input::Type::Record::Record ( const Record other)

Copy constructor.

We allow only copies of non-empty records.

Definition at line 108 of file type_record.cc.

Input::Type::Record::Record ( const string &  type_name_in,
const string &  description 
)

Basic constructor.

You have to provide type_name of the new declared Record type and its description.

Definition at line 114 of file type_record.cc.

Member Function Documentation

Record & Input::Type::Record::add_attribute ( std::string  key,
TypeBase::json_string  value 
)

Add TYPE key as obligatory.

This method can't be used for derived record.

Definition at line 352 of file type_record.cc.

Here is the caller graph for this function:

Record & Input::Type::Record::allow_auto_conversion ( const string &  from_key)
virtual

Allows shorter input of the Record providing only value of the from_key given as the parameter.

All other keys of the Record must have default values specified at declaration. This is checked when the finish method is called.

If the input reader come across the Record in declaration tree, but there is not 'record-like' input, it save default values into storage tree and tries to match the input with the type of the from_key.

Reimplemented in Input::Type::Tuple.

Definition at line 132 of file type_record.cc.

Here is the caller graph for this function:

Record::KeyIter Input::Type::Record::auto_conversion_key_iter ( ) const

Returns iterator to auto-conversion key.

See Record::allow_auto_conversion. If the auto conversion is not allowed, returns end().

Definition at line 333 of file type_record.cc.

Here is the caller graph for this function:

Record::KeyIter Input::Type::Record::begin ( ) const
inline

Container-like access to the keys of the Record.

Returns iterator to the first key.

Definition at line 575 of file type_record.hh.

Here is the caller graph for this function:

string Input::Type::Record::class_name ( ) const
overridevirtual

Override Type::TypeBase::class_name.

Reimplemented from Input::Type::TypeBase.

Reimplemented in Input::Type::Tuple.

Definition at line 321 of file type_record.cc.

Here is the caller graph for this function:

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

Close the Record for further declarations of keys.

Adds Record to type repository (see TypeRepository::add_type) and provides correct bindings between parent Abstract and child Record if Record is derived from one or more Abstracts.

Mechanism of set parent to derived Record and child to parent Abstract is provided with Abstract::add_child method.

See also derive_from and Abstract::add_child methods

Definition at line 303 of file type_record.cc.

TypeBase::TypeHash Input::Type::Record::content_hash ( ) const
overridevirtual

Implements TypeBase::content_hash.

Hash is calculated by type name, description, auto conversion key, hash of keys and attributes.

Implements Input::Type::TypeBase.

Reimplemented in Input::Type::Tuple.

Definition at line 122 of file type_record.cc.

Here is the caller graph for this function:

Record & Input::Type::Record::copy_keys ( const Record other)

Copy keys from other record.

Record other must be closed.

Definition at line 215 of file type_record.cc.

Here is the caller graph for this function:

Input::Type::Record::DECLARE_EXCEPTION ( ExcRecordKeyNotFound  ,
<< "Key "<< EI_KeyName::qval<<" not found in Record:\n"<< EI_Record::val   
)
Record & Input::Type::Record::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() 
)

Declares a new key of the Record.

Key has name given by parameter key, the type given by target of pointer type, default value by parameter default_value, and with given description. The parameter type points to a descendant of TypeBase.

The optional attributes map may be provided, e.g.:

declare_key("old_key", ..., { {Attribute::obsolete(), "Replaced by 'new_key'."} } )

Definition at line 490 of file type_record.cc.

template<class KeyType >
Record & Input::Type::Record::declare_key ( const string &  key,
const KeyType &  type,
const Default default_value,
const string &  description,
TypeBase::attribute_map  key_attributes = TypeBase::attribute_map() 
)

Declares a new key of the Record.

Key has name given by parameter key, the type given by parameter type, default value by parameter default_value, and with given description. The parameter type has a descendant of TypeBase.

Definition at line 500 of file type_record.cc.

template<class KeyType >
Record & Input::Type::Record::declare_key ( const string &  key,
const KeyType &  type,
const string &  description,
TypeBase::attribute_map  key_attributes = TypeBase::attribute_map() 
)

Declares a new key of the Record.

Same as previous method but without given default value (same as Default() - optional key )

Definition at line 514 of file type_record.cc.

Record Input::Type::Record::deep_copy ( ) const

Create deep copy of Record (copy all data stored in shared pointers etc.)

Definition at line 385 of file type_record.cc.

Here is the caller graph for this function:

Record & Input::Type::Record::derive_from ( Abstract parent)
virtual

Method to derive new Record from an AbstractRecord parent.

This register the parent to Record. Method checks if TYPE key of Record exists and ensures that Record has assigned one parent only once.

Usage of this method:

  • during creating Record before its closing (optional usage but recommended for better clarity)
  • in Abstract::add_child provides bilateral binding between parent and child

See also close and Abstract::add_child methods

Reimplemented in Input::Type::Tuple.

Definition at line 195 of file type_record.cc.

Record::KeyIter Input::Type::Record::end ( ) const
inline

Container-like access to the keys of the Record.

Returns iterator to the last key.

Definition at line 583 of file type_record.hh.

Here is the caller graph for this function:

FinishStatus Input::Type::Record::finish ( FinishStatus  finish_type = FinishStatus::regular_)
overridevirtual

Finish declaration of the Record type.

Checks if Record is closed and completes Record (check auto convertible key, parameters of generic types etc).

Reimplemented from Input::Type::TypeBase.

Reimplemented in Input::Type::Tuple.

Definition at line 242 of file type_record.cc.

Here is the caller graph for this function:

FinishStatus Input::Type::Record::finish_status ( ) const
overridevirtual

Implements TypeBase::finish_status.

Reimplemented from Input::Type::TypeBase.

Definition at line 225 of file type_record.cc.

void Input::Type::Record::finished_check ( ) const
inlineprotected

Assertion for finished Type::Record.

Definition at line 428 of file type_record.hh.

Here is the caller graph for this function:

bool Input::Type::Record::has_key ( const string &  key) const
inline

Returns true if the Record contains key with given name.

Definition at line 591 of file type_record.hh.

bool Input::Type::Record::has_key_iterator ( const string &  key,
KeyIter it 
) const
inline

Returns iterator to the key struct for given key string.

Definition at line 560 of file type_record.hh.

bool Input::Type::Record::is_closed ( ) const
overridevirtual

Returns true if data_ is closed.

Reimplemented from Input::Type::TypeBase.

Definition at line 235 of file type_record.cc.

Here is the caller graph for this function:

bool Input::Type::Record::is_finished ( ) const
overridevirtual

Implements TypeBase::is_finished.

Reimplemented from Input::Type::TypeBase.

Definition at line 230 of file type_record.cc.

Here is the caller graph for this function:

unsigned int Input::Type::Record::key_index ( const string &  key) const
inline

Interface to mapping key -> index in record.

Returns index (in continuous array) for given key.

Works also for unfinished Record.

Definition at line 538 of file type_record.hh.

Here is the caller graph for this function:

Record::KeyIter Input::Type::Record::key_iterator ( const string &  key) const
inline

Returns iterator to the key struct for given key string.

Definition at line 551 of file type_record.hh.

Here is the caller graph for this function:

void Input::Type::Record::make_copy_keys ( Record origin)
protected

Auxiliary method that actually makes the copy of keys.

Definition at line 142 of file type_record.cc.

Here is the caller graph for this function:

TypeBase::MakeInstanceReturnType Input::Type::Record::make_instance ( std::vector< ParameterPair vec = std::vector<ParameterPair>())
overridevirtual

Implements TypeBase::make_instance.

Reimplemented in Input::Type::Tuple.

Definition at line 358 of file type_record.cc.

bool Input::Type::Record::operator== ( const TypeBase other) const
overridevirtual

Class comparison and Record type name comparision.

Reimplemented from Input::Type::TypeBase.

Reimplemented in Input::Type::Tuple.

Definition at line 327 of file type_record.cc.

Record & Input::Type::Record::root_of_generic_subtree ( )
virtual

Mark the type to be root of a generic subtree. Such type can not appear in IST directly but only as the internal type of the Instance auxiliary object.

Reimplemented in Input::Type::Tuple.

Definition at line 419 of file type_record.cc.

Here is the caller graph for this function:

void Input::Type::Record::set_instance_data ( Record rec,
ParameterMap parameter_map,
std::vector< ParameterPair vec 
)
protected

Declares a TYPE key of the Record.

TYPE key must be declared as first key of Record. Set parent Abstract of Record.

This method is created for correct functionality of generic types. It must be called in Abstract::finish() and refill parent_vec_ vector of correct parents (for complete mechanism of set parent and descendant see derive_from) Set data of Instance of generic type.

Called from make_instance method and set data of Record or its descendants.

Definition at line 367 of file type_record.cc.

Here is the caller graph for this function:

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

Returns number of keys in the Record.

Definition at line 598 of file type_record.hh.

string Input::Type::Record::type_name ( ) const
overridevirtual

Implements Type::TypeBase::type_name.

Name corresponds to data->type_name_.

Reimplemented from Input::Type::TypeBase.

Definition at line 315 of file type_record.cc.

Here is the caller graph for this function:

Input::Type::Record::TYPEDEF_ERR_INFO ( EI_Record  ,
Record   
)
Input::Type::Record::TYPEDEF_ERR_INFO ( EI_RecordName  ,
const string   
)

Friends And Related Function Documentation

friend class Abstract
friend

Definition at line 184 of file type_record.hh.

friend class OutputBase
friend

Definition at line 183 of file type_record.hh.

Member Data Documentation

std::shared_ptr<RecordData> Input::Type::Record::data_
protected

Data handle.

Definition at line 527 of file type_record.hh.


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