RDCode: QueryAtom.h Source File

# QueryAtom.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 //
    00006 #ifndef _RD_QUERYATOM_H_
    00007 #define _RD_QUERYATOM_H_
    00008
    00009 #include "Atom.h"
    00010 #include <Query/QueryObjects.h>
    00011 #include <GraphMol/QueryOps.h>
    00012
    00013 namespace RDKit{
    00014
    00015   //! Class for storing atomic queries
    00016   /*!
    00017     QueryAtom objects are derived from Atom objects, so they can be
    00018     added to molecules and the like, but they have much fancier
    00019     querying capabilities.
    00020
    00021    */
    00022   class QueryAtom : public Atom {
    00023   public:
    00024     typedef Queries::Query<int,Atom const *,true> QUERYATOM_QUERY;
    00025
    00026     QueryAtom() : Atom(), dp_query(NULL) {};
    00027     explicit QueryAtom(int num) : Atom(num), dp_query(makeAtomNumEqualsQuery(num)) {};
    00028     explicit QueryAtom(const Atom &other) : Atom(other), dp_query(makeAtomNumEqualsQuery(other.getAtomicNum())) {};
    00029     QueryAtom( const QueryAtom & other) : Atom(other),dp_query(other.dp_query->copy()){};
    00030     ~QueryAtom();
    00031
    00032
    00033     //! returns a copy of this query, owned by the caller
    00034     Atom *copy() const;
    00035
    00036     // This method can be used to distinguish query atoms from standard atoms:
    00037     bool hasQuery() const { return dp_query!=0; };
    00038
    00039     //! replaces our current query with the value passed in
    00040     void setQuery(QUERYATOM_QUERY *what) { dp_query = what; }
    00041     //! returns our current query
    00042     QUERYATOM_QUERY *getQuery() const { return dp_query; };
    00043
    00044     //! expands our current query
    00045     /*!
    00046       \param what          the Queries::Query to be added
    00047       \param how           the operator to be used in the expansion
    00048       \param maintainOrder (optional) flags whether the relative order of
    00049                            the queries needs to be maintained, if this is
    00050                            false, the order is reversed
    00051       <b>Notes:</b>
    00052         - \c what should probably be constructed using one of the functions
    00053            defined in QueryOps.h
    00054         - the \c maintainOrder option can be useful because the combination
    00055           operators short circuit when possible.
    00056
    00057     */
    00058     void expandQuery(QUERYATOM_QUERY *what,
    00059                      Queries::CompositeQueryType how=Queries::COMPOSITE_AND,
    00060                      bool maintainOrder=true);
    00061
    00062     //! returns true if we match Atom \c what
    00063     bool Match(const Atom::ATOM_SPTR what) const;
    00064     //! \overload
    00065     bool Match(Atom const *what) const;
    00066
    00067   private:
    00068     QUERYATOM_QUERY *dp_query;
    00069
    00070   }; // end o' class
    00071
    00072 }; // end o' namespace
    00073
    00074
    00075 #endif