OrQuery.h

Go to the documentation of this file.
00001 //
00002 // Copyright (c) 2003-2006 Greg Landrum and Rational Discovery LLC
00003 //
00004 //   @@ All Rights Reserved @@
00005 //  This file is part of the RDKit.
00006 //  The contents are covered by the terms of the BSD license
00007 //  which is included in the file license.txt, found at the root
00008 //  of the RDKit source tree.
00009 //
00010 #ifndef __RD_ORQUERY_H__
00011 #define __RD_ORQUERY_H__
00012 
00013 #include "Query.h"
00014 
00015 namespace Queries {
00016   //! a Query implementing AND: requires any child to be \c true
00017   template <class MatchFuncArgType, class DataFuncArgType=MatchFuncArgType,
00018     bool needsConversion=false>
00019   class OrQuery : public Query<MatchFuncArgType, DataFuncArgType,needsConversion> {
00020 
00021   public:
00022     typedef Query<MatchFuncArgType, DataFuncArgType,needsConversion> BASE;
00023     OrQuery() {
00024       this->df_negate = false;
00025     };
00026 
00027     bool Match(const DataFuncArgType what) const {
00028       bool res = false;
00029       typename BASE::CHILD_VECT_CI it1;
00030       for(it1=this->beginChildren();
00031           it1!=this->endChildren();
00032           ++it1){
00033         bool tmp = (*it1)->Match(what);
00034         if( tmp ){
00035           res = true;
00036           break;
00037         }
00038       }
00039       if( this->getNegation() ) res = !res;
00040       return res;
00041     };
00042 
00043     Query<MatchFuncArgType,DataFuncArgType,needsConversion> *  
00044     copy( ) const {
00045       OrQuery<MatchFuncArgType,DataFuncArgType,needsConversion> *res =
00046         new OrQuery<MatchFuncArgType,DataFuncArgType,needsConversion>();
00047 
00048       typename BASE::CHILD_VECT_CI i;
00049       for(i=this->beginChildren();
00050           i!=this->endChildren();
00051           ++i){
00052         res->addChild(*i);
00053       }
00054       res->setNegation(this->getNegation());
00055       res->d_description = this->d_description;
00056       return res;
00057     };
00058   };
00059 
00060 }
00061 #endif