QueryBond.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (C) 2001-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_QUERYBOND_H
00011 #define _RD_QUERYBOND_H
00012 
00013 #include <Query/QueryObjects.h>
00014 #include "Bond.h"
00015 #include "QueryOps.h"
00016 
00017 
00018 namespace RDKit{
00019 
00020   //! Class for storing Bond queries
00021   /*!
00022     QueryBond objects are derived from Bond objects, so they can be
00023     added to molecules and the like, but they have much fancier
00024     querying capabilities.
00025     
00026    */
00027 
00028   class QueryBond : public Bond {
00029   public:
00030     typedef Queries::Query<int,Bond const *,true> QUERYBOND_QUERY;
00031 
00032     QueryBond() : Bond(), dp_query(NULL) {};
00033     //! initialize with a particular bond order
00034     explicit QueryBond(BondType bT);
00035     //! initialize from a bond
00036     explicit QueryBond(const Bond &other) : Bond(other), dp_query(makeBondOrderEqualsQuery(other.getBondType())) {};
00037     QueryBond(const QueryBond &other) : Bond(other), dp_query(other.dp_query->copy()) {};
00038 
00039     ~QueryBond();
00040 
00041     
00042     //! returns a copy of this query, owned by the caller
00043     virtual Bond *copy() const;
00044 
00045     QueryBond &operator=(const QueryBond &other);
00046 
00047     //! sets the BondType of this query:
00048     void setBondType(BondType bT);
00049     //! sets the BondDir of this query:
00050     void setBondDir(BondDir bD);
00051   
00052 
00053     //! returns true if we match Bond \c what
00054     bool Match(const Bond::BOND_SPTR what) const;
00055     //! \overload
00056     bool Match(Bond const *what) const;
00057 
00058 
00059     // This method can be used to distinguish query bonds from standard bonds
00060     bool hasQuery() const { return dp_query!=0; };
00061     
00062     //! returns our current query
00063     QUERYBOND_QUERY *getQuery() const { return dp_query; };
00064     //! replaces our current query with the value passed in
00065     void setQuery(QUERYBOND_QUERY *what) {
00066       // free up any existing query (Issue255):
00067       if(dp_query)delete dp_query;
00068       dp_query = what;
00069     };
00070 
00071     //! expands our current query
00072     /*!
00073       \param what          the Queries::Query to be added
00074       \param how           the operator to be used in the expansion
00075       \param maintainOrder (optional) flags whether the relative order of
00076                            the queries needs to be maintained, if this is
00077                            false, the order is reversed
00078 
00079       <b>Notes:</b>
00080         - \c what should probably be constructed using one of the functions
00081            defined in QueryOps.h
00082         - the \c maintainOrder option can be useful because the combination
00083           operators short circuit when possible.
00084       
00085     */
00086     void expandQuery(QUERYBOND_QUERY *what,
00087                      Queries::CompositeQueryType how=Queries::COMPOSITE_AND,
00088                      bool maintainOrder=true);
00089 
00090   protected:
00091     QUERYBOND_QUERY *dp_query;
00092   };
00093 
00094 };
00095 
00096 
00097 #endif