Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
Type Support

ELM provides several facilities to handle type and parametric types. More...

Namespaces

 array
 

Classes

class  type_info< T >
 

Typedefs

typedef signed char int8
 
typedef unsigned char uint8
 
typedef short int16
 
typedef unsigned short uint16
 
typedef int int32
 
typedef unsigned int uint32
 
typedef long int64
 
typedef unsigned long uint64
 
typedef uint64 size
 
typedef uint64 offset
 
typedef uint64 uint
 
typedef uint64 intptr
 
template<class T >
using var = typename type_info< T >::var_t
 
template<class T >
using in = typename type_info< T >::in_t
 
template<class T >
using out = typename type_info< T >::out_t
 
template<class T >
using ret = typename type_info< T >::ret_t
 
template<class T >
using mut = typename type_info< T >::mut_t
 

Functions

int msb (t::uint32 i)
 
int msb (t::uint64 i)
 
int ones (t::uint8 i)
 
t::uint32 leastUpperPowerOf2 (t::uint32 v)
 
t::uint64 leastUpperPowerOf2 (t::uint64 v)
 
t::uint32 mult (t::uint32 a, t::uint32, bool &over)
 
t::uint64 mult (t::uint64 a, t::uint64, bool &over)
 
t::uint32 roundup (t::uint32 v, t::uint32 m)
 
t::uint32 rounddown (t::uint32 v, t::uint32 m)
 
int ones (t::uint16 i)
 
int ones (t::uint32 i)
 
int ones (t::uint64 i)
 
template<class T >
T * null (void)
 
template<class T >
T & single (void)
 
template<class T >
void put (var< T > &x, in< T > v)
 
template<class T >
ret< T > get (const var< T > &v)
 
template<class T >
mut< T > ref (var< T > &x)
 

Detailed Description

ELM provides several facilities to handle type and parametric types.

basic_types Basic Types
#include <elm/types.h>
using namespace elm;

This definitions provide several facilities to work with integers. To use, one has to include <elm/int.h>.

This module provides reliable and OS-independent types to represent integers together with a list of efficiently-implemented functions to process them. These types are stored in the elm::t sub-namespace and, if you are using the elm namespace, are quickly accessed by syntax t::type .

#include <elm/int.h>
using namespace elm;
...
t::uint32 my_variable;

You can also use the null<T>() function to build easily typed null pointer.

Type Information
#include <elm/type_info.h>
using namespace elm;

Class elm::type_info<T> allows to get information from the type passed as the parametric argument. The following information are available:

In addition, elm::type_info<T> provides facilities to efficiently and powerfully manage types used in templates:

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:

class MyClass { ... };
template <> struct type_info<T> { static cstring name(void) { return "MyClass"; } }

Or just add a static member named "__type_name" in the class declaration:

class MyClass {
public:
static cstring __type_name(void) { return "MyClass"; }
...
};

Instead of using directly type_info<T> members, some shortcuts are available (and advised):

Enumeration Information

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):

typedef enum { V1, V2, V3, ... } my_enum;
...
namespace elm {
template <> struct type_info<my_enum>: enum_info<my_enum> { };
}

And then to provided the missing (usually in the source file providing implementation).

namespace elm {
template <> cstring enum_info<my_enum>::name(void) { return "my_enum"; }
value("V1", V1),
value("V2", V2),
value("V3", V3),
last()
};
}

As the primitives provided by ELM, the values may examined with such a loop:

for(type_info<my_enum>::iterator i = type_info<my_enum>::begin(); i != type_info<my_enum>::end(); i++)
cout << "name = " << i.name << ", value = " << i.value << io::endl;
Array Copying

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:

class MyClass {
...
};
template <>
class type_info<MyClass>: public class_t<T> { enum { is_deep = 1 }; };

Typedef Documentation

◆ in

in

#include <include/elm/type_info.h>

Shortcut to type_info<T>::in_t;

◆ int16

#include <include/elm/arch.h>

Signed 16-bit integer type.

◆ int32

#include <include/elm/arch.h>

Signed 32-bit integer type.

◆ int64

#include <include/elm/arch.h>

Signed 64-bit integer type.

◆ int8

#include <include/elm/arch.h>

Signed 8-bit integer type.

◆ intptr

#include <include/elm/arch.h>

Integer sufficiently big to store a pointer (according to the system configuration).

◆ mut

mut

#include <include/elm/type_info.h>

Shortcut to type_info<T>::mut_t;

◆ offset

#include <include/elm/arch.h>

Integer type to represent memory offset (according to the system configuration).

◆ out

out

#include <include/elm/type_info.h>

Shortcut to type_info<T>::out_t;

◆ ret

ret

#include <include/elm/type_info.h>

Shortcut to type_info<T>::ret_t;

◆ size

#include <include/elm/arch.h>

Integer type to represent memory size (according to the system configuration).

◆ uint

#include <include/elm/arch.h>

Default size unsigned integer type.

◆ uint16

#include <include/elm/arch.h>

Unsigned 16-bit integer type.

◆ uint32

#include <include/elm/arch.h>

Unsigned 32-bit integer type.

◆ uint64

#include <include/elm/arch.h>

Unsigned 64-bit integer type.

◆ uint8

#include <include/elm/arch.h>

Unsigned 8-bit integer type.

◆ var

var

#include <include/elm/type_info.h>

Shortcut to type_info<T>::var_t;

Function Documentation

◆ get()

ret< T > get ( const var< T > &  v)
inline

#include <include/elm/type_info.h>

Shortcut to type_info::get().

References type_info< T >::get().

Referenced by access_t< const cstring & >::set(), and access_t< const string & >::set().

◆ leastUpperPowerOf2() [1/2]

t::uint32 leastUpperPowerOf2 ( t::uint32  v)

#include <include/elm/int.h>

Get the least upper power of 2 for the given value. If the value is a power of two, return it else compute the least greater power.

Parameters
vValue to process.
Returns
Least upper power of two.

References elm::msb().

Referenced by Builder< K, T, Comparator< K > >::allocate().

◆ leastUpperPowerOf2() [2/2]

t::uint64 leastUpperPowerOf2 ( t::uint64  v)

#include <include/elm/int.h>

Get the least upper power of 2 for the given value. If the value is a power of two, return it else compute the least greater power.

Parameters
vValue to process.
Returns
Least upper power of two.

References elm::msb().

◆ msb() [1/2]

int msb ( t::uint32  i)

#include <include/elm/int.h>

Compute the position of the left-most bit to one.

Parameters
iInteger to test.
Returns
Position of left-most bit to one or -1 if the integer is 0.

Referenced by elm::leastUpperPowerOf2(), and elm::msb().

◆ msb() [2/2]

int msb ( t::uint64  i)

#include <include/elm/int.h>

Compute the position of the left-most bit to one.

Parameters
iInteger to test.
Returns
Position of left-most bit to one or -1 if the integer is 0.

References elm::msb().

◆ mult() [1/2]

t::uint32 mult ( t::uint32  a,
t::uint32  b,
bool over 
)

#include <include/elm/int.h>

Perform multiplication on unsigned integer 32-bits.

Parameters
aFirst number to multiply.
bSecond number to multiply.
overSet to true if overflow occurs.
Returns
Result of multiplication (only valide if over is false).

◆ mult() [2/2]

t::uint64 mult ( t::uint64  a,
t::uint64  b,
bool over 
)

#include <include/elm/int.h>

Perform multiplication on unsigned integer 64-bits.

Parameters
aFirst number to multiply.
bSecond number to multiply.
overSet to true if overflow occurs.
Returns
Result of multiplication (only valide if over is false).

◆ null()

T * null ( void  )
inline

#include <include/elm/types.h>

Build a typed null pointer from the template type.

Parameters
TPointed object type.

Referenced by Tree< K, T, C >::node_t::node_t().

◆ ones() [1/4]

int ones ( t::uint16  i)
inline

#include <include/elm/int.h>

Count the number of ones in the given half-word.

Parameters
iHalf-word to count ones in.
Returns
Number of ones in the half-word.

References elm::countOnes().

◆ ones() [2/4]

int ones ( t::uint32  i)
inline

#include <include/elm/int.h>

Count the number of ones in the given word.

Parameters
iWord to count ones in.
Returns
Number of ones in the word.

References elm::countOnes().

◆ ones() [3/4]

int ones ( t::uint64  i)
inline

#include <include/elm/int.h>

Count the number of ones in the given double-word.

Parameters
iDouble-word to count ones in.
Returns
Number of ones in the double-word.

References elm::countOnes().

◆ ones() [4/4]

int ones ( t::uint8  i)
inline

#include <include/elm/int.h>

Count the number of ones in the given byte.

Parameters
iByte to count ones in.
Returns
Number of ones in the byte.

References elm::countOnes().

Referenced by BitVector::countBits(), elm::countOnes(), WAHVector::countOnes(), and BitVector::countOnes().

◆ put()

void put ( var< T > &  x,
in< T >  v 
)
inline

#include <include/elm/type_info.h>

Shortcut to type_info::put().

References type_info< T >::put().

◆ ref()

◆ rounddown()

t::uint32 rounddown ( t::uint32  v,
t::uint32  m 
)
inline

#include <include/elm/int.h>

Round upto upper multiple integer

Parameters
vValue to round.
mMultiple to round with.
Returns
Value round upto the upper multiple integer.

References elm::countOnes().

◆ roundup()

t::uint32 roundup ( t::uint32  v,
t::uint32  m 
)
inline

#include <include/elm/int.h>

Round upto upper multiple integer

Parameters
vValue to round.
mMultiple to round with.
Returns
Value round upto the upper multiple integer.

References elm::countOnes().

◆ single()

T & single ( void  )
inline

#include <include/elm/types.h>

Returns a singleton corresponding to the parameter type. The uniqueness of the return value is ensured, meaning that any call to this function will ever return the same singleton object. This function provides an easy and fast way to define a singleton.

Parameters
TType of singleton. Must support default constructor.

References elm::_.

elm::enum_info::value_t
struct elm::enum_info::value_t value_t
elm::cstring
CString cstring
Definition: CString.h:62
elm::cout
io::Output cout
value
elm::enum_info::name
static cstring name(void)
elm
Definition: adapter.h:26
elm::io::endl
const EOL endl
Definition: io_Output.cpp:880
elm::type_info::is_deep
@ is_deep
Definition: type_info.h:59
elm::type_info::name
static cstring name(void)
Definition: type_info.h:63
elm::enum_info::values
static value_t values[]
Definition: enum_info.h:37