RDKit
Open-source cheminformatics and machine learning.
MolCatalogEntry.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 Greg Landrum
3 //
4 #ifndef _RD_MOLCATALOGENTRY_H_
5 #define _RD_MOLCATALOGENTRY_H_
6 
7 #include <RDGeneral/Dict.h>
9 #include <fstream>
10 #include <string>
11 
12 
13 namespace RDKit {
14  class ROMol;
15 
16  //! This class is used to store ROMol objects in a MolCatalog
18  public :
19 
20  MolCatalogEntry() : dp_mol(0),d_descrip("") {
21  dp_props = new Dict();
22  setBitId(-1);
23  }
24 
25  //! copy constructor
26  MolCatalogEntry(const MolCatalogEntry &other);
27 
28  //! create an entry to hold the provided ROMol
29  /*!
30  The MolCatalogEntry takes ownership of the pointer
31  */
32  MolCatalogEntry(const ROMol *omol);
33 
34  //! construct from a pickle
35  MolCatalogEntry(const std::string &pickle){
36  this->initFromString(pickle);
37  }
38 
40 
41  std::string getDescription() const {return d_descrip;}
42 
43  void setDescription(std::string val) {d_descrip = val;}
44 
45  unsigned int getOrder() const { return d_order; };
46  void setOrder(unsigned int order) { d_order=order; };
47 
48  const ROMol *getMol() const { return dp_mol; };
49  //! hold the provided ROMol
50  /*!
51  The MolCatalogEntry takes ownership of the pointer.
52  If the MolCatalogEntry already has a molecule, this one will be deleted.
53  */
54  void setMol(const ROMol *molPtr);
55 
56  //! set a named property
57  template <typename T> void setProp(const char *key, T &val) const {
58  dp_props->setVal(key, val);
59  }
60 
61  //! \overload
62  template <typename T> void setProp(const std::string &key, T &val) const {
63  setProp(key.c_str(), val);
64  }
65 
66  //! get the value of a named property
67  template <typename T>
68  void getProp(const char *key, T &res) const {
69  dp_props->getVal(key, res);
70  }
71  //! \overload
72  template <typename T>
73  void getProp(const std::string &key, T &res) const {
74  getProp(key.c_str(), res);
75  }
76 
77  //! returns true if such a property exists
78  bool hasProp(const char *key) const {
79  if (!dp_props) return false;
80  return dp_props->hasVal(key);
81  }
82  //! \overload
83  bool hasProp(const std::string &key) const {
84  return hasProp(key.c_str());
85  }
86 
87  //! clears a named property
88  void clearProp(const char *key) const {
89  dp_props->clearVal(key);
90  }
91  //! \overload
92  void clearProp(const std::string &key) const {
93  clearProp(key.c_str());
94  }
95 
96  //! serializes this entry to the stream
97  void toStream(std::ostream &ss) const;
98  //! returns a serialized (pickled) form of the entry
99  std::string Serialize() const;
100  //! initialize from a stream containing a pickle
101  void initFromStream(std::istream &ss);
102  //! initialize from a string containing a pickle
103  void initFromString(const std::string &text);
104 
105  private:
106  const ROMol *dp_mol;
107  Dict *dp_props;
108 
109  unsigned int d_order;
110  std::string d_descrip;
111  };
112 }
113 
114 #endif
115 
unsigned int getOrder() const
This class is used to store ROMol objects in a MolCatalog.
void setVal(const std::string &what, T &val)
Sets the value associated with a key.
Definition: Dict.h:170
bool hasProp(const std::string &key) const
bool hasProp(const char *key) const
returns true if such a property exists
void getProp(const std::string &key, T &res) const
void initFromString(const std::string &text)
initialize from a string containing a pickle
Defines the Dict class.
ROMol is a molecule class that is intended to have a fixed topology.
Definition: ROMol.h:105
void clearVal(const std::string &what)
Clears the value associated with a particular key, removing the key from the dictionary.
Definition: Dict.h:198
void getVal(const std::string &what, T &res) const
Gets the value associated with a particular key.
Definition: Dict.h:86
void setOrder(unsigned int order)
void setBitId(int bid)
sets our bit Id
Definition: CatalogEntry.h:24
const ROMol * getMol() const
std::string getDescription() const
returns a text description of this entry
void setProp(const char *key, T &val) const
set a named property
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
void clearProp(const char *key) const
clears a named property
void setMol(const ROMol *molPtr)
hold the provided ROMol
bool hasVal(const char *what) const
Returns whether or not the dictionary contains a particular key.
Definition: Dict.h:50
Abstract base class to be used to represent an entry in a Catalog.
Definition: CatalogEntry.h:19
void setProp(const std::string &key, T &val) const
MolCatalogEntry(const std::string &pickle)
construct from a pickle
void initFromStream(std::istream &ss)
initialize from a stream containing a pickle
std::string Serialize() const
returns a serialized (pickled) form of the entry
void toStream(std::ostream &ss) const
serializes this entry to the stream
The Dict class can be used to store objects of arbitrary type keyed by strings.
Definition: Dict.h:33
void setDescription(std::string val)
void clearProp(const std::string &key) const
void getProp(const char *key, T &res) const
get the value of a named property