Home » Community » Newbie corner » Initial settings for U++ application
Re: Initial settings for U++ application [message #27293 is a reply to message #27288] |
Sun, 11 July 2010 10:40   |
|
Hi Neil,
Some time ago I write a simple class for similar purpose. I actually used it even for other things, like passing large number of parameters to a function.
It saves key-value pairs as strings. So you have to make all the conversions yourself, but if you have low number of options to save it should not be a problem.
The interface is simple, you will probably need only few functions:
config cfg(filename); //constructor which loads a file
cfg.Load(filename); //load a file into existing config object
cfg.Get(key,default); //get the value from underlaying file
cfg(key,default); //same as Get(), shortcut
cfg.Set(key,value); //store value to config object
cfg.Save(); //write the stored values to the file
It has even some more capabilities, like saving arrays and tables (2D arrays), but based on your description you won't need that. The resulting file is human readable and supports comments (#).
I never had time to really polish it, so it might not follow the U++ coding style. Also, there might be some bugs, since I just quickly stripped out some of my app specific stuff. But don't be afraid, even though this disclaimer, it should do the job 
Small example of usage is enclosed with the class.
Bye,
Honza
-
Attachment: config.zip
(Size: 6.96KB, Downloaded 257 times)
|
|
|
Goto Forum:
Current Time: Sat Jun 21 22:03:04 CEST 2025
Total time taken to generate the page: 0.02930 seconds
|