Opened 9 years ago

Last modified 7 years ago

#9495 new Patches

property_tree json_read should accept iterators instead of just streams

Reported by: Egbert van der Wal <ewal@…> Owned by: Sebastian Redl
Milestone: To Be Determined Component: property_tree
Version: Boost Development Trunk Severity: Optimization
Keywords: Cc:

Description

For a project I am using boost::property_tree abundantly. The trees need to be transfered across all kinds of interfaces and I have ran the limited function call several times.

It requires a istream to read from. To make matters worse, as soon as it enters the function, a complete copy is made to a vector. And that happens when I already had to make a copy because the read_json method expects to consume all input data, which rarely happens for me. I know the exact beginning and ending position in the stream, but there is no way to specify this.

The following function signature would be prefered:

 template<typename Iterator, class Ptree>
    void read_json_internal(Iterator begin,
                            Iterator end,
                            Ptree &pt,
                            const std::string &filename)

This signature could still be used by the existing read_json_internal, which first converts this to a vector and then passed the vector iterators begin and and to this function, to avoid code duplication.

Of course, the proper front-end in json_parser.hpp needs to be added to.

The benefit is that this method can operate directly on my input sequence where I can specify exactly where the JSON states and where the JSON ends, avoiding all copies completely.

I will attach a patch based on SVN Trunk that will accomplish this.

Attachments (1)

boost_property_tree.patch (4.8 KB ) - added by Egbert van der Wal <ewal@…> 9 years ago.
Patch to add a iterator accepting variant of boost::property_tree::read_json

Download all attachments as: .zip

Change History (3)

by Egbert van der Wal <ewal@…>, 9 years ago

Attachment: boost_property_tree.patch added

Patch to add a iterator accepting variant of boost::property_tree::read_json

comment:1 by anonymous, 9 years ago

Any idea when/if this will be merged for a new Boost release?

comment:2 by Sebastian Redl, 7 years ago

I rewrote the JSON parser. The new parser is completely iterator-based. I will soon define a front-end to make it possible to parse from iterators without reaching into the detail namespace.

Note: See TracTickets for help on using tickets.