Enhancement - Sequence implemented

- Implemented a sequence object to handle ID sequences.
This commit is contained in:
Paul Beckingham 2009-05-23 12:26:34 -04:00
parent fbea29e27c
commit 3cdfb733de
2 changed files with 20 additions and 0 deletions

View file

@ -25,7 +25,9 @@
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <map>
#include <string> #include <string>
#include "util.h"
#include "Sequence.h" #include "Sequence.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -62,3 +64,20 @@ void Sequence::parse (const std::string& input)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Sequence::combine (const Sequence& other)
{
// Create a map using the sequence elements as keys. This will create a
// unique list, with no duplicates.
std::map <int, int> both;
foreach (i, *this) both[*i] = 0;
foreach (i, other) both[*i] = 0;
// Now make a sequence out of the keys of the map.
this->clear ();
foreach (i, both)
this->push_back (i->first);
std::sort (this->begin (), this->end ());
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -39,6 +39,7 @@ public:
~Sequence (); // Destructor ~Sequence (); // Destructor
void parse (const std::string&); void parse (const std::string&);
void combine (const Sequence&);
}; };
#endif #endif