プロジェクトでブーストptreeを使用したいのですが、ptree.hppによって約1000個のヘッダーファイルがインクルードされるため、コンパイル時間が大幅に増加し(たとえば、1秒から7秒)、20を超える異なるcppファイルで必要になるため、これはそうではありません。許容範囲内(プリコンパイル済みヘッダーはあまり改善されません)。だから私は自分のクラスにブーストptreeをカプセル化することを考えています
// 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;
};
しかし、私はイテレータをうまく実装できていません。理想的には、boost::property_tree::ptree::iterator
をプライベートメンバー変数としてm_tree
使用し、それを自分のメンバー関数を使用して繰り返すことができるようにしたいのですが、内部クラスを前方宣言するにはどうすればよいですか?これは一般的に不可能です。このクラス内にイテレータを実装するエレガントな方法はありますか?