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:
Expand|Select|Wrap|Line Numbers
- //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..
- }
Expand|Select|Wrap|Line Numbers
- std::map<const char*, int>
- std::map<const char*, float>
Expand|Select|Wrap|Line Numbers
- template <typename T>
- void add(const char* name, T value)
- {
- attributes[name] = value;
- }
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?