I would like to use boost ptree in my project, but since ptree.hpp calls about 1000 header files to be included, it increases compilation time (for example, from 1 to 7 seconds) and, as necessary, in more than 20 different files cpp is unacceptable (precompiled headers do nothing better). So I'm thinking of encapsulating boost ptree in my class, something like
// myptree.h #include <boost/property_tree/ptree_fwd.hpp> class myptree { private: boost::property_tree::ptree *m_tree; public: ... // adding new (single value) members to the the tree void put(const std::string&, double); void put(const std::string&, int); void put(const std::string&, const std::string&); // returning (single value) members of the tree double get_double(const std::string&) const; int get_int(const std::string&) const; std::string get_str(const std::string&) const; // working with subtrees void push_back(const std::string&, const myptree&); myptree get_child(const std::string&) const; // import/export void read_from_json(const std::string&); void write_to_json(const std::string&) const; };
However, I cannot implement an iterator in a beautiful way. Ideally, I would like to have boost::property_tree::ptree::iterator as a private member variable, which could then be repeated through m_tree using my own member functions, but as I understand from How to forward an inner class declaration? this is generally impossible. Any elegant ways to implement an iterator in this class?
source share