summaryrefslogtreecommitdiff
path: root/project2/basics/tests/isdistinct.cpp
blob: 303f88de908be753709481fc0eb43acb946bb8d6 (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
41
#include <pch.hpp>
#include <test.h>
#include <scriptLoader.h>
#include <iHaveParameters.h>
#include <boost/foreach.hpp>
#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(NULL))->registerFor(RowProcessor::Complete, boost::bind(&IsDistinct::reset, this));
		}

		bool passes(ExecContext * ec) const {
			Vars row;
			BOOST_FOREACH(const Parameters::value_type & p, parameters) {
				row.push_back(p.second(ec));
			}
			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);