Skip to content

Commit 4131bba

Browse files
[Device] Remove weak pointer to itself and use shared_from_this instead.
1 parent c49c10e commit 4131bba

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

include/hpp/manipulation/device.hh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class HPP_MANIPULATION_DLLAPI Device
5555
/// \param name of the new instance,
5656
static DevicePtr_t create(const std::string& name);
5757

58-
DevicePtr_t self() const { return self_.lock(); }
58+
DevicePtr_t self() { return shared_from_this(); }
5959

6060
/// Print object in a stream
6161
virtual std::ostream& print(std::ostream& os) const;
@@ -85,20 +85,15 @@ class HPP_MANIPULATION_DLLAPI Device
8585

8686
void init(const DeviceWkPtr_t& self) {
8787
Parent_t::init(self);
88-
self_ = self;
8988
}
9089

9190
void initCopy(const DeviceWkPtr_t& self, const Device& other) {
9291
Parent_t::initCopy(self, other);
93-
self_ = self;
9492
}
9593

9694
/// For serialization only
9795
Device() {}
9896

99-
private:
100-
DeviceWkPtr_t self_;
101-
10297
HPP_SERIALIZABLE();
10398
}; // class Device
10499
} // namespace manipulation

src/device.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void Device::removeJoints(const std::vector<std::string>& jointNames,
139139
Parent_t::removeJoints(jointNames, referenceConfig);
140140

141141
for (auto& pair : grippers.map)
142-
pair.second = pinocchio::Gripper::create(pair.second->name(), self_);
142+
pair.second = pinocchio::Gripper::create(pair.second->name(), shared_from_this());
143143
// TODO update handles and jointAndShapes
144144
}
145145

@@ -169,7 +169,6 @@ void Device::serialize(Archive& ar, const unsigned int version) {
169169
name_, false) != this);
170170
ar& BOOST_SERIALIZATION_NVP(written);
171171
if (written) {
172-
ar& BOOST_SERIALIZATION_NVP(self_);
173172
// TODO (easy) add serialization of core::Container ?
174173
// ar & BOOST_SERIALIZATION_NVP(handles);
175174
// ar & BOOST_SERIALIZATION_NVP(grippers);

0 commit comments

Comments
 (0)