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.
|
// Same for the assignment operator.
|
||||||
scoped_dohptr& operator=(scoped_dohptr const& other) {
|
scoped_dohptr& operator=(scoped_dohptr const& other) {
|
||||||
if (&other != this) {
|
reset(other.release());
|
||||||
Delete(obj_);
|
|
||||||
obj_ = other.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assignment operator takes ownership of the pointer, just as the ctor does.
|
// Assignment operator takes ownership of the pointer, just as the ctor does.
|
||||||
scoped_dohptr& operator=(DOH* obj) {
|
scoped_dohptr& operator=(DOH* obj) {
|
||||||
if (obj != obj_) {
|
reset(obj);
|
||||||
Delete(obj_);
|
|
||||||
obj_ = obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
@ -68,10 +62,10 @@ public:
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset() {
|
void reset(DOH* obj = NULL) {
|
||||||
if (obj_) {
|
if (obj != obj_) {
|
||||||
Delete(obj_);
|
Delete(obj_);
|
||||||
obj_ = NULL;
|
obj_ = obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue