Refactor scoped_dohptr() to reuse its reset()

No real changes, just avoid some code duplication and add an optional
argument to reset() to make it more compatible with std::unique_ptr<>
and also more flexible.
This commit is contained in:
Vadim Zeitlin 2021-11-03 01:25:16 +01:00
commit ca56f14aa5

View file

@ -42,20 +42,14 @@ public:
// Same for the assignment operator.
scoped_dohptr& operator=(scoped_dohptr const& other) {
if (&other != this) {
Delete(obj_);
obj_ = other.release();
}
reset(other.release());
return *this;
}
// Assignment operator takes ownership of the pointer, just as the ctor does.
scoped_dohptr& operator=(DOH* obj) {
if (obj != obj_) {
Delete(obj_);
obj_ = obj;
}
reset(obj);
return *this;
}
@ -68,10 +62,10 @@ public:
return obj;
}
void reset() {
if (obj_) {
void reset(DOH* obj = NULL) {
if (obj != obj_) {
Delete(obj_);
obj_ = NULL;
obj_ = obj;
}
}