1 // 2 // Copyright (C) 2006 Greg Landrum 3 // 4 #include <RDGeneral/export.h> 5 #ifndef _RD_MOLCATALOGENTRY_H_ 6 #define _RD_MOLCATALOGENTRY_H_ 7 8 #include <RDGeneral/Dict.h> 9 #include <Catalogs/CatalogEntry.h> 10 #include <fstream> 11 #include <string> 12 13 namespace RDKit { 14 class ROMol; 15 16 //! This class is used to store ROMol objects in a MolCatalog 17 class RDKIT_MOLCATALOG_EXPORT MolCatalogEntry : public RDCatalog::CatalogEntry { 18 public: MolCatalogEntry()19 MolCatalogEntry() : d_descrip("") { 20 dp_props = new Dict(); 21 setBitId(-1); 22 } 23 24 //! copy constructor 25 MolCatalogEntry(const MolCatalogEntry &other); 26 27 //! create an entry to hold the provided ROMol 28 /*! 29 The MolCatalogEntry takes ownership of the pointer 30 */ 31 MolCatalogEntry(const ROMol *omol); 32 33 //! construct from a pickle MolCatalogEntry(const std::string & pickle)34 MolCatalogEntry(const std::string &pickle) { this->initFromString(pickle); } 35 36 ~MolCatalogEntry(); 37 getDescription()38 std::string getDescription() const { return d_descrip; } 39 setDescription(std::string val)40 void setDescription(std::string val) { d_descrip = val; } 41 getOrder()42 unsigned int getOrder() const { return d_order; }; setOrder(unsigned int order)43 void setOrder(unsigned int order) { d_order = order; }; 44 getMol()45 const ROMol *getMol() const { return dp_mol; }; 46 //! hold the provided ROMol 47 /*! 48 The MolCatalogEntry takes ownership of the pointer. 49 If the MolCatalogEntry already has a molecule, this one will be deleted. 50 */ 51 void setMol(const ROMol *molPtr); 52 53 //! set a named property 54 template <typename T> setProp(const char * key,T & val)55 void setProp(const char *key, T &val) const { 56 dp_props->setVal(key, val); 57 } 58 59 //! \overload 60 template <typename T> setProp(const std::string & key,T & val)61 void setProp(const std::string &key, T &val) const { 62 setProp(key.c_str(), val); 63 } 64 65 //! get the value of a named property 66 template <typename T> getProp(const char * key,T & res)67 void getProp(const char *key, T &res) const { 68 dp_props->getVal(key, res); 69 } 70 //! \overload 71 template <typename T> getProp(const std::string & key,T & res)72 void getProp(const std::string &key, T &res) const { 73 getProp(key.c_str(), res); 74 } 75 76 //! returns true if such a property exists hasProp(const char * key)77 bool hasProp(const char *key) const { 78 if (!dp_props) return false; 79 return dp_props->hasVal(key); 80 } 81 //! \overload hasProp(const std::string & key)82 bool hasProp(const std::string &key) const { return hasProp(key.c_str()); } 83 84 //! clears a named property clearProp(const char * key)85 void clearProp(const char *key) const { dp_props->clearVal(key); } 86 //! \overload clearProp(const std::string & key)87 void clearProp(const std::string &key) const { clearProp(key.c_str()); } 88 89 //! serializes this entry to the stream 90 void toStream(std::ostream &ss) const; 91 //! returns a serialized (pickled) form of the entry 92 std::string Serialize() const; 93 //! initialize from a stream containing a pickle 94 void initFromStream(std::istream &ss); 95 //! initialize from a string containing a pickle 96 void initFromString(const std::string &text); 97 98 private: 99 const ROMol *dp_mol{nullptr}; 100 Dict *dp_props; 101 102 unsigned int d_order{0}; 103 std::string d_descrip; 104 }; 105 } // namespace RDKit 106 107 #endif 108