Enhancement - Sequence implemented
- Implemented a sequence object to handle ID sequences.
This commit is contained in:
@@ -25,7 +25,9 @@
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include "util.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 ());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -39,6 +39,7 @@ public:
|
||||
~Sequence (); // Destructor
|
||||
|
||||
void parse (const std::string&);
|
||||
void combine (const Sequence&);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user