Elm
1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
|
Classes | |
class | elm::type_info< T > |
ELM provides several facilities to handle type and parametric types.
This include provides alternative non-ambiguous names for integer types (Integer Operations) and associated basic operations.
Class elm::type_info<T> allows to get from the type passed as the parametric argument. This may be useful for templates using static evaluation. The common fields includes:
Notice that ELM provides type information for basic (integer, float, string) and composed types (pointer, references) but need the developer help for more complex types like classes, struct or unions. Either one can add the specialized type_info structure for the defined type:
Or just add a static member named "__type_name" in the class declaration:
A big issue in C++ is the selection of type for parameters and functions results. A common practice is to pass a simple type as is as parameter and to use const references for bigger types. This policy is easy to apply when the type is known but what to do when the parameter method is in a template class. Here, a conservative approach advise to use const reference in any case in the hope that the compiler will optimize the code and use only straight type for scalar types.
ELM proposes an alternative to this approach that works with template. Using the type_info<T> class (that is aware of the actual type of the generic parameter), one can obtain the type declaration that fits the best its use:
Notice type_info<T>::embed_t that allows storing references: in fact, when T is a reference, it is stored automatically as a pointer. type_info<T>::put() and type_info<T>::get() can then be used to store the generic value or to get it.
Users may also benefit from whole facilities of input/output, serialization and like for the enumerated type. First, the type_info must be specialized (in the header containing the enumeration declaration):
And then to provided the missing (usually in the source file providing implementation).
As the primitives provided by ELM, the values may examined with such a loop:
The include file <otawa/util/array.h> provides functions to handling arrays:
According to the type of the type of the items, these functions may invokes specific system functions to make faster this operation. Usually, only types without pointers can only be processed in this way (scalar data) but you can informs that your own class can be shallowly copied by specializing the type_info class: