Properties File Library for C (Or C++)

Properties file library for C (or C++)

STLSoft's 1.10 alpha contains a platformstl::properties_file class. It can be used to read from a file:

using platformstl::properties_file;

properties_file properties("stuff.properties");

properties_file::value_type value = properties["name"];

or from memory:

properties_file  properties(
"name0=value1\n name1 value1 \n name\\ 2 : value\\ 2 ",
properties_file::contents);

properties_file::value_type value0 = properties["name0"];

properties_file::value_type value1 = properties["name1"];

properties_file::value_type value2 = properties["name 2"];

Looks like the latest 1.10 release has a bunch of comprehensive unit-tests, and that they've upgraded the class to handle all the rules and examples given in the Java documentation.

The only apparent rub is that the value_type is an instance of stlsoft::basic_string_view (described in this Dr Dobb's article), which is somewhat similar to std::string, but doesn't actually own its memory. Presumably they do this to avoid unneccessary allocations, presumably for performance reasons, which is something the STLSoft design holds dear. But it means that you can't just write

std::string  value0 = properties["name0"];

You can, however, do this:

std::string  value0 = properties["name0"].c_str();

and this:

std::cout << properties["name0"];

I'm not sure I agree with this design decision, since how likely is it that reading properties - from file or from memory - is going to need the absolute last cycle. I think they should change it to use std::string by default, and then use the "string view" if explicitly required.

Other than that, the properties_file class looks like it does the trick.

Properties file in python (similar to Java Properties)

For .ini files there is the configparser module that provides a format compatible with .ini files.

Anyway there's nothing available for parsing complete .properties files, when I have to do that I simply use jython (I'm talking about scripting).

Parsing a Java Properties file in Objective-C for iPhone

I would take a look at ParseKit http://parsekit.com/. Otherwise you could use RegexKitLite and create some regular expressions.

Properties of an audio file using C from the taglib library functions

One can first check the location of the header file 'tag_c.h'. In my system, it's path was '/usr/include/taglib' hence I had to modify the include header to:

#include <taglib/tag_c.h>

Then compile your your code by linking it with tag library using the command:

gcc -Wall tag.c -L/usr/include/taglib -ltag_c

Java .properties files as strongly typed classes

There is a somewhat similar project for doing configuration as statically typed files. It requires to declare an interface, but it fills in the implementation itself:

public interface AppConfig extends Config {
long getTimeout ();
URL getURL ();
Class getHandlerClass ();
}


Related Topics



Leave a reply



Submit