See what's going on with flipcode!




This section of the archives stores flipcode's complete Developer Toolbox collection, featuring a variety of mini-articles and source code contributions from our readers.

 

  Configuration File Parser
  Submitted by



Confix is a full featured configuration file parser I wrote some time ago. The configuration file's structure is presented as a simple object model and can be easily manipulated (eg. changing settings, moving variables to different sections, and so on).

To set it apart from existing libraries, I included these features:
  • Bullet proof parser (try parsing your windows folder!)
  • Does not reformat the configuration file on changes
  • Recognizes three kinds of comments
  • Support for multi-line strings with escape sequences


  • Here's a little example of what you could do:

    int main(void) {
     CConfigFile CFG("# Simple configuration file\n"
                     "Test = 123          // With comments\n"
                     "String = Hello"
                     "\n"
                     "[Section        ]\n"
                     "String = World\n"
                     "Test = 123.456\n";);

    // Reading variables cout << "Global entries: " << CFG.getSection(0).getNumVariables() << endl; cout << "Value of Test: " <<

    CFG.getSection(0).getVariable("Test").getLong() << endl; // Changing CFG.getSection(0).getVariable("Test") = 456; CFG.getSection("Section").setName("NewName");

    // Removing / adding CFG.getSection(0).removeVariable("String"); CFG.getSection("NewName").addVariable(CConfigVariable("String = Hello")); }



    Some people may be offended by my usage of hungarian notation, but it will only hit you in form of the class names (CConfigFile, CConfigSection). The parser also wasn't generated by flex or another common tool, but handcrafted in order to provide maximum compatibility, flexibility and speed.

    The entire library is documented using doxygen comments and for windows users, an MSVC 6.0 workspace and CHM help file is included in the download. The code is released under the IBM common public license - in short you can do anything except to re-release it under your name or sue me :D Contact: confix@spam.lunaticsystems.de (remove the spam.)
    -Markus-

    Download Associated File: Confix-1.0.0.zip (144,307 bytes)

    The zip file viewer built into the Developer Toolbox made use of the zlib library, as well as the zlibdll source additions.

     

    Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
    Please read our Terms, Conditions, and Privacy information.