What library functionality would you most like to see in D?
Alex Rønne Petersen
xtzgzorex at gmail.com
Sun Jul 31 03:24:38 PDT 2011
On 31-07-2011 12:09, Anders Ahlstr�m wrote:
> == Quote from Alex Rønne Petersen (xtzgzorex at gmail.com)'s article
>> On 31-07-2011 11:30, Anders Ahlstr�m wrote:
>>>> I'm new to D, but I guess I might be able to develop some sort of configuration
>>>> file library (supporting reading and writing values etc.). Do you guys have some
>>>> sort of preferences or should I just go with standard INI files?
>>>>
>>>> AFAIK, D supports XML already, which can be used for configuration files, but
>>>> sometimes something simpler can be convenient.
>> On 31-07-2011 11:44, Mirko Pilger wrote:
>>>> I'm new to D, but I guess I might be able to develop some sort of
>>>> configuration
>>>> file library (supporting reading and writing values etc.). Do you guys
>>>> have some
>>>> sort of preferences or should I just go with standard INI files?
>>>
>>> maybe boost::property_tree could be of some inspiration here:
>>>
>>> http://www.boost.org/doc/libs/1_47_0/doc/html/property_tree.html
>>>
>> That seems like a good idea! As the doc page suggests, we could store
>> configuration in XML, JSON, INI, or whatever people would want to use in
>> their application. Phobos AFAIK has facilities for JSON and XML. Not
>> sure about INI, though.
>> - Alex
>
> The property tree is independent of the underlying format, isn't it? What is
> needed is a property tree, and then a bunch of parsers each returning a property
> tree and being able to write it back to disk. The property tree doesn't even have
> to know if it is an INI file or an XML file it is editing, which is kind of cool,
> and flexible.
Yes, indeed. It would be interesting, though, if we could utilize D's
compile-time reflection to generate the parsing code instead of reading
values by hand.
Suppose I have some configuration like:
class MainConfig
{
string ip;
int port;
class UserConfig
{
int accessLevel;
string password;
}
UserConfig[string] usernameToConfigMappings;
}
It would be nice if I could then say:
Config config = new XmlParser().ReadTree!MainConfig();
and it would automagically figure out how to map the resulting data to
an instance of MainConfig.
The config file could look like this in XML:
<node name="ip">127.0.0.1</node>
<node name="port">65535</node>
<child name="usernameToConfigMappings">
<node name="joe">
<node name="accessLevel">1234</node>
<node name="password">asdf</node>
</node>
<node name="alice">
...
</node>
...
</child>
or something like that, if I'm reading the property trees docs right...
- Alex
More information about the Digitalmars-d
mailing list