SetQuery.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006 #ifndef __RD_SETQUERY_H__
00007 #define __RD_SETQUERY_H__
00008 #include <set>
00009 #include "Query.h"
00010
00011 namespace Queries{
00012
00013
00014
00015 template <class MatchFuncArgType, class DataFuncArgType=MatchFuncArgType,
00016 bool needsConversion=false>
00017 class SetQuery :
00018 public Query<MatchFuncArgType, DataFuncArgType,needsConversion> {
00019
00020 public:
00021 typedef std::set<MatchFuncArgType> CONTAINER_TYPE;
00022
00023 SetQuery() : Query<MatchFuncArgType,DataFuncArgType,needsConversion>() {};
00024
00025
00026 void insert(const MatchFuncArgType what){
00027
00028 if(d_set.find(what) == this->d_set.end()) this->d_set.insert(what);
00029 }
00030
00031
00032 void clear(){
00033
00034 this->d_set.clear();
00035 }
00036
00037 bool Match(const DataFuncArgType what) const {
00038 MatchFuncArgType mfArg = TypeConvert(what,Int2Type<needsConversion>());
00039
00040 return ( this->d_set.find(mfArg) != this->d_set.end() ) ^ this->getNegation();
00041 };
00042
00043 Query<MatchFuncArgType,DataFuncArgType,needsConversion> *
00044 copy( ) const {
00045 SetQuery<MatchFuncArgType,DataFuncArgType,needsConversion> *res =
00046 new SetQuery<MatchFuncArgType,DataFuncArgType,needsConversion>();
00047 res->setDataFunc(this->d_dataFunc);
00048 typename std::set<MatchFuncArgType>::const_iterator i;
00049 for(i=this->d_set.begin();
00050 i!=this->d_set.end();
00051 ++i){
00052 res->insert(*i);
00053 }
00054 res->setNegation(this->getNegation());
00055 res->d_description = this->d_description;
00056 return res;
00057 };
00058
00059 typename CONTAINER_TYPE::const_iterator beginSet() const {
00060 return d_set.begin();
00061 };
00062 typename CONTAINER_TYPE::const_iterator endSet() const {
00063 return d_set.end();
00064 };
00065 unsigned int size() const {
00066 return d_set.size();
00067 };
00068
00069 protected:
00070 CONTAINER_TYPE d_set;
00071 };
00072
00073 }
00074 #endif