|
Flow123d
last_with_con_2.0.0-2-g938dee8
|
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 bool | is_finished () const |
| Returns true if the type is fully specified and ready for read access. More... | |
| 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 bool | finish (bool is_generic=false) |
| 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 () |
Indicates if type is marked with flag root_of_generic_subtree_. More... | |
Static Public Member Functions | |
| static void | lazy_finish () |
| Finishes all types registered in type repositories. More... | |
| static std::string | hash_str (TypeHash hash) |
| Format given hash for output. More... | |
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 79 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 87 of file type_base.hh.
| typedef std::string Input::Type::TypeBase::json_string |
String stored in JSON format.
Definition at line 85 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 240 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 97 of file type_base.hh.
| typedef std::map< std::string, TypeHash > Input::Type::TypeBase::ParameterMap |
Defines map of used parameters.
Definition at line 95 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 90 of file type_base.hh.
Define vector of parameters passed to the overloaded make_instance method.
Definition at line 92 of file type_base.hh.
| typedef std::size_t Input::Type::TypeBase::TypeHash |
Type returned by content_hash methods.
Definition at line 82 of file type_base.hh.
|
virtual |
Destructor.
Definition at line 68 of file type_base.cc.
|
protected |
The default constructor.
Definition at line 56 of file type_base.cc.
|
protected |
Copy constructor.
Definition at line 62 of file type_base.cc.
|
protected |
Add attribute of given name to attribute map.
Parameter val must contain valid JSON string.
Definition at line 106 of file type_base.cc.

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

|
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 154 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 77 of file type_base.cc.

|
inlinevirtual |
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().
Finish of generic types can be different of other Input::Types (e. g. for Record) and needs set is_generic to true.
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 182 of file type_base.hh.

|
static |
Format given hash for output.
Use hex format and double quotas.
Definition at line 97 of file type_base.cc.

|
inline |
Format the hash of this type.
Definition at line 202 of file type_base.hh.

|
inlinevirtual |
Returns true if the type is closed.
Reimplemented in Input::Type::Record, Input::Type::Abstract, and Input::Type::Selection.
Definition at line 112 of file type_base.hh.
|
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, Input::Type::Abstract, and Input::Type::Selection.
Definition at line 106 of file type_base.hh.
|
inline |
Indicates if type is marked with flag root_of_generic_subtree_.
Definition at line 214 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 71 of file type_base.cc.

|
inlinestaticprotected |
Hash function.
Definition at line 243 of file type_base.hh.

|
static |
Finishes all types registered in type repositories.
Finish must be executed in suitable order 1) finish of Instance types, generic Abstract and generic Record types 2) finish of non-generic Abstract and non-generic Record types 3) finish of the other types
Definition at line 85 of file type_base.cc.

|
pure virtual |
Create instance of generic type.
Replace parameters in input tree by type stored in vec.

|
inline |
Comparison of types.
Definition at line 151 of file type_base.hh.
|
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, Input::Type::Selection, and Input::Type::Tuple.
Definition at line 147 of file type_base.hh.
|
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 134 of file type_base.cc.

|
protected |
Create JSON output from parameter_map formatted as value of attribute.
Definition at line 123 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 145 of file type_base.cc.

|
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, Input::Type::Abstract, Input::Type::Selection, and Input::Type::Parameter.
Definition at line 116 of file type_base.hh.

|
protected |
Check if str is valid JSON string.
Definition at line 112 of file type_base.cc.

|
friend |
Definition at line 291 of file type_base.hh.
|
friend |
Definition at line 293 of file type_base.hh.
|
friend |
Definition at line 292 of file type_base.hh.
|
protected |
map of type attributes (e. g. input_type, name etc.)
Definition at line 280 of file type_base.hh.
|
protected |
hash string of generic type if type is derived, or empty string
Definition at line 286 of file type_base.hh.
|
protected |
map of parameters if type is part of generic subtree
Definition at line 289 of file type_base.hh.
|
protected |
flag is true if type should be root of generic subtree
Definition at line 283 of file type_base.hh.
1.8.11