SetQuery.h

Go to the documentation of this file.
00001 //
00002 // Copyright (c) 2003-2008 Greg Landrum and Rational Discovery LLC
00003 //
00004 //   @@ All Rights Reserved  @@
00005 //
00006 #ifndef __RD_SETQUERY_H__
00007 #define __RD_SETQUERY_H__
00008 #include <set>
00009 #include "Query.h"
00010 
00011 namespace Queries{
00012   //! \brief a Query implementing a set: arguments must 
00013   //!  one of a set of values
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     //! insert an entry into our \c set
00026     void insert(const MatchFuncArgType what){
00027       //std::cout << "SET QUERY INSERT: " << what << std::endl;
00028       if(d_set.find(what) == this->d_set.end()) this->d_set.insert(what);
00029     }
00030 
00031     //! clears our \c set
00032     void clear(){
00033       //std::cout << "SET QUERY CLEAR " << std::endl;
00034       this->d_set.clear();
00035     }
00036 
00037     bool Match(const DataFuncArgType what) const {
00038       MatchFuncArgType mfArg = TypeConvert(what,Int2Type<needsConversion>());
00039       //std::cerr << "SET QUERY SEARCH: " << mfArg << ": "  << (d_set.find(mfArg)==d_set.end()) << std::endl;
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

Generated on Sat May 24 08:36:32 2008 for RDCode by  doxygen 1.5.3