title: c++ programmatically efficient method to store an index that holds depth information
body: <p>I have an XML file and a library (to which I have no access) that reads the contents. This library unfortunately returns a "flattened" version of the contents of the XML file, thus obliterating the "depth" information that the XML file contains.</p>
  
  <p>for example this xml file has the following "entries".</p>
  
  <pre><code>&lt;msg&gt;
      &lt;type 0&gt;
      &lt;struct nelem=2&gt;
          &lt;type 1&gt;
          &lt;type 2&gt;
      &lt;/struct&gt;
      &lt;type 3&gt;
      &lt;struct nelem=3&gt;
          &lt;type 4&gt;
          &lt;struct nelem=1&gt;
              &lt;type 5&gt;
          &lt;/struct&gt;
          &lt;type 6&gt;
      &lt;/struct&gt;
  &lt;/msg&gt;
  </code></pre>
  
  <p>will be returned,through a <code>Entry getNextElement()</code> method, as</p>
  
  <pre><code>type 0, 
  struct(elem_num=2), 
  type 1, 
  type 2, 
  type 3,
  struct(elem_num=3),
  type 4,
  struct(elem_num=1),
  type 5,
  type 6,
  </code></pre>
  
  <p>which I save in an <code>std::vector&lt;entries&gt;</code>.</p>
  
  <p>So I have the necessary info to reconstruct the XML structure. The question is what is more appropriate and how attach the indexing info to the "entry" structure.</p>
  
  <p>I was thinking of attaching an index (groupID) that contains the depth info like so:</p>
  
  <pre><code>&lt;msg&gt;                         
      &lt;type 0&gt;                    1
      &lt;struct nelem=2&gt;            2
          &lt;type 1&gt;                2.1
          &lt;type 2&gt;                2.2
      &lt;/struct&gt;
      &lt;type 3&gt;                    3
      &lt;struct nelem=3&gt;            4
          &lt;type 4&gt;                4.1
          &lt;struct nelem=1&gt;        4.2
              &lt;type 5&gt;            4.2.1
          &lt;/struct&gt;
          &lt;type 6&gt;                4.3
      &lt;/struct&gt;
  &lt;/msg&gt;
  </code></pre>
  
  <p>I also want to implement a requesting mechanism to ask for a specific group of these entries. If I ask for "2", I should get "2.1" and 2.2" returned. Likewise when I ask for "4.2" I should get "4.2.1" returned. 
  More or less the method should have the following declaration</p>
  
  <pre><code>vector&lt;entries&gt; getGroupOfEntries(const groupID);
  </code></pre>
  
  <p>I am not sure how to implement groupID in order to be able to use in the end an <code>std::map&lt;groupID, entry*&gt;</code>. Is there a way to do that when the depth is variable? Is there a completely different approach that I am unaware of ?</p>
  
  <p>thank you for your help</p>