ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
VMeta Struct Referenceabstract

Description:

Abstract, virtual struct which provides meta-information about types storable in the StringTree nodes of class Configuration. A pointer to a singleton of this type is stored together with a reinterpreted pointer to the custom data record.

To register a custom data type with the configuration system, this type has to inherited and all methods implemented. It is recommended to define custom derived types using macro ALIB_CONFIG_VARIABLE_DEFINE_TYPE. Derived types are to be registered with the configuration instance by invoking Configuration::RegisterType.

See also
Chapter 5.2 Custom Variable Types of the Programmer's Manual of camp ALib Configuration.

Definition at line 68 of file vmeta.hpp.

#include <vmeta.hpp>

Public Method Index:

virtual ~VMeta ()
 Virtual empty destructor.
 
virtual void construct (void *memory, PoolAllocator &pool)=0
 
virtual const std::type_info & dbgTypeID ()=0
 
virtual void destruct (void *memory, PoolAllocator &pool)=0
 
virtual void exPort (detail::VDATA *data, Configuration &cfg, const StringEscaper &escaper, AString &dest)=0
 
virtual void imPort (detail::VDATA *data, Configuration &cfg, const StringEscaper &escaper, const String &src)=0
 
virtual size_t size ()=0
 
virtual String typeName () const =0
 

Constructor(s) / Destructor Details:

◆ ~VMeta()

virtual ~VMeta ( )
inlinevirtual

Virtual empty destructor.

Definition at line 71 of file vmeta.hpp.

Method Details:

◆ construct()

virtual void construct ( void * memory,
PoolAllocator & pool )
pure virtual

Abstract virtual method. Descendants need to construct a custom instance at the given memory. This is done using a "placement-new" as follows:

        new (memory) MyType();

The pool allocator is not provided to allocate the custom type itself (this was already done before calling this method). Instead, it may be used to allocate members in the custom type. It may also be passed to the instance for further use during it's lifecycle. However, in this case chapter 11. Multi-Threading / Racing Conditions of the Programmer's Manual has to be considered.

Parameters
memoryThe pointer to the object of custom type.
poolThe object pool of the configuration. May be used to dispose pool objects.

◆ dbgTypeID()

virtual const std::type_info & dbgTypeID ( )
pure virtual

Abstract virtual method. Descendants need to return the std::type_info& received with typeid(). This method is available only in debug-compilations and is used to assert that the correct types are read from declared variables.
Types declared with macro ALIB_CONFIG_VARIABLE_DEFINE_TYPE implement this method rightfully.

Returns
The C++ type ID.

◆ destruct()

virtual void destruct ( void * memory,
PoolAllocator & pool )
pure virtual

Abstract virtual method. Descendants need to destruct a custom instance at the given memory. This is done by calling the destructor as follows:

        reinterpret_cast<MyTypeName*>(memory)->~MyTypeName();

The pool allocator is not provided to free the custom type itself (this will be done automatically right after the call to this method). Instead, it may be used to free members of the type, which had been allocated during construction or during the use.

Note
However, for most types included with ALib, for example AStringPA, if used as a member of the custom type, no special action need to be taken and it is sufficient to call the destructor of the custom type. This is because these types take a copy of the pool on construction and thus their destructor disposes allocated pool objects autonomously. In other words, if only such members are used, then method construct has to be implemented to pass the pool object to the members, but this method simply invokes the destructor of the custom type as shown above.
Parameters
memoryThe place to construct the custom type at.
poolThe object pool of the configuration. May be used to allocate pool objects.

◆ exPort()

virtual void exPort ( detail::VDATA * data,
Configuration & cfg,
const StringEscaper & escaper,
AString & dest )
pure virtual

Abstract virtual method. Descendants need to implement this method. It is invoked when a variable is written into an external configuration source (in this case 'drain') or otherwise needs to be serialized.

Note that export functions are allowed to add NEW_LINE codes into the export string. This allows external configuration systems to nicely format their entries, in case those are human-readable. See chapter 7.4 Attaching a Custom Configuration System of the Programmer's Manual for more information.

Attention
Types declared with macro ALIB_CONFIG_VARIABLE_DEFINE_TYPE only declare this method. An implementation needs to be provided in a compilation unit. Otherwise linking a software fails.
Parameters
dataA pointer to the user type which is to be serialized.
cfgThe configuration that holds the variable.
escaperAn escaper to be used to escape strings.
destThe destination string. Must not be reset prior writing, but appended.

◆ imPort()

virtual void imPort ( detail::VDATA * data,
Configuration & cfg,
const StringEscaper & escaper,
const String & src )
pure virtual

Abstract virtual method. Descendants need to implement this method and de-serialize (aka parse) the custom type from the given string value.

Attention
Types declared with macro ALIB_CONFIG_VARIABLE_DEFINE_TYPE only declare this method. An implementation needs to be provided in a compilation unit.
Parameters
dataA pointer to the user type which is to be initialized.
cfgThe configuration that holds the variable.
escaperAn escaper to be used to convert external strings to C++ native strings.
srcThe source string to parse. This may be assigned to a value of type TSubstring which already provides simple parser mechanics. Likewise, TTokenizer might be an easy helper to be used for parsing.

◆ size()

virtual size_t size ( )
pure virtual

Abstract virtual method. Descendants need to return 'sizeof(T)', with T being the custom type. Types declared with macro ALIB_CONFIG_VARIABLE_DEFINE_TYPE implement this method rightfully. With that, it is also asserted that the alignment of the custom type is not greater than 'alignof(uint64_t)', respectively not greater than what is specified with compiler symbol ALIB_MONOMEM_POOLALLOCATOR_DEFAULT_ALIGNMENT.

Returns
The size of the variable's content type.

◆ typeName()

virtual String typeName ( ) const
pure virtual

Abstract virtual method. Descendants need to return the type name they care of.
Types declared with macro ALIB_CONFIG_VARIABLE_DEFINE_TYPE implement this method rightfully.

Returns
The type's name.

The documentation for this struct was generated from the following file: