Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace boost::shared_ptr with std::shared_ptr #6923

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Code/DataStructs/FPBReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,10 +647,10 @@ void FPBReader::destroy() {
dp_impl = nullptr;
};

boost::shared_ptr<ExplicitBitVect> FPBReader::getFP(unsigned int idx) const {
std::shared_ptr<ExplicitBitVect> FPBReader::getFP(unsigned int idx) const {
PRECONDITION(df_init, "not initialized");

return boost::shared_ptr<ExplicitBitVect>(detail::extractFP(dp_impl, idx));
return std::shared_ptr<ExplicitBitVect>(detail::extractFP(dp_impl, idx));
};
boost::shared_array<boost::uint8_t> FPBReader::getBytes(
unsigned int idx) const {
Expand Down
8 changes: 4 additions & 4 deletions Code/DataStructs/FPBReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <DataStructs/ExplicitBitVect.h>

#include <cstdint>
#include <boost/shared_ptr.hpp>
#include <memory>
#include <boost/shared_array.hpp>

namespace RDKit {
Expand All @@ -40,7 +40,7 @@ struct FPBReader_impl;
\code
FPBReader reader("foo.fpb");
reader.init();
boost::shared_ptr<ExplicitBitVect> ebv = reader.getFP(95);
std::shared_ptr<ExplicitBitVect> ebv = reader.getFP(95);
std::vector<std::pair<double, unsigned int> > nbrs =
reader.getTanimotoNeighbors(*ebv.get(), 0.70);
\endcode
Expand Down Expand Up @@ -124,14 +124,14 @@ class RDKIT_DATASTRUCTS_EXPORT FPBReader {
df_init = false;
}
//! returns the requested fingerprint as an \c ExplicitBitVect
boost::shared_ptr<ExplicitBitVect> getFP(unsigned int idx) const;
std::shared_ptr<ExplicitBitVect> getFP(unsigned int idx) const;
//! returns the requested fingerprint as an array of bytes
boost::shared_array<std::uint8_t> getBytes(unsigned int idx) const;

//! returns the id of the requested fingerprint
std::string getId(unsigned int idx) const;
//! returns the fingerprint and id of the requested fingerprint
std::pair<boost::shared_ptr<ExplicitBitVect>, std::string> operator[](
std::pair<std::shared_ptr<ExplicitBitVect>, std::string> operator[](
unsigned int idx) const {
return std::make_pair(getFP(idx), getId(idx));
}
Expand Down
2 changes: 1 addition & 1 deletion Code/DataStructs/MultiFPBReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace RDKit {
readers.append(&r2);
MultiFPBReader fpbs(readers);
fpbs.init();
boost::shared_ptr<ExplicitBitVect> ebv = fpbs.getReader(0)->getFP(95);
std::shared_ptr<ExplicitBitVect> ebv = fpbs.getReader(0)->getFP(95);
std::vector<std::tuple<double,unsigned int, unsigned int> > nbrs =
fpbs.getTanimotoNeighbors(*ebv.get(), 0.70);
\endcode
Expand Down
2 changes: 1 addition & 1 deletion Code/DataStructs/Wrap/SparseIntVect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ struct sparseIntVec_wrapper {
template <typename IndexType>
static void wrapOne(const char *className) {
python::class_<SparseIntVect<IndexType>,
boost::shared_ptr<SparseIntVect<IndexType>>>(
std::shared_ptr<SparseIntVect<IndexType>>>(
className, sparseIntVectDoc.c_str(),
python::init<IndexType>("Constructor"))
.def(python::init<std::string>())
Expand Down
2 changes: 1 addition & 1 deletion Code/DataStructs/Wrap/wrap_ExplicitBV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ or by indexing (i.e. bv[i] = 1 or if bv[i]).\n\

struct EBV_wrapper {
static void wrap() {
python::class_<ExplicitBitVect, boost::shared_ptr<ExplicitBitVect>>(
python::class_<ExplicitBitVect, std::shared_ptr<ExplicitBitVect>>(
"ExplicitBitVect", ebvClassDoc.c_str(), python::init<unsigned int>())
.def(python::init<std::string>())
.def(python::init<unsigned int, bool>(python::args("size", "bitsSet")))
Expand Down
2 changes: 1 addition & 1 deletion Code/DataStructs/Wrap/wrap_FPB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ double getTaniHelper(const FPBReader *self, unsigned int which,
return self->getTanimoto(which, bv);
}
python::tuple getItemHelper(const FPBReader *self, unsigned int which) {
std::pair<boost::shared_ptr<ExplicitBitVect>, std::string> v = (*self)[which];
std::pair<std::shared_ptr<ExplicitBitVect>, std::string> v = (*self)[which];
return python::make_tuple(v.first, v.second);
}
double getTverskyHelper(const FPBReader *self, unsigned int which,
Expand Down
2 changes: 1 addition & 1 deletion Code/DataStructs/Wrap/wrap_SparseBV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ or by indexing (i.e. bv[i] = 1 or if bv[i]).\n\
\n";
struct SBV_wrapper {
static void wrap() {
python::class_<SparseBitVect, boost::shared_ptr<SparseBitVect>>(
python::class_<SparseBitVect, std::shared_ptr<SparseBitVect>>(
"SparseBitVect", sbvClassDoc.c_str(), python::init<unsigned int>())
.def(python::init<std::string>())
.def("SetBit", (bool(SBV::*)(unsigned int)) & SBV::setBit,
Expand Down
22 changes: 11 additions & 11 deletions Code/DataStructs/testFPB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void _basicsTest(FPBReader &fps) {
std::string nm = fps.getId(0);
// std::cerr << " nm: >" << nm << "<" << std::endl;
TEST_ASSERT(nm == "ZINC00902219");
boost::shared_ptr<ExplicitBitVect> fp = fps.getFP(0);
std::shared_ptr<ExplicitBitVect> fp = fps.getFP(0);
TEST_ASSERT(fp);
TEST_ASSERT(fp->getNumBits() == 2048);
TEST_ASSERT(fp->getNumOnBits() == 17);
Expand All @@ -50,8 +50,8 @@ void _basicsTest(FPBReader &fps) {
}
}
{ // operator[] version
std::pair<boost::shared_ptr<ExplicitBitVect>, std::string> tpl = fps[0];
boost::shared_ptr<ExplicitBitVect> fp = tpl.first;
std::pair<std::shared_ptr<ExplicitBitVect>, std::string> tpl = fps[0];
std::shared_ptr<ExplicitBitVect> fp = tpl.first;
TEST_ASSERT(fp);
TEST_ASSERT(fp->getNumBits() == 2048);
TEST_ASSERT(fp->getNumOnBits() == 17);
Expand All @@ -63,7 +63,7 @@ void _basicsTest(FPBReader &fps) {
TEST_ASSERT(tpl.second == "ZINC00902219");
}
{ // test another fp
boost::shared_ptr<ExplicitBitVect> fp = fps.getFP(3);
std::shared_ptr<ExplicitBitVect> fp = fps.getFP(3);
TEST_ASSERT(fp);
TEST_ASSERT(fp->getNumBits() == 2048);
TEST_ASSERT(fp->getNumOnBits() == 20);
Expand Down Expand Up @@ -220,7 +220,7 @@ void test4LazyFPBReaderBasics() {
{ // get* version
std::string nm = fps.getId(0);
TEST_ASSERT(nm == "ZINC00902219");
boost::shared_ptr<ExplicitBitVect> fp = fps.getFP(0);
std::shared_ptr<ExplicitBitVect> fp = fps.getFP(0);
TEST_ASSERT(fp);
TEST_ASSERT(fp->getNumBits() == 2048);
TEST_ASSERT(fp->getNumOnBits() == 17);
Expand All @@ -231,8 +231,8 @@ void test4LazyFPBReaderBasics() {
}
}
{ // operator[] version
std::pair<boost::shared_ptr<ExplicitBitVect>, std::string> tpl = fps[0];
boost::shared_ptr<ExplicitBitVect> fp = tpl.first;
std::pair<std::shared_ptr<ExplicitBitVect>, std::string> tpl = fps[0];
std::shared_ptr<ExplicitBitVect> fp = tpl.first;
TEST_ASSERT(fp);
TEST_ASSERT(fp->getNumBits() == 2048);
TEST_ASSERT(fp->getNumOnBits() == 17);
Expand All @@ -244,7 +244,7 @@ void test4LazyFPBReaderBasics() {
TEST_ASSERT(tpl.second == "ZINC00902219");
}
{ // test another fp
boost::shared_ptr<ExplicitBitVect> fp = fps.getFP(3);
std::shared_ptr<ExplicitBitVect> fp = fps.getFP(3);
TEST_ASSERT(fp);
TEST_ASSERT(fp->getNumBits() == 2048);
TEST_ASSERT(fp->getNumOnBits() == 20);
Expand Down Expand Up @@ -279,7 +279,7 @@ void test5LazyFPBReaderTanimoto() {
TEST_ASSERT(feq(fps.getTanimoto(1, bytes), 0.3703));
}
{
boost::shared_ptr<ExplicitBitVect> ebv = fps.getFP(0);
std::shared_ptr<ExplicitBitVect> ebv = fps.getFP(0);
TEST_ASSERT(ebv);
TEST_ASSERT(feq(fps.getTanimoto(0, *ebv.get()), 1.0));
TEST_ASSERT(feq(fps.getTanimoto(1, *ebv.get()), 0.3703));
Expand Down Expand Up @@ -339,7 +339,7 @@ void test6LazyFPBReaderTanimotoNeighbors() {
TEST_ASSERT(nbrs[1].second == 89);
}
{ // ebv with a threshold
boost::shared_ptr<ExplicitBitVect> ebv = fps.getFP(95);
std::shared_ptr<ExplicitBitVect> ebv = fps.getFP(95);
TEST_ASSERT(ebv);
std::vector<std::pair<double, unsigned int>> nbrs =
fps.getTanimotoNeighbors(*ebv.get(), 0.30);
Expand Down Expand Up @@ -454,7 +454,7 @@ void test8FPBReaderContains() {
TEST_ASSERT(nbrs[3] == 88);
}
{
boost::shared_ptr<ExplicitBitVect> ebv = fps.getFP(87);
std::shared_ptr<ExplicitBitVect> ebv = fps.getFP(87);
TEST_ASSERT(ebv);
std::vector<unsigned int> nbrs = fps.getContainingNeighbors(*ebv.get());
TEST_ASSERT(nbrs.size() == 4);
Expand Down
4 changes: 2 additions & 2 deletions Code/Demos/boost/smartPtrsAndIters/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <boost/python/detail/api_placeholder.hpp>
#include <boost/shared_ptr.hpp>
#include <memory>

#include <vector>

Expand All @@ -20,7 +20,7 @@ class DemoKlass {
private:
int val_;
};
typedef boost::shared_ptr<DemoKlass> DemoKlassSPtr;
typedef std::shared_ptr<DemoKlass> DemoKlassSPtr;
typedef std::vector<DemoKlass *> DemoKlassPtrVect;
typedef std::vector<DemoKlassSPtr> DemoKlassSPtrVect;

Expand Down
2 changes: 1 addition & 1 deletion Code/DistGeom/BoundsMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class RDKIT_DISTGEOMETRY_EXPORT BoundsMatrix
}
};

typedef boost::shared_ptr<BoundsMatrix> BoundsMatPtr;
typedef std::shared_ptr<BoundsMatrix> BoundsMatPtr;
} // namespace DistGeom

#endif
2 changes: 1 addition & 1 deletion Code/DistGeom/ChiralSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class RDKIT_DISTGEOMETRY_EXPORT ChiralSet {
inline double getLowerVolumeBound() const { return d_volumeLowerBound; }
};

typedef boost::shared_ptr<ChiralSet> ChiralSetPtr;
typedef std::shared_ptr<ChiralSet> ChiralSetPtr;
typedef std::vector<ChiralSetPtr> VECT_CHIRALSET;
} // namespace DistGeom

Expand Down
2 changes: 1 addition & 1 deletion Code/ForceField/ForceField.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ computeDihedral(const RDGeom::Point3D *p1, const RDGeom::Point3D *p2,
namespace ForceFields {
class ForceFieldContrib;
typedef std::vector<int> INT_VECT;
typedef boost::shared_ptr<const ForceFieldContrib> ContribPtr;
typedef std::shared_ptr<const ForceFieldContrib> ContribPtr;
typedef std::vector<ContribPtr> ContribPtrVect;

//-------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions Code/ForceField/Wrap/PyForceField.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <ForceField/MMFF/Params.h>
#include <GraphMol/Trajectory/Snapshot.h>
#include <boost/python/tuple.hpp>
#include <boost/shared_ptr.hpp>
#include <memory>
#include <vector>
#include <algorithm>
#include <Geometry/point.h>
Expand All @@ -36,7 +36,7 @@ class PyForceField {
int addExtraPoint(double x, double y, double z, bool fixed = true) {
PRECONDITION(this->field, "no force field");
RDGeom::Point3D *pt = new RDGeom::Point3D(x, y, z);
this->extraPoints.push_back(boost::shared_ptr<RDGeom::Point3D>(pt));
this->extraPoints.push_back(std::shared_ptr<RDGeom::Point3D>(pt));
unsigned int ptIdx = this->extraPoints.size() - 1;
RDGeom::Point3D *ptr = this->extraPoints[ptIdx].get();
this->field->positions().push_back(ptr);
Expand Down Expand Up @@ -79,8 +79,8 @@ class PyForceField {
}

// private:
std::vector<boost::shared_ptr<RDGeom::Point3D>> extraPoints;
boost::shared_ptr<ForceField> field;
std::vector<std::shared_ptr<RDGeom::Point3D>> extraPoints;
std::shared_ptr<ForceField> field;
};

class PyMMFFMolProperties {
Expand Down Expand Up @@ -153,7 +153,7 @@ class PyMMFFMolProperties {
void setMMFFVerbosity(unsigned int verbosity) {
mmffMolProperties->setMMFFVerbosity(verbosity);
}
boost::shared_ptr<RDKit::MMFF::MMFFMolProperties> mmffMolProperties;
std::shared_ptr<RDKit::MMFF::MMFFMolProperties> mmffMolProperties;
};
PyObject *getUFFBondStretchParams(const RDKit::ROMol &mol,
const unsigned int idx1,
Expand Down
2 changes: 1 addition & 1 deletion Code/Geometry/point.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ class RDKIT_RDGEOMETRYLIB_EXPORT Point2D : public Point {

class RDKIT_RDGEOMETRYLIB_EXPORT PointND : public Point {
public:
typedef boost::shared_ptr<RDNumeric::Vector<double>> VECT_SH_PTR;
typedef std::shared_ptr<RDNumeric::Vector<double>> VECT_SH_PTR;

PointND(unsigned int dim) {
RDNumeric::Vector<double> *nvec = new RDNumeric::Vector<double>(dim, 0.0);
Expand Down
4 changes: 2 additions & 2 deletions Code/GraphMol/Basement/FeatTrees/FeatTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <boost/graph/adjacency_list.hpp>
#include <boost/property_map.hpp>
#include <boost/shared_ptr.hpp>
#include <memory>
#include <set>

namespace RDKit {
Expand Down Expand Up @@ -44,7 +44,7 @@ typedef boost::property<FeatTreeEdge_t, unsigned int> FeatTreeEdge;
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
FeatTreeNode, FeatTreeEdge>
FeatTreeGraph;
typedef boost::shared_ptr<FeatTreeGraph> FeatTreeGraphSPtr;
typedef std::shared_ptr<FeatTreeGraph> FeatTreeGraphSPtr;

typedef boost::property_map<FeatTreeGraph, FeatTreeEdge_t>::type
FeatTreeEdgePMap;
Expand Down
4 changes: 2 additions & 2 deletions Code/GraphMol/ChemReactions/Enumerate/EnumerateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ namespace RDKit {
class RDKIT_CHEMREACTIONS_EXPORT EnumerateLibraryBase {
protected:
ChemicalReaction m_rxn;
boost::shared_ptr<EnumerationStrategyBase> m_enumerator;
boost::shared_ptr<EnumerationStrategyBase> m_initialEnumerator;
std::shared_ptr<EnumerationStrategyBase> m_enumerator;
std::shared_ptr<EnumerationStrategyBase> m_initialEnumerator;

public:
//! default constructor
Expand Down
13 changes: 6 additions & 7 deletions Code/GraphMol/ChemReactions/Enumerate/EnumerationPickler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ std::string GetClass(const EnumerationStrategyBase *en) {

namespace EnumerationStrategyPickler {

void pickle(const boost::shared_ptr<EnumerationStrategyBase> &enumerator,
void pickle(const std::shared_ptr<EnumerationStrategyBase> &enumerator,
std::ostream &ss) {
#ifdef RDK_USE_BOOST_SERIALIZATION
boost::archive::text_oarchive ar(ss);
Expand All @@ -72,7 +72,7 @@ void pickle(const boost::shared_ptr<EnumerationStrategyBase> &enumerator,
#endif
}

void pickle(const boost::shared_ptr<EnumerationStrategyBase> &enumerator,
void pickle(const std::shared_ptr<EnumerationStrategyBase> &enumerator,
std::string &s) {
#ifdef RDK_USE_BOOST_SERIALIZATION
std::stringstream ss;
Expand All @@ -85,8 +85,8 @@ void pickle(const boost::shared_ptr<EnumerationStrategyBase> &enumerator,
#endif
}

boost::shared_ptr<EnumerationStrategyBase> fromPickle(std::istream &pickle) {
boost::shared_ptr<EnumerationStrategyBase> enumerator;
std::shared_ptr<EnumerationStrategyBase> fromPickle(std::istream &pickle) {
std::shared_ptr<EnumerationStrategyBase> enumerator;
#ifdef RDK_USE_BOOST_SERIALIZATION
boost::archive::text_iarchive ar(pickle);
ar &enumerator;
Expand All @@ -97,15 +97,14 @@ boost::shared_ptr<EnumerationStrategyBase> fromPickle(std::istream &pickle) {
#endif
}

boost::shared_ptr<EnumerationStrategyBase> fromPickle(
const std::string &pickle) {
std::shared_ptr<EnumerationStrategyBase> fromPickle(const std::string &pickle) {
#ifdef RDK_USE_BOOST_SERIALIZATION
std::stringstream ss(pickle);
return fromPickle(ss);
#else
RDUNUSED_PARAM(pickle);
PRECONDITION(0, "BOOST SERIALIZATION NOT INSTALLED");
return boost::shared_ptr<EnumerationStrategyBase>();
return std::shared_ptr<EnumerationStrategyBase>();
#endif
}
} // namespace EnumerationStrategyPickler
Expand Down
13 changes: 6 additions & 7 deletions Code/GraphMol/ChemReactions/Enumerate/EnumerationPickler.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,20 @@ namespace RDKit {
namespace EnumerationStrategyPickler {
//! pickles a EnumerationStrategy and adds the results to a stream \c ss
RDKIT_CHEMREACTIONS_EXPORT void pickle(
const boost::shared_ptr<EnumerationStrategyBase> &enumerator,
const std::shared_ptr<EnumerationStrategyBase> &enumerator,
std::ostream &ss);
RDKIT_CHEMREACTIONS_EXPORT void pickle(
const boost::shared_ptr<EnumerationStrategyBase> &enumerator,
std::string &s);
const std::shared_ptr<EnumerationStrategyBase> &enumerator, std::string &s);

//! constructs a EnumerationStrategy from a pickle stored in a string
//! Since an EnumerationStrategyBase is polymorphic, this must return
//! a shared pointer to the EnumerationStrategyBase
RDKIT_CHEMREACTIONS_EXPORT boost::shared_ptr<EnumerationStrategyBase>
fromPickle(std::istream &pickle);
RDKIT_CHEMREACTIONS_EXPORT std::shared_ptr<EnumerationStrategyBase> fromPickle(
std::istream &pickle);

//! a pointer to the EnumerationStrategyBase
RDKIT_CHEMREACTIONS_EXPORT boost::shared_ptr<EnumerationStrategyBase>
fromPickle(const std::string &pickle);
RDKIT_CHEMREACTIONS_EXPORT std::shared_ptr<EnumerationStrategyBase> fromPickle(
const std::string &pickle);
} // namespace EnumerationStrategyPickler
} // namespace RDKit

Expand Down