File tree Expand file tree Collapse file tree 5 files changed +9
-7
lines changed
include/lsst/afw/typehandling Expand file tree Collapse file tree 5 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -137,7 +137,8 @@ class PolymorphicValue final {
137
137
std::size_t hash_value () const ;
138
138
139
139
private:
140
- std::unique_ptr<Storable> _value;
140
+ // unique_ptr would be more appropriate, but Storable::cloneStorable must return shared_ptr
141
+ std::shared_ptr<Storable> _value;
141
142
};
142
143
143
144
} // namespace typehandling
Original file line number Diff line number Diff line change @@ -73,7 +73,8 @@ class Storable : public table::io::Persistable {
73
73
* @note If this class supports a `clone` operation, the two should behave
74
74
* identically except for the formal return type.
75
75
*/
76
- virtual std::unique_ptr<Storable> cloneStorable () const ;
76
+ // Return shared_ptr to work around https://github.com/pybind/pybind11/issues/1138
77
+ virtual std::shared_ptr<Storable> cloneStorable () const ;
77
78
78
79
/* *
79
80
* Create a string representation of this object (optional operation).
Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ class SimpleStorable : public Storable {
59
59
public:
60
60
virtual ~SimpleStorable () = default ;
61
61
62
- std::unique_ptr <Storable> cloneStorable () const override { return std::make_unique<SimpleStorable>(); }
62
+ std::shared_ptr <Storable> cloneStorable () const override { return std::make_unique<SimpleStorable>(); }
63
63
64
64
std::string toString () const override { return " Simplest possible representation" ; }
65
65
@@ -80,7 +80,7 @@ class ComplexStorable final : public SimpleStorable {
80
80
return *this ;
81
81
}
82
82
83
- std::unique_ptr <Storable> cloneStorable () const override {
83
+ std::shared_ptr <Storable> cloneStorable () const override {
84
84
return std::make_unique<ComplexStorable>(storage);
85
85
}
86
86
Original file line number Diff line number Diff line change @@ -32,12 +32,12 @@ namespace typehandling {
32
32
33
33
PolymorphicValue::PolymorphicValue (Storable const & value) : _value(value.cloneStorable()) {}
34
34
// No move-constructor, because putting a pointer to Storable&& into a
35
- // unique_ptr is safe only if the object was dynamically allocated
35
+ // shared_ptr is safe only if the object was dynamically allocated
36
36
37
37
PolymorphicValue::~PolymorphicValue () noexcept = default ;
38
38
39
39
PolymorphicValue::PolymorphicValue (PolymorphicValue const & other)
40
- : _value(other._value ? other._value->cloneStorable () : std::unique_ptr<Storable>() ) {}
40
+ : _value(other._value ? other._value->cloneStorable () : nullptr ) {}
41
41
PolymorphicValue::PolymorphicValue (PolymorphicValue&&) = default; // other._value emptied
42
42
43
43
PolymorphicValue& PolymorphicValue::operator =(PolymorphicValue const & other) {
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ namespace typehandling {
33
33
34
34
Storable::~Storable () noexcept {}
35
35
36
- std::unique_ptr <Storable> Storable::cloneStorable () const {
36
+ std::shared_ptr <Storable> Storable::cloneStorable () const {
37
37
throw LSST_EXCEPT (UnsupportedOperationException, " Cloning is not supported." );
38
38
}
39
39
You can’t perform that action at this time.
0 commit comments