summaryrefslogtreecommitdiff
path: root/project2/common/tests/isdistinct.cpp
blob: b754d2dad6440056b59357a6688b74329a660af6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <pch.hpp>
#include "../test.h"
#include "../scriptLoader.h"
#include "../iHaveParameters.h"
#include "../rowProcessor.h"

class IsDistinct : public Test, IHaveParameters {
	public:
		IsDistinct(ScriptNodePtr s) :
			SourceObject(s),
			Test(s),
			IHaveParameters(s),
			scope(s, "scope")
		{
		}
		
		void loadComplete(const CommonObjects *)
		{
			findComponent(scope())->registerFor(RowProcessor::Complete, boost::bind(&IsDistinct::reset, this));
		}

		bool passes() const {
			Vars row;
			BOOST_FOREACH(const Parameters::value_type & p, parameters) {
				row.push_back(p.second());
			}
			return previous.insert(row).second;
		}
		
		void reset() const {
			previous.clear();
		}

	private:
		Variable scope;
		typedef std::vector<VariableType> Vars;
		typedef std::set<Vars> Rows;
		mutable Rows previous;
};
DECLARE_LOADER("isdistinct", IsDistinct);