AndQuery.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_ANDQUERY_H__
00011 #define __RD_ANDQUERY_H__
00012 
00013 #include "Query.h"
00014 
00015 namespace Queries{
00016 
00017   //! a Query implementing AND: requires all children to be \c true
00018   template <class MatchFuncArgType, class DataFuncArgType=MatchFuncArgType,
00019     bool needsConversion=false>
00020   class AndQuery :
00021     public Query<MatchFuncArgType, DataFuncArgType,needsConversion> {
00022 
00023   public:
00024     typedef Query<MatchFuncArgType, DataFuncArgType,needsConversion> BASE;
00025     AndQuery() { this->df_negate=false; };
00026 
00027     bool Match(const DataFuncArgType what) const {
00028       bool res = true;
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 = false;
00036           break;
00037         }
00038       }
00039       if( this->getNegation() ) res = !res;
00040       return res;
00041     };
00042     Query<MatchFuncArgType,DataFuncArgType,needsConversion> *
00043     copy( ) const {
00044       AndQuery<MatchFuncArgType,DataFuncArgType,needsConversion> *res =
00045         new AndQuery<MatchFuncArgType,DataFuncArgType,needsConversion>();
00046       typename BASE::CHILD_VECT_CI i;
00047       for(i=this->beginChildren();
00048           i!=this->endChildren();
00049           ++i){
00050         res->addChild(*i);
00051       }
00052       res->setNegation(this->getNegation());
00053       res->d_description = this->d_description;
00054       return res;
00055     };
00056   };
00057 
00058 }
00059 #endif