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