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