Give WalletModel::UnlockContext move semantics

This commit is contained in:
Pieter Wuille 2019-05-09 18:07:33 -07:00
parent 79046d5749
commit 0b09a57aec
2 changed files with 8 additions and 5 deletions

View file

@ -482,7 +482,7 @@ WalletModel::UnlockContext::~UnlockContext()
}
}
void WalletModel::UnlockContext::CopyFrom(const UnlockContext& rhs)
void WalletModel::UnlockContext::CopyFrom(UnlockContext&& rhs)
{
// Transfer context; old object no longer relocks wallet
*this = rhs;

View file

@ -194,15 +194,18 @@ public:
bool isValid() const { return valid; }
// Copy operator and constructor transfer the context
UnlockContext(const UnlockContext& obj) { CopyFrom(obj); }
UnlockContext& operator=(const UnlockContext& rhs) { CopyFrom(rhs); return *this; }
// Copy constructor is disabled.
UnlockContext(const UnlockContext&) = delete;
// Move operator and constructor transfer the context
UnlockContext(UnlockContext&& obj) { CopyFrom(std::move(obj)); }
UnlockContext& operator=(UnlockContext&& rhs) { CopyFrom(std::move(rhs)); return *this; }
private:
WalletModel *wallet;
bool valid;
mutable bool relock; // mutable, as it can be set to false by copying
void CopyFrom(const UnlockContext& rhs);
UnlockContext& operator=(const UnlockContext&) = default;
void CopyFrom(UnlockContext&& rhs);
};
UnlockContext requestUnlock();