Boost C++ Libraries: Ticket #4786: custom property_tree https://svn.boost.org/trac10/ticket/4786 <p> When creating custom property_trees by using a data type different from std::string, property_tree has errors. Attached is a patch along with an implementation of a tree containing variant data type. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4786 Trac 1.4.3 saleyn@… Mon, 25 Oct 2010 18:22:02 GMT attachment set https://svn.boost.org/trac10/ticket/4786 https://svn.boost.org/trac10/ticket/4786 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost_1_44_0.property_tree.patch</span> </li> </ul> Ticket saleyn@… Mon, 25 Oct 2010 18:22:37 GMT attachment set https://svn.boost.org/trac10/ticket/4786 https://svn.boost.org/trac10/ticket/4786 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">variant_property_tree.tgz</span> </li> </ul> <p> Variant property tree </p> Ticket saleyn@… Mon, 25 Oct 2010 18:56:55 GMT attachment set https://svn.boost.org/trac10/ticket/4786 https://svn.boost.org/trac10/ticket/4786 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost_1_44_0.property_tree.2.patch</span> </li> </ul> <p> Please use this patch instead, the previous upload broke some legacy functionality. </p> Ticket viboes Sat, 27 Nov 2010 15:51:10 GMT <link>https://svn.boost.org/trac10/ticket/4786#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4786#comment:1</guid> <description> <p> Please, could you add the kind or errors you get? </p> </description> <category>Ticket</category> </item> <item> <author>Serge Aleynikov <saleyn@…></author> <pubDate>Sun, 05 Dec 2010 00:34:06 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4786#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4786#comment:2</guid> <description> <p> You can just untar the variant_property_tree.tgz and try to compile the project with latest version of property_tree to get the errors. If that's not enough, I can post the actual errors. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 20 Mar 2012 11:13:04 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4786#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4786#comment:3</guid> <description> <p> the idea looks nice. the C-style casts don't. the try/catch cascade with lexical_cast for guessing the type from string looks even more horrible, but there's nothing else to do since INFO files don't have any hints like "this property has that type" inside. it's too bad that the library maintainer didn't pay attention yet, maybe he could suggest something. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Sebastian Redl</dc:creator> <pubDate>Tue, 20 Mar 2012 15:22:45 GMT</pubDate> <title>type changed https://svn.boost.org/trac10/ticket/4786#comment:4 https://svn.boost.org/trac10/ticket/4786#comment:4 <ul> <li><strong>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Feature Requests</span> </li> </ul> <p> The INFO parser (like all other parsers) only supports string trees. That's just the way it is. I may enhance the parsers in the future. However, wildly casting pointers is *not* the way to do it. </p> <p> Marking this as a feature request. </p> Ticket saleyn Tue, 20 Mar 2012 15:32:33 GMT <link>https://svn.boost.org/trac10/ticket/4786#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4786#comment:5</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/4786#comment:4" title="Comment 4">cornedbee</a>: </p> <blockquote class="citation"> <p> The INFO parser (like all other parsers) only supports string trees. That's just the way it is. I may enhance the parsers in the future. However, wildly casting pointers is *not* the way to do it. </p> <p> Marking this as a feature request. </p> </blockquote> <p> I agree that the casts were somewhat ugly, but supporting the feature of having derived trees with typed data nodes favored by the property_tree's underlying parsing architecture would be a great add-on. I couldn't see the way of doing it cleanly in the current implementation without needing to patch it at least minimally. So if you can introduce this feature given the derived version of the variant_tree that I submitted above it would be great! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>saleyn</dc:creator> <pubDate>Tue, 20 Mar 2012 15:52:16 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4786#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4786#comment:6</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/4786#comment:3" title="Comment 3">anonymous</a>: </p> <blockquote class="citation"> <p> the idea looks nice. the C-style casts don't. the try/catch cascade with lexical_cast for guessing the type from string looks even more horrible, but there's nothing else to do since INFO files don't have any hints like "this property has that type" inside. it's too bad that the library maintainer didn't pay attention yet, maybe he could suggest something. </p> </blockquote> <p> Ideally the parsers would minimally give an ability to infer the type based on the parsed data, and provide a hint to the derived implementation so that the commonly identifiable inputs "1", "2.0", '"string"' are transformed into statically overridable calls that the transform function would be able to map into properly typed objects, e.g.: </p> <p> enum hint_t {UNDEFINED, INT, FLOAT, STRING}; </p> <p> std::pair&lt;std::basic_string&lt;Ch&gt;, hint_t&gt; raw_data = read_data(text, &amp;need_more_lines); typename Ptree::data_type typed_data = transform_data(raw_data); last.data() = typed_data; </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 21 Mar 2012 10:07:49 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4786#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4786#comment:7</guid> <description> <p> that last idea of guessing the type by its looks sounds dangerous to me. it may prove even worse than the try/catch/lexical_cast cascade. it's better to provide a way to supply some "schema" to the parser so he would know each property's type. explicit is better than implicit, as they say. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Sebastian Redl</dc:creator> <pubDate>Wed, 21 Mar 2012 10:38:42 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4786#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4786#comment:8</guid> <description> <p> I can see the point in making the JSON parser variant-tree-aware. JSON is already typed, after all, and the current parser throws away information. </p> <p> But all this talk about how to shoehorn INFO into a typed tree doesn't make sense to me. INFO is not any official format. It was invented by the original PTree author specifically for string ptrees. If you want types, then why not just adjust the format to allow type annotations? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>saleyn</dc:creator> <pubDate>Wed, 21 Mar 2012 13:28:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4786#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4786#comment:9</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/4786#comment:7" title="Comment 7">anonymous</a>: </p> <blockquote class="citation"> <p> that last idea of guessing the type by its looks sounds dangerous to me. it may prove even worse than the try/catch/lexical_cast cascade. it's better to provide a way to supply some "schema" to the parser so he would know each property's type. explicit is better than implicit, as they say. </p> </blockquote> <p> Agree. The explicit schema would be a much better solution. Especially if that schema can be uniformly adapted across all ptree's parsers. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>saleyn</dc:creator> <pubDate>Wed, 21 Mar 2012 13:40:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4786#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4786#comment:10</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/4786#comment:8" title="Comment 8">cornedbee</a>: </p> <blockquote class="citation"> <p> I can see the point in making the JSON parser variant-tree-aware. JSON is already typed, after all, and the current parser throws away information. </p> <p> But all this talk about how to shoehorn INFO into a typed tree doesn't make sense to me. INFO is not any official format. It was invented by the original PTree author specifically for string ptrees. If you want types, then why not just adjust the format to allow type annotations? </p> </blockquote> <p> IMHO, INFO is a very succinct and convenient format. It's conceptually very similar to Erlang term encoding format, which is quite popular. In fact most of dynamically typed languages use standard implicit rules to parse 1234 as integers, 234.5 or 2.345e2 as floats, "1234" as strings, and true or false as booleans (just like JSON protocol does, except that it doesn't distinguish integers from floats and treats them as "number"). So, adapting that idea to the INFO parser so that it can use a custom translator to allow a user to take advantage of that extra metadata wouldn't be that bad. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>saleyn</dc:creator> <pubDate>Wed, 21 Mar 2012 20:04:17 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4786#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4786#comment:11</guid> <description> <p> For what it's worth, I converted the variant tree example to the latest boost version 1.49.0, and it turned out that there's a way to get it working without a need for patching the source. The latest example is uploaded as attachment. </p> <p> Following this thread I do like the schema idea, but this is definitely not a bug request. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>saleyn</dc:creator> <pubDate>Wed, 21 Mar 2012 20:05:23 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/4786 https://svn.boost.org/trac10/ticket/4786 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">variant_property_tree-1_49_0.tgz</span> </li> </ul> <p> Sample of a variant property tree with typed node data (boost version 1_49_0 </p> Ticket anonymous Fri, 13 Apr 2012 10:29:25 GMT <link>https://svn.boost.org/trac10/ticket/4786#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4786#comment:12</guid> <description> <p> Some way to specify a custom default translator in basic_ptree would be really useful. I'm talking about the last example. That inheritance from basic_ptree with all those handcrafted member functions looks cumbersome (and also somewhat dangerous - there's no virtual destructor in basic_tree). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 26 Apr 2012 07:45:22 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4786#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4786#comment:13</guid> <description> <p> a few more notes regarding your example. util::detail::variant_translator::get_value seems to lack support for converting the internal value to std::string (except for the case when its type is also std::string). and if you pass std::string to util::detail::variant_translator::put_value, it looks like it will just replace the internal value with the supplied string, changing its type to std::string, not converting the string to the current internal type. maybe it's better to add util::detail::variant_translator&lt;std::string&gt; specialization to improve this. correct me if I've missed anything. :) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>saleyn</dc:creator> <pubDate>Thu, 26 Apr 2012 10:39:28 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/4786 https://svn.boost.org/trac10/ticket/4786 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">variant_tree_boost_1_49_0.tgz</span> </li> </ul> <p> Version working without needing to patch boost </p> Ticket saleyn Thu, 26 Apr 2012 10:52:14 GMT <link>https://svn.boost.org/trac10/ticket/4786#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4786#comment:14</guid> <description> <p> Upon checking my last submission, I noticed that I uploaded a stale version which still didn't work without patching the tree. variant_tree_boost_1_49_0.tgz solves that problem. The work-around was to apply a "post-conversion" transform after reading data from the info file to convert strings to corresponding variant types. </p> <p> Concerning the last comment, the variant_translator has the following code that makes sure that std::string is one of the types it handles (variant::valid_types type includes std::string): </p> <pre class="wiki"> template&lt;typename T&gt; typename boost::disable_if&lt; boost::is_same&lt; boost::mpl::end&lt;valid_types&gt;::type, boost::mpl::find&lt;variant::valid_types, T&gt; &gt;, internal_type&gt;::type put_value(T value) const { return variant(value); } </pre><p> Since variant_tree::put_value(value) uses default translator, it should be able to handle std::string conversion. If you don't believe it does, please include a test case in the test_variant.cpp that illustrates a failing case. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 27 Apr 2012 06:23:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4786#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4786#comment:15</guid> <description> <p> hmm, well, I see a two-argument variant constructor that calls from_string (this seems to be the only place where the conversion from string takes place), but I can't figure out where is that constructor used :) </p> </description> <category>Ticket</category> </item> </channel> </rss>