Parent< T > Struct Template Reference

Primary Parent template meta-function. More...

#include <Parent.h>


Detailed Description

template<typename T>
struct keyvalue::value::Parent< T >

Primary Parent template meta-function.

The types in namespace value follow an hierarchy NOT built through inheritance. Before explaining how this hierarchy is implemented, we will consider the reason for its existence by an explanatory example.

Consider a Calculator whose result is a double x. Since all Calculators are expected to return Values, x must be converted before being returned. Recall that Value is a container for Matrix, Vector or Single. Obviously, Single is the right choice to carry x. However, Single is a container for Variants. Hence, firstly x must be converted to Variant. We conclude that x must to pass trough a series of conversions provided by copy-constructors. Therefore, the Calculator might return x as follows:

 return Value(Single(Variant(x)));

It would be more convenient if these conversions were automatic. That is the reason for the hierarchy of types. Any type might be copy-constructed or assigned from any other type in a lower level of the hierarchy. In the example, returning x directly from the Calculator would imply in all the conversions up to Value.

Let T be a type (a basic one or one created by a Builder) and N be of type size_t. The hierarchy has Result on the top level and is as follows:

 Result
 `- Result::DataType_
    +- ObjectPtr
    |  `- shared_ptr<T>
    |     `- T*
    `- Value
       `- Value::DataType_
          +- Single
          |  `- Variant
          |     `- Variant::DataType_
          |        +- Nothing
          |        +- bool
          |        +- double
          |        |  +- int
          |        |  +- unsigned int
          |        |  `- long unsigned int
          |        +- string
          |        |  +- char[]
          |        |  +- char[N]
          |        |  +- char*
          |        |  +- const char[]
          |        |  +- const char[N]
          |        |  `- const char*
          |        `- ptime
          +- Vector
          |  `- vector<T>
          `- Matrix

Remarks:

Finally, Parent a template meta-function which returns the parent of a type according to the value hierarchy. Each for each type in the hierarchy (excluding Result) there should be a specialization.

Parameters:
T : The type whose parent should be returned.
Return values:
Parent<T>::Type_ : T's parent type.