XOrQuery.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_XORQUERY_H__
00011 #define __RD_XORQUERY_H__
00012 
00013 #include "Query.h"
00014 
00015 namespace Queries{
00016 
00017   //! a Query implementing XOR: requires exactly one child to be \c true
00018   template <class MatchFuncArgType, class DataFuncArgType=MatchFuncArgType,
00019     bool needsConversion=false>
00020   class XOrQuery : public Query<MatchFuncArgType, DataFuncArgType,needsConversion> {
00021 
00022   public:
00023     typedef Query<MatchFuncArgType, DataFuncArgType,needsConversion> BASE;
00024     XOrQuery() {
00025       this->df_negate = false;
00026     };
00027 
00028     bool Match(const DataFuncArgType what) const {
00029       bool res = false;
00030       typename BASE::CHILD_VECT_CI it1;
00031       for(it1=this->beginChildren();
00032           it1!=this->endChildren();
00033           ++it1){
00034         bool tmp = (*it1)->Match(what);
00035         if( tmp ){
00036           if( res ){
00037             res = false;
00038             break;
00039           } else{
00040             res = true;
00041           }
00042         }
00043       }
00044       if( this->getNegation() ) res = !res;
00045       return res;
00046     };
00047 
00048     Query<MatchFuncArgType,DataFuncArgType,needsConversion> *
00049     copy( ) const {
00050       XOrQuery<MatchFuncArgType,DataFuncArgType,needsConversion> *res =
00051         new XOrQuery<MatchFuncArgType,DataFuncArgType,needsConversion>();
00052 
00053       typename BASE::CHILD_VECT_CI i;
00054       for(i=this->beginChildren();
00055           i!=this->endChildren();
00056           ++i){
00057         res->addChild(*i);
00058       }
00059       res->setNegation(this->getNegation());
00060       res->d_description = this->d_description;
00061       return res;
00062     };
00063   };
00064 
00065 }
00066 #endif