AMTypeID  201909
String localization library
Andromeda typeid library

AMTypeID - unique integral id for an every typeUseful for example for implementing variant types. You may have union of multiple types and tag with stored type.

Usage

Typical usage is very simple...

uint64_t sw = AMCETypeID<uint64_t>::id();
switch(sw) {
case AMCETypeID<uint32_t>::id(): FAIL() << "Switch: bad branch selected";break;
case AMCETypeID<int64_t>::id(): FAIL() << "Switch: bad branch selected";break;
case AMCETypeID<uint64_t>::id(): ;break;
case AMCETypeID<char*>::id(): FAIL() << "Switch: bad branch selected";break;
case AMCETypeID<std::string>::id(): FAIL() << "Switch: bad branch selected";break;
}

If you dislike long range of hash, you may put its own id by:

namespace AMCore {
template<> inline constexpr uint64_t AMCETypeID<uint64_t>::id() { return 100;}
template<> inline constexpr uint64_t AMCETypeID<int64_t>::id() { return 101;}
template<> inline constexpr uint64_t AMCETypeID<const char*>::id() { return 102;}
template<> inline constexpr uint64_t AMCETypeID<uint32_t>::id() { return 104;}
}

Sources

Download at GitHUB

Building AMTypeID

Getting sources

git submodule update

Compiling

mkdir cmake-build-debug
cd cmake-build-debug
cmake ..
make

Output Library

/lib/libAMTypeID.so

Single test (not necessary)

./TEST_AMTypeID
./TEST_AMTypeID_collect

License

This library is under GNU GPL v3 license. If you need business license, don't hesitate to contact me.

Contribute

Please contact me.

Dependencies

AMCore::AMCETypeID::id
static constexpr uint64_t id()
id Practically, id is some index in range in 0 to N. Main purpose is optimize switch statement,...
Definition: AMCETypeID.h:175
AMCETypeID.h