Home » U++ Library support » U++ Core » Convenient work with options/properties
Convenient work with options/properties [message #15552] |
Tue, 29 April 2008 00:52 |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |
|
|
I was needed a class for handling properties lists:
Property1 = Value1
Property2 = Value2
Property3 = Value3
...
Idea was to create a class to work with such lists with minimum effort. Class should be able able to write itself to file and read it from file.
After some thinking I`ve come to it`s realization. Storage of data is handled through XML. Class supports types int, double, string and Date. Nested properties are supported too.
Example of usage:
XmlProperties props0;
props0.Add("prop1", 1);
props0.Add("prop2", 1.5);
props0.Add("prop3", "test");
XmlProperties props1;
props1.Add("id1", "ID1test");
props1.Add("id2", "ID2test");
props1.Add("id3", RawToValue(props0));
XmlProperties props;
props.AddPick("main", RawToValue(props1));
props.Add("more", 1.5);
props.Add("more2", 7);
Cout() << props;
Gives output:
<props name="main">
<string name="id1">ID1test</string>
<string name="id2">ID2test</string>
<props name="id3">
<int name="prop1">1</int>
<double name="prop2">1.5</double>
<string name="prop3">test</string>
</props>
</props>
<double name="more">1.5</double>
<int name="more2">7</int>
Of course it may be easily stored to file. Reading properties from String is easy too.
Maybe it will be handy for someone else who`s working with properties, options or any other properties-like data.
P.S. Critics and suggestions are appreciated.
[Updated on: Tue, 29 April 2008 10:37] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Thu Mar 28 13:16:36 CET 2024
Total time taken to generate the page: 0.01410 seconds
|