Primary Parent template
meta-function.
More...
#include <Parent.h>
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 | | +- unsigned int | | `- long unsigned int | +- string | | +- char[] | | +- const char[N] | | +- char[N] | | `- char* | `- ptime +- Vector | `- vector<T> `- Matrix
Remarks:
class
es. You are not intent to directly create objects of those types.shared_ptr<
T>
provides an extra level of safety. Indeed, if a raw pointer to T is assigned or copy-constructed to a Result or any other type between them, then it will be immediately wrapped by a shared_ptr<
T>
.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.
T | : The type whose parent should be returned. |
Parent<T>::Type_ | : T's parent type. |