33#ifndef __RD_FILTER_CATALOG_H__
34#define __RD_FILTER_CATALOG_H__
42#ifdef RDK_USE_BOOST_SERIALIZATION
44#include <boost/archive/text_oarchive.hpp>
45#include <boost/archive/text_iarchive.hpp>
46#include <boost/serialization/vector.hpp>
47#include <boost/serialization/shared_ptr.hpp>
59 boost::shared_ptr<FilterMatcherBase> d_matcher;
66 :
RDCatalog::CatalogEntry(), d_matcher(matcher.copy()) {
71 boost::shared_ptr<FilterMatcherBase> matcher)
72 :
RDCatalog::CatalogEntry(), d_matcher(std::move(matcher)) {
78 d_matcher(rhs.d_matcher),
79 d_props(rhs.d_props) {}
86 bool isValid()
const {
return d_matcher.get() && d_matcher->isValid(); }
112 template <
typename T>
114 std::string what(key);
118 template <
typename T>
139 template <
typename T>
144 template <
typename T>
145 void getProp(
const std::string &key, T &res)
const {
149 template <
typename T>
151 return d_props.
getVal<T>(key);
154 template <
typename T>
156 return d_props.
getVal<T>(key);
161 template <
typename T>
166 template <
typename T>
175 return d_props.
hasVal(key);
181 std::string what(key);
202 std::vector<FilterMatch> &matchVect)
const {
203 return this->isValid() && d_matcher->getMatches(mol, matchVect);
213 return this->isValid() && d_matcher->hasMatch(mol);
226#ifdef RDK_USE_BOOST_SERIALIZATION
227 friend class boost::serialization::access;
228 template <
class Archive>
229 void save(Archive &ar,
const unsigned int version)
const {
231 registerFilterMatcherTypes(ar);
236 std::vector<std::string> string_props;
237 for (
size_t i = 0; i < keys.size(); ++i) {
241 string_props.push_back(keys[i]);
242 string_props.push_back(val);
244 }
catch (
const std::bad_any_cast &) {
252 template <
class Archive>
253 void load(Archive &ar,
const unsigned int version) {
255 registerFilterMatcherTypes(ar);
258 std::vector<std::string> string_props;
262 for (
size_t i = 0; i < string_props.size() / 2; ++i) {
263 d_props.
setVal(string_props[i * 2], string_props[i * 2 + 1]);
267 BOOST_SERIALIZATION_SPLIT_MEMBER();
272#ifdef RDK_USE_BOOST_SERIALIZATION
#define RDUNUSED_PARAM(x)
pulls in the core RDKit functionality
Abstract base class to be used to represent an entry in a Catalog.
The Dict class can be used to store objects of arbitrary type keyed by strings.
void reset()
Clears all keys (and values) from the dictionary.
STR_VECT keys() const
Returns the set of keys in the dictionary.
bool hasVal(const std::string &what) const
Returns whether or not the dictionary contains a particular key.
bool getValIfPresent(const std::string &what, T &res) const
Potentially gets the value associated with a particular key returns true on success/false on failure.
void getVal(const std::string &what, T &res) const
Gets the value associated with a particular key.
void clearVal(const std::string &what)
Clears the value associated with a particular key, removing the key from the dictionary.
void setVal(const std::string &what, T &val)
Sets the value associated with a key.
~FilterCatalogEntry() override
bool hasProp(const std::string &key) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void getProp(const char *key, T &res) const
allows retrieval of a particular property value
void getProp(const std::string &key, T &res) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void toStream(std::ostream &ss) const override
serializes (pickles) to a stream
void clearProp(const std::string &key)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void initFromString(const std::string &text) override
initializes from a string pickle
void setProp(const char *key, T val)
sets a property value
bool getPropIfPresent(const char *key, T &res) const
bool getPropIfPresent(const std::string &key, T &res) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
FilterCatalogEntry(const std::string &name, boost::shared_ptr< FilterMatcherBase > matcher)
bool isValid() const
Returns true if the Filters stored in this catalog entry are valid.
bool getFilterMatches(const ROMol &mol, std::vector< FilterMatch > &matchVect) const
Returns the matching filters for this catalog entry.
std::string Serialize() const override
returns a string with a serialized (pickled) representation
void setDescription(const std::string &description)
Sets the description of the catalog entry.
STR_VECT getPropList() const
returns a list with the names of our properties
bool hasFilterMatch(const ROMol &mol) const
Returns true if the filters in this catalog entry match the molecule.
void setProps(const Dict &props)
const Dict & getProps() const
FilterCatalogEntry(const FilterCatalogEntry &rhs)
T getProp(const char *key) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void clearProp(const char *key)
clears the value of a property
std::string getDescription() const override
Returns the description of the catalog entry.
FilterCatalogEntry(const std::string &name, const FilterMatcherBase &matcher)
void initFromStream(std::istream &ss) override
initializes from a stream pickle
void setProp(const std::string &key, T val)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool hasProp(const char *key) const
returns whether or not we have a property with name key
T getProp(const std::string &key) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
#define RDKIT_FILTERCATALOG_EXPORT
std::vector< std::string > STR_VECT
std::map< std::string, std::string > STRING_PROPS