Hi, trying to add scripting support for a game i'm making.
I'd like to be able to add an arbitrary type to any object in the game, and i'm using a base class with maps to hold the types. Currently a have a map for every known type (bool, int, float, double and some templates), but i'd like to have just one map to hold them all. This is what i got so far:
-
//adds a variable to the map with with the name 'name' and the value 'value'
-
template <typename T>
-
void add(const char* name, T value)
-
{
-
if( typeid(T) == typeid(int) )
-
ints[name] = value;
-
-
if( typeid(T) == typeid(float) )
-
floats[name] = value;
-
-
//ect..
-
}
-
ints and floats are maps of the type
-
std::map<const char*, int>
-
std::map<const char*, float>
-
but i'd like to have a function like this
-
template <typename T>
-
void add(const char* name, T value)
-
{
-
attributes[name] = value;
-
}
-
but i can't figure out how the map should be declared or how to get things out of the map without knowing the type.
Is this at all understandable? Does anyone have an idear for a solution?
Should i just settle with have to have a map for every type?