Flow123d  JS_before_hm-883-gc471082
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 292 of file accessors.hh.

Member Typedef Documentation

Definition at line 295 of file accessors.hh.

Constructor & Destructor Documentation

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.

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

Copy constructor.

Definition at line 164 of file accessors.cc.

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

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:

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:

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.

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:

string Input::Record::input_type_name ( )
virtual

Get name of record_type_

Reimplemented in Input::Tuple.

Definition at line 189 of file accessors.cc.

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 366 of file accessors.hh.

Here is the caller graph for this function:

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:

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

Set address (currently necessary for creating root accessor)

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.

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

friend class AbstractRecord
friend

Definition at line 402 of file accessors.hh.

friend class ReaderToStorage
friend

Definition at line 391 of file accessors.hh.

Member Data Documentation

Address Input::Record::address_
protected

Contains address and relationships with record ancestor.

Definition at line 397 of file accessors.hh.

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

Corresponding Type::Record object.

Definition at line 401 of file accessors.hh.


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