Ensure uniqueness of data before creating object?
<p>I have a file full of data that I need to operate on. Each line of this file contains floating point numbers (represented as strings of course) like this:</p>

<p>x1 y1 z1 x2 y2 z2 x3 y3 z3 r1 g1 b1 r2 g2 b2 r3 g3 b3</p>

<p>each line represents 3 different objects that I need to create, like:<br>
<code>Foo foo1(x1,y1,z1,r1,g1,b1);</code><br>
<code>Foo foo2(x2,y2,z2,r2,g2,b2);</code><br>
<code>Foo foo3(x3,y3,z3,r3,g3,b3);</code></p>

<p>the twist is that:  </p>

<ol>
<li><p>I want to ONLY create objects if they haven't been created yet. if I've already made a <code>Foo</code> with those exact same 6 floats, instead of creating a new <code>Foo</code> I want to just retrieve that object I already made. </p></li>
<li><p>The data in the file is unreliably delimited -- there could be any number of spaces or tabs between the different numbers. </p></li>
</ol>

<p>Before I realized this issue with the spacing, I was splitting each line I read from the file into strings, concatenating the strings that represented each foo, and then using a <code>std::map&lt;std::string,int&gt;</code> to test for uniqueness, where the int returned by the map represented an index into a <code>std::vector&lt;Foo*&gt;</code> that I was pushing pointers to each <code>Foo</code> I was creating into. This fails when the spacing isn't consistent.  </p>

<p>all I can think of right now is doing something like:
<a href="http://codepad.org/hLhFzhPh" rel="nofollow">http://codepad.org/hLhFzhPh</a> (for example) but that seems completely screwy. I also tried making a struct of 6 floating point values, overloading <code>operator&gt;&gt;</code> to read from a stringstream into it, and then making a <code>map&lt;weirdstruct,int&gt;</code> but I didn't really know how to overload <code>operator&lt;</code> to make this work.</p>

<p>Anyway, this seems like it should be easy and I just don't have a clue. Any ideas?</p>
