Hi,
I am stuck with a design problem that I hope you guys can help with. I have a few different classes that have various parameters (more than 20 in each case, and they are mostly different, although some are exactly the same in which case they inherit from a base class). I want to control these parameters through the user of a class called ObjectProperties. Each class will create ObjectProperties and populate it with it's own parameter list when the class is initialized. This is done with a map which is set up like so:
std::map<std::string, [data_type]> // where [data_type] can be an int, float, bool, string etc.
the 'string' is the name for the parameter and the data type is the type it's associated with. This is done for easy scripting later on (instead of having 20+ getters/setters). I have already made the ObjectProperties class, but it is less than ideal. I have a structure with all the possible data types called DataTypeStruct and a variable for the map in the ObjectProperties class called pDataTypeMap;
typedef struct
{
int* IntValue;
float* FloatValue;
bool* BoolValue;
std::string* StringValue;
}DataTypeStruct;
std::map<std::string, DataTypeStruct> pDataTypeMap;
When a class wants to add a parameter for manipulation, it calls one of the following functions, which then creates a new structure appropriately and pairs it with the name to be put in the map. The function returns true or false depending on whether it was able to insert it or not (if false, then the name already exists)
bool AddParam(std::string aName, int* aParam);
bool AddParam(std::string aName, float* aParam);
bool AddParam(std::string aName, bool* aParam);
bool AddParam(std::string aName, std::string* aString);
The reason aParam is/are pointers is because it is required that the parameters must be passed by reference so that they can be manipulated later on.
To change the value for the parameter I have similar functions. As you can see, this is less than ideal, as I have wasted some space with the structure (where each new structure only stores an int OR a bool OR a string OR a float), and calling overloaded functions is unsafe (I 'can' make the functions have unique names, but again, that is less than ideal).
I hope I have explained the design issue that I have come across (it is a little difficult to explain) and would really like to hear suggestions on how to go about solving this problem.