From 3cdfb733de9398e6cc5be37108047fa9ba4c787c Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 23 May 2009 12:26:34 -0400 Subject: [PATCH] Enhancement - Sequence implemented - Implemented a sequence object to handle ID sequences. --- src/objects/Sequence.cpp | 19 +++++++++++++++++++ src/objects/Sequence.h | 1 + 2 files changed, 20 insertions(+) diff --git a/src/objects/Sequence.cpp b/src/objects/Sequence.cpp index 4c6bcf7f7..ca06f3be4 100644 --- a/src/objects/Sequence.cpp +++ b/src/objects/Sequence.cpp @@ -25,7 +25,9 @@ // //////////////////////////////////////////////////////////////////////////////// +#include #include +#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 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 ()); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/objects/Sequence.h b/src/objects/Sequence.h index eb2abbee6..85f417a2f 100644 --- a/src/objects/Sequence.h +++ b/src/objects/Sequence.h @@ -39,6 +39,7 @@ public: ~Sequence (); // Destructor void parse (const std::string&); + void combine (const Sequence&); }; #endif