Hi guys
Have you noticed that there aren't many open-source libraries for parsing configuration files? I've googled for a while and found only standard WinAPI functions on Windows, and CFL library on Linux distros (but I wasn't searching very long). I thought that it would be nice, if there was open-source, portable C/C++ library for reading/writing configuration files. By "configuration files" I mean .ini files known from Win, ie.
[Foo]
bar = "this is string value"
version = 0.5 // this is float value
integer = 7
fullscreen = false // this is bool
// and this is a comment :-)
I decided to write such library... which will be called SDL_Config (shamelessly plugging into SDL fame :-) ), distributed as GNU GPL, and hosted on Sourceforge. After few days of planning, it became obvious, that there are things which should be discussed with group of potential users. And knowing that there are many advanced "potential users" here on SDL mailing list, who are very experienced in desiging library interface, I dediced to write here. Because it's interface, with what I have problems.
Questions:
-
Author of TinyXML (which is small library for parsing XML files) decided to give user ability to choose, whether: TinyXML will be using STL containers or self-made versions, and whether to use std::iostreams, or FILE. There are subtle differences between those modes, how they work. First I thought to aspire higher, and went crazy with possible ways my library could be build:
// It controls what version of function definitions will be compiled - those with or without default values.
// Not _cplusplus because someone may want to use C version in C++ project
#define PLAIN_C, C_PLUS_PLUS// Defines whether library will be build as static lib, or as DLL
#define BUILD_STATIC_LIB, BUILD_DLL// What string version use in function definitions and internally, when parsing
#define USE_C_STRINGS, USE_STD_STRINGS, USE_UNICODE_STRINGS// Include SDL.h and use typedefs there used, or include separate file, which won’t add dependencies on SDL
#define USE_SDL_TYPES, USE_OUTSIDE_TYPES// Use std::map and iterators, or my own implementation in C
#define USE_STL, USE_C_CONTAINERS// If not defined, functions that operate on bools won’t be compiled? or will be changed to ints? see next point
#define USE_BOOL// Which version of handling files to use
#define USE_STDIO_FILE, USE_IOSTREAMS// How to allocate memory on heap
#define USE_MALLOC, USE_NEW
Hmmm… quite many, right? Do you think someone would want to use this level of customizeability, knowing that none of them will change external library behavior even a bit, only internal implementation would be different, and interface would change slightly in some cases (strings that would be returned)? Or would it be better just to stick with those options that are available natively in plain C?
-
Bool type - there’s nothing like “bool” in C, and this library is going to be compiled in C. Situation clear - remove functions that operate on bools, right? Not quite, since “bool” exists in C++, so if someone decides to compile this library in C++, he should be able to use bool. Of course, #ifdefs spring to mind, but there’s also issue how to use them, and generally there are two ways:
1 -Iif _cplusplus isn’t defined, simply don’t compile functions that operate on bools.
2 - This code will tell you all:#ifdef _cplusplus
#define BOOL bool
#else
#define BOOL int
#endif
Which one do you like more? Is there any third (better) way?
- Because this library is more or less, just a bunch of plain C functions, and file state is stored in global variables, only one config file can be opened at a time. So, ie. you won’t be able to write to file “aaaa.cfg” and read from “bbbb.cfg” simultaneously - you will have to write all to “aaaa.cfg”, close it, and then open “bbbb.cfg” etc.
Well, at least is how I’m planning it now, but - if it is important to have ability to write/read many files at once - I’ll extend interface (bloating it a little). So, I ask, is it important?
- This one is easy: will you want to use such library? If there’s no interest, there’s no need to write it, simple.
Thanks in advance for answers!–
Koshmaar
<Of all the things I’'ve lost, I miss my mind the most>
GG: 3928072
http://jnr.sourceforge.net/
www.pongowar.prv.pl