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:
parent
8014af974d
commit
ca56f14aa5
1 changed files with 5 additions and 11 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue