Flow123d  master-92884d111
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | Friends | List of all members
Input::Record Class Reference

Accessor to the data with type Type::Record. More...

#include <accessors.hh>

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

Public Types

typedef ::Input::Type::Record InputType
 

Public Member Functions

 Record ()
 
 Record (const Record &rec)
 
 Record (const Address &address, const Type::Record type)
 
template<class Ret >
const Ret val (const string &key) const
 
template<class Ret >
const Ret val (const string &key, const Ret default_val) const
 
template<class Ret >
Iterator< Ret > find (const string &key) const
 
template<class Ret >
bool opt_val (const string &key, Ret &value) const
 
bool is_empty () const
 
EI_Address ei_address () const
 
string address_string () const
 
virtual string input_type_name ()
 

Protected Member Functions

void set_address (const Address &address)
 
virtual Type::Record::KeyIter get_type_key_iterator (const string &key) const
 Return iterator to Type::Record key of given name. More...
 

Protected Attributes

Address address_
 Contains address and relationships with record ancestor. More...
 

Private Attributes

Input::Type::Record record_type_
 Corresponding Type::Record object. More...
 

Friends

class ReaderToStorage
 
class AbstractRecord
 

Detailed Description

Accessor to the data with type Type::Record.

This class provides access to the data through names – key of the data fields. It merge information from a Type::Record object, which describes valid keys and their types, and reference into a StorageBase that provides access to actual values.

The keys that are obligatory or has specified default value can be read either by the method template val<OutputType> which returns the value of type OutputType that should be compatible with declared type (i.e. you can get unsigned int from an input value of type Type:Integer, but not from an input value of type Type::String).

The keys which are optional and has no default value you has to use the method template find<OutputType> that returns an iterator to the type OutputType, which is invalid if the value is missing on the input and no the default string is provided.

Usage:

using namespace Input;
Record record = some_other_record.val<Record>("output_format");
// reading an obligatory key or key with default value
int n_digis = record.val<int>("number_of_substances");
// reading an optional key
Iterator<Array> it = record.find<Array>("substances_names");
if ( it ) {
it->copy_to( list_of_names );
} else {
// generic names of substances
}

Definition at line 291 of file accessors.hh.

Member Typedef Documentation

◆ InputType

Definition at line 294 of file accessors.hh.

Constructor & Destructor Documentation

◆ Record() [1/3]

Input::Record::Record ( )

Default constructor.

Constructor uses empty Address which causes error in program, Address has to be filled.

Definition at line 158 of file accessors.cc.

◆ Record() [2/3]

Input::Record::Record ( const Record rec)

Copy constructor.

Definition at line 164 of file accessors.cc.

◆ Record() [3/3]

Input::Record::Record ( const Address address,
const Type::Record  type 
)

Constructs the accessor providing pointer store to storage node with list of data of the record and type specification of the record given by parameter type.

Definition at line 170 of file accessors.cc.

Member Function Documentation

◆ address_string()

string Input::Record::address_string ( ) const

Get address as string.

Definition at line 184 of file accessors.cc.

Here is the caller graph for this function:

◆ ei_address()

Input::EI_Address Input::Record::ei_address ( ) const

Returns address error info.

Definition at line 178 of file accessors.cc.

Here is the caller graph for this function:

◆ find()

template<class Ret >
Iterator< Ret > Input::Record::find ( const string &  key) const
inline

Returns iterator to the key if it exists or NULL Iterator if it doesn't. This method must be used for keys which are optional or has default value provided at read time.

Definition at line 91 of file accessors_impl.hh.

Here is the caller graph for this function:

◆ get_type_key_iterator()

Type::Record::KeyIter Input::Record::get_type_key_iterator ( const string &  key) const
protectedvirtual

Return iterator to Type::Record key of given name.

Reimplemented in Input::Tuple.

Definition at line 195 of file accessors.cc.

Here is the caller graph for this function:

◆ input_type_name()

string Input::Record::input_type_name ( )
virtual

Get name of record_type_

Reimplemented in Input::Tuple.

Definition at line 189 of file accessors.cc.

◆ is_empty()

bool Input::Record::is_empty ( ) const
inline

Returns true if the accessor is empty (after default constructor). TODO: have something similar for other accessors.

Definition at line 365 of file accessors.hh.

Here is the caller graph for this function:

◆ opt_val()

template<class Ret >
bool Input::Record::opt_val ( const string &  key,
Ret &  value 
) const
inline

This has similar function as the previous method, but simpler usage in some cases. You has to provide reference to the variable value where the value of an optional key should be placed. If the key in not present in the input the value of value is not changed and the method returns false. If the key has a value the method returns true. Typical usage:

double param;
string other_param;
if (rec.opt_val("optional_param", param) ) {
use_param(param);
} else if (rec.opt_val("other_param", other_param) ) {
use_other_param(other_param);
} else {
... error, no value for param
}

Definition at line 107 of file accessors_impl.hh.

Here is the caller graph for this function:

◆ set_address()

void Input::Record::set_address ( const Address address)
protected

Set address (currently necessary for creating root accessor)

◆ val() [1/2]

template<class Ret >
const Ret Input::Record::val ( const string &  key) const
inline

Returns value of given key if the declared key type (descendant of Input:Type:TypeBase) is convertible to the C++ class type given as the template parameter. If the key has no defined value (either from input or a declared default value) it throws an exception. It throws also, if the declared type do not match desired C++ type.

This method can be used only for keys which are obligatory or has default value given at declaration. The optional keys must use method find. Keys with default value at read time must use the overloaded variant of method val or the method find

Definition at line 31 of file accessors_impl.hh.

◆ val() [2/2]

template<class Ret >
const Ret Input::Record::val ( const string &  key,
const Ret  default_val 
) const
inline

Same as the previous, but you can specify default value default_val that is used if the key is not specified at the input. This method can be used only for keys declared with Default::reat_time().

Definition at line 60 of file accessors_impl.hh.

Friends And Related Function Documentation

◆ AbstractRecord

friend class AbstractRecord
friend

Definition at line 401 of file accessors.hh.

◆ ReaderToStorage

friend class ReaderToStorage
friend

Definition at line 390 of file accessors.hh.

Member Data Documentation

◆ address_

Address Input::Record::address_
protected

Contains address and relationships with record ancestor.

Definition at line 396 of file accessors.hh.

◆ record_type_

Input::Type::Record Input::Record::record_type_
private

Corresponding Type::Record object.

Definition at line 400 of file accessors.hh.


The documentation for this class was generated from the following files:
Input
Abstract linear system class.
Definition: balance.hh:40
value
static constexpr bool value
Definition: json.hpp:87
Input::Iterator
Definition: accessors.hh:143
Input::Type
Definition: balance.hh:41
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
Input::Type::Array
Class for declaration of inputs sequences.
Definition: type_base.hh:339