Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > java-like properties files (key/value)?

Reply
Thread Tools

java-like properties files (key/value)?

 
 
Markus Dehmann
Guest
Posts: n/a
 
      10-06-2005
Is there a library that supports Java-like .properties files? I have
several settings for each of my classes. So, I want to have a file like
this:

MainClass.numOfLoops = 3232 # the number of loops
MainClass.version = 0.95
OtherClass.readDirectory = /etc/passwd
OtherClass.whatever = true

The library should read and parse this and provide the values in a
global/singleton hash or so. I tried boost:rogram_options, but there
you have to define exactly which options you are expecting. It's really
for command line options for executables. I want that the user can
define all kinds of keys/values in such a file. Each class should also
be allowed to read its own .properties file. In that case, the
keys/values are only visible for that class.

I should be able to say something like:

double version = properties.get("MainClass.version").toBool();
bool whatever = properties.get("OtherClass.whatever").toDouble();

Thanks!
Markus
 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      10-06-2005
Markus Dehmann wrote:

> Is there a library that supports Java-like .properties files? I have
> several settings for each of my classes. So, I want to have a file like
> this:
>
> MainClass.numOfLoops = 3232 # the number of loops
> MainClass.version = 0.95
> OtherClass.readDirectory = /etc/passwd
> OtherClass.whatever = true
>
> The library should read and parse this and provide the values in a
> global/singleton hash or so. I tried boost:rogram_options, but there
> you have to define exactly which options you are expecting. It's really
> for command line options for executables. I want that the user can
> define all kinds of keys/values in such a file. Each class should also
> be allowed to read its own .properties file. In that case, the
> keys/values are only visible for that class.
>
> I should be able to say something like:
>
> double version = properties.get("MainClass.version").toBool();
> bool whatever = properties.get("OtherClass.whatever").toDouble();
>
> Thanks!
> Markus


What about:

#include <boost/lexical_cast.hpp>
#include <map>
#include <string>
#include <iostream>

typedef std::map< std::string, std::string > OptionMap;

int main ( void ) {
OptionMap options;

options[ "opt_1" ] = "0.95";
options[ "opt_2" ] = "1";

double opt_1_val = boost::lexical_cast< double >( options[ "opt_1" ] );
bool opt_2_val = boost::lexical_cast< bool >( options[ "opt_2" ] );

std::cout << opt_1_val << " " << opt_2_val << '\n';
}


Now, with the boolean type, you will have to work a little bit to make
"true" and "false" work.


Best

Kai-Uwe Bux
 
Reply With Quote
 
 
 
 
Matthias Kaeppler
Guest
Posts: n/a
 
      10-06-2005
Markus Dehmann wrote:
> Is there a library that supports Java-like .properties files?

Yes, try boost:rogram_options (www.boost.org). It's quite powerful.

--
Matthias Kaeppler | Tel: +49 631 3405805
Gerhart-Hauptmann-Str. 16a | Mob: +49 176 20108693
D-67663 Kaiserslautern | E-Mail: matthias at finitestate dot org
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting properties (not necessarily "Properties") in Java 5.0 Wardie Java 4 11-08-2006 09:46 AM
CompositeControls: ViewState properties w/ Mapped properties probl =?Utf-8?B?Q2hyaXN0b3BoZSBQZWlsbGV0?= ASP .Net 1 01-19-2006 09:19 AM
Making Custom Control Properties Visible in Visual Studio's Properties Palette Nathan Sokalski ASP .Net 0 10-17-2005 02:05 AM
Re: C++ properties Library Created (was Binding together Properties of Objects) Victor Porton C++ 1 08-29-2004 08:02 PM
Problems parsing when Properties.dtd.properties Kent Lichty Java 0 04-16-2004 03:08 PM



Advertisments