I need to read a configuration file and store its options in a data structure. For example:
And the configuration file would be:Code:struct ConfigurationFile{ int option1; int option2; double option3; };
#begin of file
this is an option = value of this option
another option = some value1, some value2, ...
...
last option = final value
#end of file
What I have done so far is not even good. I have created three structures, one for each kind of option: integer, float or array of floats. Each option has a string that represent it. Three array (one of each kind of option) are created. After reading an option I iterate through the arrays and look for the one that has the string. For example:
The problem is not to read the options and values from the file, but to store the options in the ConfigurationFile structure. There are many possible options, and a "if-else" approach would not suffice. Please, if I not explained correctly my problem I would be happy to give more details.Code:struct OpcaoInteira{ char opcao[50]; int valor; }; struct OpcaoReal{ char opcao[50]; double valor; }; struct OpcaoVetor{ char opcao[50]; double* valores; }; OpcaoInteira opInteiras[] = { {"numero aneis", 0}, {"numero aneis concentricos", 0} }; OpcaoReal opReais[] = { {"drmax", 350.e-6}, {"posicao eletrons", 200.0} }; OpcaoVetor opVetores[] = { {"ra", NULL}, {"z0", NULL} };
Any help is much appreciated.![]()



LinkBack URL
About LinkBacks



