]> git.tdb.fi Git - poefilter.git/commitdiff
Remove duplicates when merging choice conditions
authorMikko Rasa <tdb@tdb.fi>
Fri, 17 Aug 2018 15:49:27 +0000 (18:49 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 17 Aug 2018 15:49:27 +0000 (18:49 +0300)
source/choicecondition.h

index 91b5e71aa5e58bbc22ead2df8cf8a54bbc7ca7b8..c2f7f0e66875bf465721574ff4cf244af3605ca4 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef CHOICECONDITION_H_
 #define CHOICECONDITION_H_
 
+#include <msp/core/algorithm.h>
 #include "condition.h"
 #include "filter.h"
 
@@ -71,14 +72,13 @@ ChoiceCondition<T> *ChoiceCondition<T>::merge(const std::vector<Condition *> &co
 {
        if(dynamic_cast<const OrCondition *>(&parent) && !conditions.empty())
        {
-               ChoiceCondition<T> *result = 0;
+               ChoiceCondition<T> *result = new ChoiceCondition<T>(std::vector<Type>());
                for(std::vector<Condition *>::const_iterator i=conditions.begin(); i!=conditions.end(); ++i)
                {
                        const std::vector<Type> &v = static_cast<ChoiceCondition<T> *>(*i)->values;
-                       if(!result)
-                               result = new ChoiceCondition<T>(v);
-                       else
-                               result->values.insert(result->values.end(), v.begin(), v.end());
+                       for(typename std::vector<Type>::const_iterator j=v.begin(); j!=v.end(); ++j)
+                               if(Msp::find(result->values, *j)==result->values.end())
+                                       result->values.push_back(*j);
                }
                return result;
        }