A C++ template library for embedded applications
Designed and maintained by
Aster Consulting Ltd

Type Lookup

Compile time mapping of id to type, type to id and type to type.
This file is generated from type_lookup_generator.h and can be created by running generate_type_lookup.bat.

type_id_pair

Support structure for type_id_lookup.

etl::type_id_pair<typename T, size_t ID>

Defines:
type The type.
ID   The id associated with the type.

type_type_pair

Support structure for type_type_lookup.

etl::type_type_pair<typename T1, typename T2>

Defines:
type1 The indexing type.
type2 The associated type.

type_id_lookup

Creates a class for compile time id to type and type to id mappings.
etl::type_id_lookup<typename T1, ...>

The number of types that can be handled is determined by the generator.
Each template parameter is a type_id_pair.

The class contains two nested templates.

type_from_id

Gets the type from the id.
type_from_id<size_t ID>

Defines:
type The associated type.

id_from_type

Gets the id from the type.
id_from_type<typename T>

Defines:
ID The associated id.

Static functions

Gets the id from the type.
template <typename T>
static unsigned int get_id_from_type(const T&)


template <typename T>
static unsigned int get_id_from_type()

type_type_lookup

Creates a class for compile time type to type mapping.

etl::type_id_lookup<typename T1, ...>
The number of types that can be handled is determined by the generator.
Each template parameter is a type_id_pair.

The class contains one nested template.

type_from_type

type_from_type<typename T>

Defines:
type The associated type.

Examples


type_id_lookup

enum
{
  INT32  = 32,
  STRING = 1,
  UINT8  = 8,
  OTHER  = 0
};

typedef etl::type_id_pair<int32_t,     INT32>  TypeIdInt32;
typedef etl::type_id_pair<uint8_t,     UINT8>  TypeIdUint8;
typedef etl::type_id_pair<std::string, STRING> TypeIdString;

// Type from Id / Id from Type.
typedef etl::type_id_lookup<TypeIdInt32, TypeIdString, TypeIdUint8> Type_Id_Lookup;

// int32_t
typename Type_Id_Lookup::type_from_id<INT32>::type

// uint8_t
typename Type_Id_Lookup::type_from_id<UINT8>::type

// std::string
typename Type_Id_Lookup::type_from_id<STRING>::type

// Compile error
typename Type_Id_Lookup::type_from_id<OTHER>::type

// INT32
Type_Id_Lookup::id_from_type<int32_t>::ID

// UINT8
Type_Id_Lookup::id_from_type<uint8_t>::ID

// STRING
Type_Id_Lookup::id_from_type<std::string>::ID

// Compile error
Type_Id_Lookup::id_from_type<double>::ID

type_type_lookup

// Get the next larger type.
typedef etl::type_type_pair<int16_t, int32_t>  TypeInt16;
typedef etl::type_type_pair<uint8_t, uint16_t> TypeUint8;
typedef etl::type_type_pair<float,   double>   TypeFloat;

// Type from Type.
etl::type_type_lookup<TypeInt16, TypeUint8, TypeFloat> Type_Type_Lookup;

// int32_t
typename Type_Type_Lookup::type_from_type<int16_t>::type

// uint16_t
typename Type_Type_Lookup::type_from_type<uint8_t>::type

// double
typename Type_Type_Lookup::type_from_type<float>::type

// Compile error
typename Type_Type_Lookup::type_from_type<int32_t>::type

type_lookup.h