I have dilemma how to design the configuration. The software has configuration files that vary by customer. So for customerA the config file may have parametarA and parametarB. and for customerB the config file will have parametarA, parametarB and parametarC. So not of all the parameters that control software behavior are included in all configuration files. Further, this parameters are not all simple types like ints, string and doubles, i.e they can be themselves structures witch contain also optional members. So say I have the following parameters for CustomerC : param1 of type int, param2 of type structA, param3 of type structB.
structA
{
int param1;
boost::optional<double> param2;
};
struct B
{
optional<int> param1;
optional<int> param2;
};
So I have two options : -first option to store the parametars as key/values in map. access to parametars is with string name , and one have to know the type of the parametar at access point to cast it to the adequate type. in the map I am storing only the required params for the customer. one have to check whether the parametar exists in the map before retrieving it, and using it.
-second option is to have one big conf class which contains all optional memebers for all customeers, and one have to check whether the optional parametar is initialized before using it, so this is same as option1. The good thing is one doesnot need to know the type of the parametar before accessing it, because the parametar is known at compile time. Bad thing is that I have one big class that contains parameters for all customers. This is a little strange. But besides that this option2 looks good.
class Conf
{
optional<int> Param1;
optional<StructA> Param2;
optional<StructB> Param3;
optional<double> Param4;
optional<int> Param5;
//all software params for all customers
};
Also why to store parameters in map when I can in class ? One reason that I can thinkof is because in map you can add parameters at runtime if you want without recompiling, but if you are gonna add new parameter which controls some aspect of the software you have to include the parametar in the application logic, so anywhere you need to recompile. I was searching the internet and it seems popular to store the configuration in a map. So I am missing something here