Subject: Re: [Boost-bugs] [Boost C++ Libraries] #5588: property_tree INFO include directive
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-12-01 23:02:44
#5588: property_tree INFO include directive
---------------------------------+------------------------------------------
Reporter: sarum9in@⦠| Owner: cornedbee
Type: Bugs | Status: new
Milestone: To Be Determined | Component: property_tree
Version: Boost 1.46.1 | Severity: Problem
Resolution: | Keywords:
---------------------------------+------------------------------------------
Comment (by Filippov Aleksey <sarum9in@â¦>):
While I was changing current implementation I went to the following
architecture:
We can implement event-like class that will receive the following events:
enter(std::string) and exit(),
also this class will provide a query method: resolve(std::string) ->
std::string.
We can use this in the following way: let's introduce new template
argument to every read_info function named PathResolver.
Such functions will accept PathResolver instances as their last argument:
{{{
template<class Ptree, class Ch, class PathResolver>
void read_info(std::basic_istream<Ch> &stream, Ptree &pt,
PathResolver &path_resolver)
{
//...
}
}}}
We should also provide overloads with old interface for every such
read_info function:
{{{
template<class Ptree, class Ch>
void read_info(std::basic_istream<Ch> &stream, Ptree &pt)
{
default_path_resolver pr;
read_info(stream, pt, pr);
}
}}}
Let's reimplement read_info_internal in the following way:
{{{
template<class Ptree, class Ch, class PathResolver>
void read_info_internal(std::basic_istream<Ch> &stream,
Ptree &pt,
const std::string &filename,
PathResolver &path_resolver,
int include_depth)
{
//...
std::basic_ifstream<Ch> inc_stream(
path_resolver.resolve(inc_name.c_str()));
//...
path_resolver.enter(inc_name);
read_info_internal(/*...*/);
path_resolver.exit();
//...
}
}}}
There is a case when we do not know the real file name, for example if
user passes std::istream-like object. In that case PathResolver has to
implement enter() method (without arguments).
As you has noticed, I used non-const references in code. In my opinion it
should be done in that way because PathResolver can have inner state.
It is much simplier and efficientlier to pass object by reference rather
than implementing inner share-state for (PathResolver path_resolver)
signature
or (const PathResolver &path_resolver) one. Please note, that my changes
will not break any legacy code. I have provided old-style
overloads with default_path_resolver.
I do not think this changes are completed. I tried to show you only idea.
My code is still
unchecked and probably have bugs.
One question I have: how user should access standard path resolvers?
Should we export them like read_info functions to boost::property_tree
namespace?
Or should we do something else?
P.S.
In my opinion publishing code that is being at developing stage only to
bugtracker is not a good idea.
I have created public git repository to share my code, if you can't watch
it through git, I have created a patch.
git repository is located at
[http://cs.istu.ru/gitweb/?p=boost.git;a=summary].
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/5588#comment:4> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:07 UTC