RDCode: AndQuery.h Source File

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