title: Setting up boost property_tree for a custom path type
body: <p>I need to use boost::property_tree in my program. Right now I'm having hard time trying to figure out how to use it with a custom path type. The path type I want to have is <code>Framework::CommonClientServer::InterfacePathChain_t</code> </p>
  
  <p>which is typedef'ed like this:</p>
  
  <pre><code>typedef std::vector&lt;InterfaceID_t&gt; InterfacePathChain_t;
  typedef int InterfaceID_t;
  </code></pre>
  
  <p>So basically the path type should be <code>std::vector&lt;int&gt;</code>.</p>
  
  <p>For example: </p>
  
  <pre><code>     0
      / \
     1   2
    /   / \
   3   4   5
  </code></pre>
  
  <p>These nodes will have the following paths:</p>
  
  <pre><code>0: {0}
  1: {0, 0}
  2: {0, 1}
  3: {0, 0, 0}
  4: {0, 1, 0}
  5: {0, 1, 1}
  </code></pre>
  
  <p>I've defined the <code>path_of</code> struct in the following way:</p>
  
  <pre><code>namespace boost { namespace property_tree {
  template&lt;&gt; class path_of&lt;Framework::CommonClientServer::InterfacePathChain_t&gt;
  {
  public:
  
      typedef Framework::CommonClientServer::InterfacePathChain_t key_type;
  
      struct type 
      {
          key_type path;  
      public:
          type(key_type pathVal)
          {
              path = pathVal;
          }
  
          std::string dump() const    
          {
              std::ostringstream oss;
              if (path.size() &gt; 0)
              {
                  key_type::const_iterator it = path.begin();
                  oss &lt;&lt; *it;
                  ++it;
                  while(it != path.end())
                  {
                      oss &lt;&lt; '.' &lt;&lt; *it;
                      ++it;
                  };
              }
              return oss.str();
          }
  
          bool empty() const  
          {
              return path.size() == 0;
          }
  
          key_type reduce()   
          {
              key_type res;
              res.push_back(*path.begin());
              path.erase(path.begin());
              return res;
          }
  
          bool single() const 
          {
              return path.size() == 1;
          }
      };
  };
  }}
  </code></pre>
  
  <p>After that I tried adding 2 nodes with different paths and IDs to the tree, but it doesn't seem to work. Actually, the first node is being added with the id I set (the path is {0}). But the second node (path is {0, 0} so it's supposed to be a child for node1) doesn't seem to be added. When I try to iterate through the tree, this happens:</p>
  
  <pre><code>MetaStorageTree tree;
  Framework::CommonClientServer::InterfacePathChain_t path;
  path.push_back(0);
  MetaStorageTreeNode* node = new MetaStorageTreeNode(1);
  tree.put(path, node);
  Framework::CommonClientServer::InterfacePathChain_t path1;
  path1.push_back(0);
  path1.push_back(0);
  MetaStorageTreeNode* node1 = new MetaStorageTreeNode(2);
  tree.put(path1, node);
  for (auto it : tree)
      {
          for (int i = 0; i &lt; it.first.size(); i++)
          {
              std::cout &lt;&lt; it.first[i];
          }
          std::cout &lt;&lt; std::endl;
          if (it.second.empty()) //this returns true so node1 does not have a child
          {
              std::cout &lt;&lt; "empty" &lt;&lt; std::endl;
          }
      }
  </code></pre>
  
  <p>I believe I did something wrong with typedef'ing all the things in boost::property_tree I needed, but couldn't find any sufficient information on the topic, since most use of property_tree is dedicated to JSON parsing so standard std::string path type is used.</p>