Welcome to Config Maker home

This page describes the motivation, basic usage and installation of the Config Maker tool for C++.

Aim of the project

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:

Getting the source-code

Go to the sourceforge page

Basic usage

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)?

Type of the entry, can be int, double, string or bool. If the basic type is followed by any number, the corresponding C++ object variable will be of type vector <basic type> If there is also a default value, this value is the minimum length of the vector. If the configuration file contains less entries, the rest will be filled with default values. If there are more entries in the configuration file than default values, the vector will have exactly as many elements as specified in the configuration file. If no default value is given the vector always has exactly as many values as in the configuration file.
Name of the entry and corresponding variable. Has to be at least two characters long and can contain characters and numbers, but has to start with a character. Case insensitive.
Default value for the entry. This is optional.
Each comment starts with // and is completely ignored

An example

If you run a .cfm file through cfmake that looks like this:

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{
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);}

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:


Setting up directories and paths

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

This site is hosted by SourceForge.net Logo
Valid HTML 4.01 Strict