Flow123d  jenkins-Flow123d-windows32-release-multijob-163
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | 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]

Public Member Functions

virtual bool is_finished () const
 
virtual string type_name () const
 Returns an identification of the type. Useful for error messages. More...
 
virtual string full_type_name () const
 Returns an identification of the type in format "type_name():parent->type_name()". More...
 
string desc () const
 
virtual bool operator== (const TypeBase &other) const
 
bool operator!= (const TypeBase &other) const
 Comparison of types. More...
 
virtual ~TypeBase ()
 
virtual bool finish ()
 
virtual bool valid_default (const string &str) const =0
 
virtual std::size_t content_hash () const =0
 

Static Public Member Functions

static void lazy_finish ()
 Finishes all registered lazy types. More...
 

Protected Types

typedef string KeyHash
 
typedef std::vector
< boost::shared_ptr< TypeBase > > 
LazyTypeVector
 
typedef std::set< const
TypeBase * > 
LazyObjectsSet
 

Protected Member Functions

 TypeBase ()
 
 TypeBase (const TypeBase &other)
 

Static Protected Member Functions

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)
 

Friends

class Array
 
class Record
 

Detailed Description

Base of classes for declaring structure of the input data.

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

Definition at line 63 of file type_base.hh.

Member Typedef Documentation

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

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 168 of file type_base.hh.

typedef std::set<const TypeBase *> Input::Type::TypeBase::LazyObjectsSet
protected

Set of pointers to all constructed (even temporaries) lazy types. This list contains ALL instances (including copies and empty handles) of lazy types.

Definition at line 204 of file type_base.hh.

typedef std::vector< boost::shared_ptr<TypeBase> > Input::Type::TypeBase::LazyTypeVector
protected

The Singleton class LazyTypes serves for handling the lazy-evaluated input types, derived from the base class LazyType. When all static variables are initialized, the method LazyTypes::instance().finish() can be called in order to finish initialization of lazy types such as Records, AbstractRecords, Arrays and Selections. Selections have to be finished after all other types since they are used by AbstractRecords to register all derived types. For this reason LazyTypes contains two arrays - one for Selections, one for the rest.

This is list of unique instances that may contain raw pointers to possibly not yet constructed (static) objects. Unique instance is the instance that creates unique instance of the data class in pimpl idiom. These has to be completed/finished before use.

Definition at line 193 of file type_base.hh.

Constructor & Destructor Documentation

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

Destructor removes type object from lazy_object_set.

Definition at line 59 of file type_base.cc.

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

Default constructor. Register type object into lazy_object_set.

Definition at line 46 of file type_base.cc.

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

Copy constructor. Register type object into lazy_object_set.

Definition at line 52 of file type_base.cc.

Member Function Documentation

virtual std::size_t 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.

Implemented in Input::Type::AdHocAbstractRecord, Input::Type::AbstractRecord, Input::Type::FileName, Input::Type::String, Input::Type::Double, Input::Type::Integer, Input::Type::Bool, Input::Type::Array, Input::Type::Record, and Input::Type::Selection.

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.

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 refered object can be temporary solutions:
    • consistently move TypeBase to Pimpl design
    • provide virtual function make_copy, that returns valid shared_ptr

Definition at line 73 of file type_base.cc.

Here is the caller graph for this function:

virtual bool Input::Type::TypeBase::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 in Input::Type::AdHocAbstractRecord, Input::Type::Record, Input::Type::Array, and Input::Type::Selection.

Definition at line 131 of file type_base.hh.

virtual string Input::Type::TypeBase::full_type_name ( ) const
inlinevirtual

Returns an identification of the type in format "type_name():parent->type_name()".

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

Definition at line 78 of file type_base.hh.

virtual bool Input::Type::TypeBase::is_finished ( ) const
inlinevirtual

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, and Input::Type::Selection.

Definition at line 71 of file type_base.hh.

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 67 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 171 of file type_base.hh.

Here is the caller graph for this function:

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

Finishes all registered lazy types.

Definition at line 88 of file type_base.cc.

Here is the caller graph for this function:

TypeBase::LazyObjectsSet & Input::Type::TypeBase::lazy_object_set ( )
staticprotected

Definition at line 117 of file type_base.cc.

Here is the caller graph for this function:

TypeBase::LazyTypeVector & Input::Type::TypeBase::lazy_type_list ( )
staticprotected

The reference to the singleton instance of lazy_type_list.

Definition at line 81 of file type_base.cc.

Here is the caller graph for this function:

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

Comparison of types.

Definition at line 107 of file type_base.hh.

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

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, and Input::Type::Selection.

Definition at line 103 of file type_base.hh.

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

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, and Input::Type::Selection.

Definition at line 75 of file type_base.hh.

Here is the caller graph for this function:

virtual bool Input::Type::TypeBase::valid_default ( const string &  str) const
pure virtual

For types that can be initialized from a default string, this method check validity of the default string. For invalid string an exception is thrown.

Return false if the validity can not be decided due to presence of unconstructed types (Record, Selection)

Implemented in Input::Type::AbstractRecord, Input::Type::String, Input::Type::Double, Input::Type::Integer, Input::Type::Bool, Input::Type::Array, Input::Type::Record, and Input::Type::Selection.

Here is the caller graph for this function:

bool Input::Type::TypeBase::was_constructed ( const TypeBase ptr)
staticprotected

Definition at line 124 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 210 of file type_base.hh.

friend class Record
friend

Definition at line 211 of file type_base.hh.


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