473,513 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

java-like properties files (key/value)?

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::program_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
Oct 6 '05 #1
2 5570
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::program_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
Oct 6 '05 #2
Markus Dehmann wrote:
Is there a library that supports Java-like .properties files?

Yes, try boost::program_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
Oct 6 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
6785
by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what...
1
6900
by: ptaz | last post by:
Hi I'm trying to run a web page but I get the following error. Ca anyone please tell me a solution to this. Thanks Ptaz HTTP Status 500 - type Exception report
0
2823
by: Markus Wollny | last post by:
Hello! When I try to run ./configure --with-java, it complains that ant doesn't work. However ant is installed, as is the latest Java SDK 1.4.2 from sun, PATH and JAVA_HOME are set correctly; ...
0
5640
by: mailkhurana | last post by:
Hii , I am trying to use a type 2 driver to connect to DB2 0n AIX 5 I have a small java test to class to establish a conneciton with the db .. I am NOT using WAS or any appserver When I try to...
12
5894
by: Mark Fink | last post by:
I wrote a Jython class that inherits from a Java class and (thats the plan) overrides one method. Everything should stay the same. If I run this nothing happens whereas if I run the Java class it...
0
3251
by: jaywak | last post by:
Just tried running some code on Linux (2.4.21-32.0.1.EL and Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)) and Windows XPSP2 (with Java HotSpot(TM) Client VM (build...
0
3237
oll3i
by: oll3i | last post by:
package library.common; import java.sql.ResultSet; public interface LibraryInterface { public ResultSet getBookByAuthor(String author); public ResultSet getBookByName(String name);
7
1965
oll3i
by: oll3i | last post by:
i need to write publisher subscriber application on openjms and use db4o but i dont know how do i add the references to db4o when i compile the app with javac ? i added db4o-6.1-java5.jar to my...
0
1992
by: JAYROO5245 | last post by:
Hi, We are running Weblogic in a clustered environment (2 servers), Citrix as our presentation servers (2) and Oracle as our database backend. We are getting this stacktrace... ...
0
7394
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7123
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5701
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4756
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.