RDCode: MolCatalogEntry.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories

# MolCatalogEntry.h

Go to the documentation of this file.

    00001 //
    00002 //  Copyright (C) 2006 Greg Landrum
    00003 //
    00004 #ifndef _RD_MOLCATALOGENTRY_H_
    00005 #define _RD_MOLCATALOGENTRY_H_
    00006
    00007 #include <RDGeneral/Dict.h>
    00008 #include <Catalogs/CatalogEntry.h>
    00009 #include <fstream>
    00010 #include <string>
    00011
    00012
    00013 namespace RDKit {
    00014   class ROMol;
    00015
    00016   //! This class is used to store ROMol objects in a MolCatalog
    00017   class MolCatalogEntry : public RDCatalog::CatalogEntry {
    00018     public :
    00019
    00020     MolCatalogEntry() : dp_mol(0),d_descrip("") {
    00021       dp_props = new Dict();
    00022       setBitId(-1);
    00023     }
    00024
    00025     //! copy constructor
    00026     MolCatalogEntry(const MolCatalogEntry &other);
    00027
    00028     //! create an entry to hold the provided ROMol
    00029     /*!
    00030       The MolCatalogEntry takes ownership of the pointer
    00031      */
    00032     MolCatalogEntry(const ROMol *omol);
    00033
    00034     //! construct from a pickle
    00035     MolCatalogEntry(const std::string &pickle){
    00036       this->initFromString(pickle);
    00037     }
    00038
    00039     ~MolCatalogEntry();
    00040
    00041     std::string getDescription() const {return d_descrip;}
    00042
    00043     void setDescription(std::string val) {d_descrip = val;}
    00044
    00045     unsigned int getOrder() const { return d_order; };
    00046     void setOrder(unsigned int order) { d_order=order; };
    00047
    00048     const ROMol *getMol() const { return dp_mol; };
    00049     //! hold the provided ROMol
    00050     /*!
    00051       The MolCatalogEntry takes ownership of the pointer.
    00052       If the MolCatalogEntry already has a molecule, this one will be deleted.
    00053      */
    00054     void setMol(const ROMol *molPtr);
    00055
    00056     //! set a named property
    00057     template <typename T> void setProp(const char *key, T &val) const {
    00058       dp_props->setVal(key, val);
    00059     }
    00060
    00061     //! \overload
    00062     template <typename T> void setProp(const std::string key, T &val) const {
    00063       setProp(key.c_str(), val);
    00064     }
    00065
    00066     //! get the value of a named property
    00067     template <typename T>
    00068       void getProp(const char *key, T &res) const {
    00069       dp_props->getVal(key, res);
    00070     }
    00071     //! \overload
    00072     template <typename T>
    00073       void getProp(const std::string key, T &res) const {
    00074       getProp(key.c_str(), res);
    00075     }
    00076
    00077     //! returns true if such a property exists
    00078     bool hasProp(const char *key) const {
    00079       if (!dp_props) return false;
    00080       return dp_props->hasVal(key);
    00081     }
    00082     //! \overload
    00083     bool hasProp(const std::string key) const {
    00084       return hasProp(key.c_str());
    00085     }
    00086
    00087     //! clears a named property
    00088     void clearProp(const char *key) const {
    00089       dp_props->clearVal(key);
    00090     }
    00091     //! \overload
    00092     void clearProp(const std::string key) const {
    00093       clearProp(key.c_str());
    00094     }
    00095
    00096     //! serializes this entry to the stream
    00097     void toStream(std::ostream &ss) const;
    00098     //! returns a serialized (pickled) form of the entry
    00099     std::string Serialize() const;
    00100     //! initialize from a stream containing a pickle
    00101     void initFromStream(std::istream &ss);
    00102     //! initialize from a string containing a pickle
    00103     void initFromString(const std::string &text);
    00104
    00105   private:
    00106     const ROMol *dp_mol;
    00107     Dict *dp_props;
    00108
    00109     unsigned int d_order;
    00110     std::string d_descrip;
    00111   };
    00112 }
    00113
    00114 #endif
    00115