This page describes the motivation, basic usage and installation of the Config Maker tool for C++.
For my work I write a lot of programs that require a bunch of variables to be inserted by the user. A lot of them are the same nearly every time the program is used, but can change occasionally. It therefore makes sense to store these values in a configuration file, that is read in when the program starts. I chose to use ANTLR to parse the files, because it makes the parsing robust and flexible. After writing the first parser, I realized that for each of my projects I would have to change the names of the identifiers and of the variables the values are stored in. I therefore decided to write a little program that automatically generates a parser file for ANTLR from a very simple input file and meets the following requirements:
Go to the sourceforge page
The input files for Config Maker have a very simple structure (in ANTLR/grep like notation):
objectname (configentry)+
Each configentry looks like this
type entryname defaultvalue (comment)?
If you run a .cfm file through cfmake that looks like this:
CConfig
int test -1// Comment
int 5 test2 10
double test3 2
string 2 test4 //Comment
bool test5
You will get a class with an interface like this:
class CConfig{
public:
void GetData(std::ifstream &instream);
void GetData(std::string filename);
void WriteData(std::ofstream & outstream);
void WriteData(std::string filename);
int test;
std::vector< int > test2;
double test3;
std::vector< std::string > test4;
bool test5;
CConfig(std::string filename){GetData(filename);}
CConfig(){}
};
That reads configuration files like this:
test3 = 5
test4 = filename2 filename //Comment
test5 = false
test2 = 1 2 3 4 5 //Comment 2
These files are also included in the distribution, so you can play around with them to understand how it works in detail.
Before installing Config Maker make sure you have the following up and running:
cfmake is now ready to run.
The subdirectory test contains a simple program and input file to test cfmake. Simply use test.cfm as an input file by either typing cfmake test.cfm or just cfmake and type test.cfm at the prompt. Compile with make test and run cfmtest. The output should correspond to the input in test.conf. This should also clarify the usage of the program.
I hope that this program is somewhat useful. Please use the sourceforge page to send bug reports/feature requests. If you want to improve the program feel free to join the development team. If you are interested in my other activities visit my personal homepage