Applications sometimes need to store variables between executions.
For example screen resolution chosen by client, or his favourite 3D acceleration driver, etc...
Apache, Samba, PHP, Half-Life... They do load their config with the method i am going to show here.
You all know this format:
- a text file
- a serie of pairs name/value separated by a '='
- comments are marked with '#'
- no sections
This method is older than XML, and used by 90% of linux professional apps.
Although XML benefits of several open-source librairies to parse it, I still find the ".conf" way :
- more flexible than XML (possibility to add comments with #)
- Smaller files than XML
- clear display (no tags)
- easy to edit manually
- portable, unlike INI files.
But don't get me wrong, it's mainly a question of personnal taste.Everyone does the way he wants, Free as in Freedom. For bigger structures, the binary in/out is better (as used by the bsp format for example).
In all cases, the parser has to read the file from beginning to the End Of File.
---------------------
Let's see directly how to use it.
Add the 5 files in your project directory:
config.cpp
config.h
exception.h
file.cpp
file.h
In your project, add
Code: Select all
#include <iostream>
#include "config.h"Code: Select all
Config myconf;Code: Select all
myconf.addConfigFile("config/cfg.conf");
myconf.addConfigFile("../config/server.cfg");Code: Select all
cout << "nick is: " << c->getEntry("nick") << endl;See this Dev-CPP example project, although it shouldn't be hard to use it somewhere else!
You can implement this easily in your Irrlicht projects.