Flow123d
JS_before_hm-1822-gbb48b12e9
|
Base of classes for declaring structure of the input data. More...
#include <type_base.hh>
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_string > | attribute_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< ParameterPair > | ParameterVector |
Define vector of parameters passed to the overloaded make_instance method. More... | |
typedef std::map< std::string, TypeHash > | ParameterMap |
Defines map of used parameters. More... | |
typedef std::pair< std::shared_ptr< TypeBase >, ParameterMap > | MakeInstanceReturnType |
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 | |
const static 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_map > | attributes_ |
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 |
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.
typedef std::map<std::string, json_string> Input::Type::TypeBase::attribute_map |
Defines map of Input::Type attributes.
Definition at line 101 of file type_base.hh.
typedef std::string Input::Type::TypeBase::json_string |
String stored in JSON format.
Definition at line 99 of file type_base.hh.
|
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.
typedef std::pair< std::shared_ptr<TypeBase>, ParameterMap > Input::Type::TypeBase::MakeInstanceReturnType |
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.
typedef std::map< std::string, TypeHash > Input::Type::TypeBase::ParameterMap |
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.
|
virtual |
Destructor.
Definition at line 90 of file type_base.cc.
|
protected |
The default constructor.
Definition at line 78 of file type_base.cc.
|
protected |
Copy constructor.
Definition at line 84 of file type_base.cc.
|
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.
|
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.
|
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.
|
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.
|
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.
Definition at line 107 of file type_base.cc.
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 -
Definition at line 99 of file type_base.cc.
|
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:
finish_type
to FinishStatus::generic_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.
|
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.
|
inline |
Format the hash of this type.
Definition at line 220 of file type_base.hh.
|
static |
Format given hash for output.
Use hex format and double quotas.
Definition at line 125 of file type_base.cc.
|
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.
|
virtual |
Reimplemented in Input::Type::Array, Input::Type::Record, Input::Type::Abstract, and Input::Type::Selection.
Definition at line 196 of file type_base.cc.
|
inline |
Indicates if type is marked with flag root_of_generic_subtree_
.
Definition at line 232 of file type_base.hh.
|
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.
|
inlinestaticprotected |
Hash function.
Definition at line 261 of file type_base.hh.
|
pure virtual |
Create instance of generic type.
Replace parameters in input tree by type stored in vec
.
bool Input::Type::TypeBase::operator!= | ( | const TypeBase & | other | ) | const |
Comparison of types.
Definition at line 226 of file type_base.cc.
|
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.
|
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.
|
protected |
Create JSON output from parameter_map
formatted as value of attribute.
Definition at line 151 of file type_base.cc.
|
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.
|
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.
|
protected |
Check if str
is valid JSON string.
Definition at line 140 of file type_base.cc.
|
friend |
Definition at line 309 of file type_base.hh.
|
friend |
Definition at line 311 of file type_base.hh.
|
friend |
Definition at line 310 of file type_base.hh.
|
protected |
map of type attributes (e. g. input_type, name etc.)
Definition at line 298 of file type_base.hh.
|
protected |
hash string of generic type if type is derived, or empty string
Definition at line 304 of file type_base.hh.
|
static |
Definition at line 96 of file type_base.hh.
|
protected |
map of parameters if type is part of generic subtree
Definition at line 307 of file type_base.hh.
|
protected |
flag is true if type should be root of generic subtree
Definition at line 301 of file type_base.hh.