Flow123d  JS_before_hm-978-gf0793cd
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
Input::Type::TypeBase Class Referenceabstract

Base of classes for declaring structure of the input data. More...

#include <type_base.hh>

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

Public Types

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

virtual FinishStatus finish_status () const
 Returns true if the type is fully specified and ready for read access. More...
 
virtual bool is_finished () const
 
virtual bool is_closed () const
 Returns true if the type is closed. More...
 
virtual string type_name () const
 Returns an identification of the type. Useful for error messages. More...
 
virtual string class_name () const
 Returns an identification of the class. Useful for output of the documentation. More...
 
string desc () const
 Returns string with Type extensive documentation. More...
 
virtual bool operator== (const TypeBase &other) const
 Comparison of types. More...
 
bool operator!= (const TypeBase &other) const
 Comparison of types. More...
 
virtual ~TypeBase ()
 Destructor. More...
 
virtual FinishStatus finish (FinishStatus finish_type=FinishStatus::regular_)
 Finish method. Finalize construction of "Lazy types": Record, Selection, Abstract and generic type. More...
 
virtual TypeHash content_hash () const =0
 Hash of the type specification. 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 () const
 Indicates if type is marked with flag root_of_generic_subtree_. More...
 

Static Public Member Functions

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

Static Public Attributes

static const TypeHash none_hash = std::numeric_limits<TypeHash>::max()
 

Protected Types

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

 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

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

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 Array
 
class Record
 
class OutputBase
 

Detailed Description

Base of classes for declaring structure of the input data.

Provides methods and class members common to all types. Namely, the type name, finished status (nontrivial only for types with complex initialization - Record, AbstractRecosd, Selection), attributes, data of generic types and output of the documentation.

Definition at line 92 of file type_base.hh.

Member Typedef Documentation

Defines map of Input::Type attributes.

Definition at line 101 of file type_base.hh.

String stored in JSON format.

Definition at line 99 of file type_base.hh.

typedef string Input::Type::TypeBase::KeyHash
protected

The type of hash values used in associative array that translates key names to indices in Record and Selection.

For simplicity, we currently use whole strings as "hash".

Definition at line 258 of file type_base.hh.

Return type of make_instance methods, contains instance of generic type and map of used parameters.

Definition at line 111 of file type_base.hh.

Defines map of used parameters.

Definition at line 109 of file type_base.hh.

typedef std::pair< std::string, std::shared_ptr<TypeBase> > Input::Type::TypeBase::ParameterPair

Defines pairs of (name, Input::Type), that are used for replace of parameters in generic types.

Definition at line 104 of file type_base.hh.

Define vector of parameters passed to the overloaded make_instance method.

Definition at line 106 of file type_base.hh.

typedef std::size_t Input::Type::TypeBase::TypeHash

Type returned by content_hash methods.

Definition at line 95 of file type_base.hh.

Constructor & Destructor Documentation

Input::Type::TypeBase::~TypeBase ( )
virtual

Destructor.

Definition at line 90 of file type_base.cc.

Input::Type::TypeBase::TypeBase ( )
protected

The default constructor.

Definition at line 78 of file type_base.cc.

Input::Type::TypeBase::TypeBase ( const TypeBase other)
protected

Copy constructor.

Definition at line 84 of file type_base.cc.

Member Function Documentation

void Input::Type::TypeBase::add_attribute_ ( std::string  name,
json_string  val 
)
protected

Add attribute of given name to attribute map.

Parameter val must contain valid JSON string.

Definition at line 134 of file type_base.cc.

Here is the caller graph for this function:

string Input::Type::TypeBase::class_name ( ) const
virtual

Returns an identification of the class. Useful for output of the documentation.

Reimplemented in Input::Type::FileName, Input::Type::String, Input::Type::Double, Input::Type::Integer, Input::Type::Bool, Input::Type::Array, Input::Type::Record, Input::Type::AdHocAbstract, Input::Type::Abstract, Input::Type::Selection, Input::Type::Tuple, and Input::Type::Parameter.

Definition at line 211 of file type_base.cc.

Here is the caller graph for this function:

virtual TypeHash Input::Type::TypeBase::content_hash ( ) const
pure virtual

Hash of the type specification.

Provides unique id computed from its content (definition) so that same types have same hash.

Hash is counted using type, name and other class members specific for descendants.

Implemented in Input::Type::FileName, Input::Type::String, Input::Type::Double, Input::Type::Integer, Input::Type::Bool, Input::Type::Array, Input::Type::AdHocAbstract, Input::Type::Record, Input::Type::Abstract, Input::Type::Selection, Input::Type::Instance, Input::Type::Tuple, and Input::Type::Parameter.

Here is the caller graph for this function:

void Input::Type::TypeBase::copy_attributes ( attribute_map  other_attributes)
protected

Copy attributes to the instance of the generic type. Remove all internal attributes starting with '_'.

Definition at line 182 of file type_base.cc.

Here is the caller graph for this function:

void Input::Type::TypeBase::delete_unfinished_types ( )
static

Finishes and marks all types registered in type repositories and unused in IST.

Steps of this method: 1) finishes all types unused in IST, marks them as deleted (FinishStatus::deleted_) 2) iterates these deleted types once more, checks shared pointers link to Record keys, descendants of Abstract etc.

  • if count == 1, it's OK, method resets shared pointer
  • in other cases throws error

Definition at line 107 of file type_base.cc.

Here is the caller graph for this function:

string Input::Type::TypeBase::desc ( ) const

Returns string with Type extensive documentation.

We need this to pass Type description at throw points since the Type object can be deallocated during stack unrolling so it is not good idea to pass pointer. Maybe we can pass smart pointers. Actually this method is used in various exceptions in json_to_storage.

TODO: Some old note on this topic: !!! how to pass instance of descendant of TypeBase through EI -

  • can not pass it directly since TypeBase is not copyconstructable
  • can not use shared_ptr for same reason
  • can not use C pointers since the referred object can be temporary solutions:
    • consistently move TypeBase to Pimpl design
    • provide virtual function make_copy, that returns valid shared_ptr

Definition at line 99 of file type_base.cc.

Here is the caller graph for this function:

FinishStatus Input::Type::TypeBase::finish ( FinishStatus  finish_type = FinishStatus::regular_)
virtual

Finish method. Finalize construction of "Lazy types": Record, Selection, Abstract and generic type.

These input types are typically defined by means of static generating methods, whose allows initialization any of other input types. Since e.g. a Record can link to other input types through its keys at the initialization phase. But some setting (e.g. add descendants to Abstract) can't be done in initialization phase. Therefore, the remaining part of initialization can be done later, in finalization phase, typically from main(), by calling the method finish().

Method allows finish in different cases that is managed by finish_type:

  • base finish of IST requires FinishStatus::regular_ and typically finish of root type is called in this case
  • finish of generic types can be different of other Input::Types (e. g. for Record) and needs set finish_type to FinishStatus::generic_
  • input types unused in IST can be finished with parameter FinishStatus::delete_. These types can be then safely deleted from Input::TypeRepository (see also delete_unfinished_types)

Reimplemented in Input::Type::Record, Input::Type::Array, Input::Type::AdHocAbstract, Input::Type::Selection, Input::Type::Abstract, Input::Type::Instance, Input::Type::Tuple, and Input::Type::Parameter.

Definition at line 216 of file type_base.cc.

Here is the caller graph for this function:

FinishStatus Input::Type::TypeBase::finish_status ( ) const
virtual

Returns true if the type is fully specified and ready for read access.

For Record and Array types this say nothing about child types referenced in particular type object. In particular for Record and Selection, it returns true after finish() method is called.

Reimplemented in Input::Type::Array, Input::Type::Record, Input::Type::Abstract, and Input::Type::Selection.

Definition at line 191 of file type_base.cc.

std::string Input::Type::TypeBase::hash_str ( TypeHash  hash)
static

Format given hash for output.

Use hex format and double quotas.

Definition at line 125 of file type_base.cc.

Here is the caller graph for this function:

std::string Input::Type::TypeBase::hash_str ( ) const
inline

Format the hash of this type.

Definition at line 220 of file type_base.hh.

Here is the caller graph for this function:

bool Input::Type::TypeBase::is_closed ( ) const
virtual

Returns true if the type is closed.

Reimplemented in Input::Type::Record, Input::Type::Abstract, and Input::Type::Selection.

Definition at line 201 of file type_base.cc.

bool Input::Type::TypeBase::is_finished ( ) const
virtual
bool Input::Type::TypeBase::is_root_of_generic_subtree ( ) const
inline

Indicates if type is marked with flag root_of_generic_subtree_.

Definition at line 232 of file type_base.hh.

Here is the caller graph for this function:

bool Input::Type::TypeBase::is_valid_identifier ( const string &  key)
staticprotected

Check that a key is valid identifier.

I.e. consists only of valid characters, that are lower-case letters, digits and underscore, we allow identifiers starting with a digit, but it is discouraged since it slows down parsing of the input file.

Definition at line 93 of file type_base.cc.

Here is the caller graph for this function:

static KeyHash Input::Type::TypeBase::key_hash ( const string &  str)
inlinestaticprotected

Hash function.

Definition at line 261 of file type_base.hh.

Here is the caller graph for this function:

virtual MakeInstanceReturnType Input::Type::TypeBase::make_instance ( ParameterVector  vec = ParameterVector())
pure virtual

Create instance of generic type.

Replace parameters in input tree by type stored in vec.

Here is the caller graph for this function:

bool Input::Type::TypeBase::operator!= ( const TypeBase other) const

Comparison of types.

Definition at line 226 of file type_base.cc.

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

Comparison of types.

It compares kind of type (Integer, Double, String, Record, ..), for complex types it also compares names. For arrays compare subtypes.

Reimplemented in Input::Type::FileName, Input::Type::Array, Input::Type::Record, Input::Type::Selection, and Input::Type::Tuple.

Definition at line 222 of file type_base.cc.

TypeBase::json_string Input::Type::TypeBase::print_parameter_map_keys_to_json ( ParameterMap  param_map) const
protected

JSON format of the vector of parameter names. Used for generic composed types. TODO: use ParameterVector instead of ParameterMap and merge this method with the previous one.

Definition at line 162 of file type_base.cc.

Here is the caller graph for this function:

TypeBase::json_string Input::Type::TypeBase::print_parameter_map_to_json ( ParameterMap  parameter_map) const
protected

Create JSON output from parameter_map formatted as value of attribute.

Definition at line 151 of file type_base.cc.

Here is the caller graph for this function:

void Input::Type::TypeBase::set_generic_attributes ( ParameterMap  param_map)
protected

Extract and set attributes from the ParameterMap containing parameters of the subtree. Used in implementations of the make_instance method.

Definition at line 173 of file type_base.cc.

Here is the caller graph for this function:

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

Returns an identification of the type. Useful for error messages.

Reimplemented in Input::Type::FileName, Input::Type::String, Input::Type::Double, Input::Type::Integer, Input::Type::Bool, Input::Type::Array, Input::Type::Record, Input::Type::Abstract, Input::Type::Selection, and Input::Type::Parameter.

Definition at line 206 of file type_base.cc.

Here is the caller graph for this function:

bool Input::Type::TypeBase::validate_json ( json_string  str) const
protected

Check if str is valid JSON string.

Definition at line 140 of file type_base.cc.

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class Array
friend

Definition at line 309 of file type_base.hh.

friend class OutputBase
friend

Definition at line 311 of file type_base.hh.

friend class Record
friend

Definition at line 310 of file type_base.hh.

Member Data Documentation

std::shared_ptr<attribute_map> Input::Type::TypeBase::attributes_
protected

map of type attributes (e. g. input_type, name etc.)

Definition at line 298 of file type_base.hh.

TypeHash Input::Type::TypeBase::generic_type_hash_
protected

hash string of generic type if type is derived, or empty string

Definition at line 304 of file type_base.hh.

const TypeHash Input::Type::TypeBase::none_hash = std::numeric_limits<TypeHash>::max()
static

Definition at line 96 of file type_base.hh.

ParameterMap Input::Type::TypeBase::parameter_map_
protected

map of parameters if type is part of generic subtree

Definition at line 307 of file type_base.hh.

bool Input::Type::TypeBase::root_of_generic_subtree_
protected

flag is true if type should be root of generic subtree

Definition at line 301 of file type_base.hh.


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