List of all members |
Classes |
Public Types |
Public Member Functions |
Static Public Member Functions
mpqc::DescribedClass Class Reference
Collaboration diagram for mpqc::DescribedClass:
Documentation
This class helps construction of (smart pointers to) C++ objects from , e.g., text input To be able to construct class T
from KeyVal objects do this:
-
make DescribedClass a public base of
T
, and -
register
T
with DescribedClass .
The latter can be achieved in a number of ways, but the easiest is to add any of the following statements to a source file in the global scope:
-
if you want to use class name
T
as the type identifier in KeyVal input:MPQC_CLASS_EXPORT_KEY(T)
-
if you want to use any other key
Key
as the type identifier in KeyVal input:MPQC_CLASS_EXPORT_KEY2(T, Key)
It is the easiest to add these statements in the .cpp file that defines T
, but any other .cpp file will work.
- Note
- If
T
is a template class, you must register each instance of this class you want to construct from KeyVal.
- Warning
- to ensure that the class registration code of the derived class is linked in, its destructor (at least) must be explicitly instantiated. Related: how gcc instantiates vtable and RTTI info see here
Classes | |
struct | registrar |
Public Types | |
typedef std::shared_ptr< DescribedClass >(* | keyval_ctor_wrapper_type) (const KeyVal &) |
Public Member Functions | |
DescribedClass ()=default | |
virtual | ~DescribedClass () |
std::string | class_key () const |
Public Member Functions inherited from mpqc::enable_shared_from_this< DescribedClass > | |
virtual | ~enable_shared_from_this ()=default |
std::shared_ptr< DescribedClass > | shared_from_this () |
returns the pointer to this object More... | |
std::shared_ptr< std::add_const_t< DescribedClass > > | shared_from_this () const |
returns the pointer to this object More... | |
Public Member Functions inherited from mpqc::detail::virt_base_of_enable_shared_from_this | |
virtual | ~virt_base_of_enable_shared_from_this ()=default |
bool | shared_from_this_possible () const |
template<typename Target , typename = std::enable_if_t<!std::is_const_v<Target>>> | |
std::shared_ptr< Target > | cast_shared_from_this_to () |
returns the pointer to this cast to a particular type More... | |
template<typename Target > | |
std::shared_ptr< std::add_const_t< Target > > | cast_shared_from_this_to () const |
returns the pointer to this cast to a particular type More... | |
Static Public Member Functions | |
static keyval_ctor_wrapper_type | type_to_keyval_ctor (const std::string &type_name) |
template<typename T > | |
static void | register_keyval_ctor () |
template<typename T > | |
static bool | is_registered () |
template<typename T > | |
static std::string | class_key () |
static const keyval_ctor_registry_type & | keyval_ctor_registry () |
returns const ref to the keyval ctor registry More... | |
Member Typedef Documentation
◆ keyval_ctor_wrapper_type
typedef std::shared_ptr<DescribedClass>(* mpqc::DescribedClass::keyval_ctor_wrapper_type) (const KeyVal &) |
Constructor & Destructor Documentation
◆ DescribedClass()
|
default |
◆ ~DescribedClass()
|
inlinevirtual |
Member Function Documentation
◆ class_key() [1/2]
template<typename T >
|
inlinestatic |
query the class key for std::decay_t<T>
- Template Parameters
-
T a class
- Returns
- class key with which
std::decay_t<T>
was registered, or empty string if T was not registered
- Warning
- cannot call this function before global object initialization has completed (i.e. after main() has started)
◆ class_key() [2/2]
|
inline |
query the class key for this object
- Returns
- class key with which the class of this object was registered, or empty string if it was not registered
- Warning
- cannot call this function before global object initialization has completed (i.e. after main() has started)
◆ is_registered()
template<typename T >
|
inlinestatic |
query if std::decay_t<T>
is registered
- Template Parameters
-
T a class
- Returns
- true if
std::decay_t<T>
is registered
- Warning
- cannot call this function before global object initialization has completed (i.e. after main() has started)
◆ keyval_ctor_registry()
|
inlinestatic |
returns const ref to the keyval ctor registry
◆ register_keyval_ctor()
template<typename T >
|
inlinestatic |
◆ type_to_keyval_ctor()
|
static |
The documentation for this class was generated from the following files:
- mpqc/util/keyval/keyval.h
- mpqc/util/keyval/keyval.cpp