33#ifndef __RD_FILTER_CATALOG_H__
34#define __RD_FILTER_CATALOG_H__
43#ifdef RDK_USE_BOOST_SERIALIZATION
45#include <boost/archive/text_oarchive.hpp>
46#include <boost/archive/text_iarchive.hpp>
47#include <boost/serialization/vector.hpp>
48#include <boost/serialization/shared_ptr.hpp>
60 boost::shared_ptr<FilterMatcherBase> d_matcher;
67 :
RDCatalog::CatalogEntry(), d_matcher(matcher.copy()) {
72 boost::shared_ptr<FilterMatcherBase> matcher)
73 :
RDCatalog::CatalogEntry(), d_matcher(std::move(matcher)) {
79 d_matcher(rhs.d_matcher),
80 d_props(rhs.d_props) {}
87 bool isValid()
const {
return d_matcher.get() && d_matcher->isValid(); }
113 template <
typename T>
114 void setProp(
const std::string_view key, T val) {
115 d_props.setVal(key, val);
134 template <
typename T>
135 void getProp(
const std::string_view key, T &res)
const {
136 d_props.getVal(key, res);
139 template <
typename T>
141 return d_props.getVal<T>(key);
146 template <
typename T>
148 return d_props.getValIfPresent(key, res);
152 bool hasProp(
const std::string_view key)
const {
return d_props.hasVal(key); }
155 void clearProp(
const std::string_view key) { d_props.clearVal(key); }
172 std::vector<FilterMatch> &matchVect)
const {
173 return this->
isValid() && d_matcher->getMatches(mol, matchVect);
183 return this->
isValid() && d_matcher->hasMatch(mol);
196#ifdef RDK_USE_BOOST_SERIALIZATION
197 friend class boost::serialization::access;
198 template <
class Archive>
199 void save(Archive &ar,
const unsigned int version)
const {
201 registerFilterMatcherTypes(ar);
206 std::vector<std::string> string_props;
207 for (
size_t i = 0; i < keys.size(); ++i) {
210 if (d_props.getValIfPresent<std::string>(keys[i], val)) {
211 string_props.push_back(keys[i]);
212 string_props.push_back(val);
214 }
catch (
const std::bad_any_cast &) {
222 template <
class Archive>
223 void load(Archive &ar,
const unsigned int version) {
225 registerFilterMatcherTypes(ar);
228 std::vector<std::string> string_props;
232 for (
size_t i = 0; i < string_props.size() / 2; ++i) {
233 d_props.
setVal(string_props[i * 2], string_props[i * 2 + 1]);
237 BOOST_SERIALIZATION_SPLIT_MEMBER();
242#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.
void setVal(const std::string_view what, T &val)
Sets the value associated with a key.
~FilterCatalogEntry() override
void setProp(const std::string_view key, T val)
sets a property value
void toStream(std::ostream &ss) const override
serializes (pickles) to a stream
void initFromString(const std::string &text) override
initializes from a string pickle
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.
bool getPropIfPresent(const std::string_view key, T &res) const
T getProp(const std::string_view key) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void clearProp(const std::string_view key)
clears the value of a property
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)
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
bool hasProp(const std::string_view key) const
returns whether or not we have a property with name key
void getProp(const std::string_view key, T &res) const
allows retrieval of a particular property value
#define RDKIT_FILTERCATALOG_EXPORT
std::vector< std::string > STR_VECT
std::map< std::string, std::string > STRING_PROPS