Add util::blob::operator bool() and util::blob::swap
This commit is contained in:
parent
1e1679ffe0
commit
bfff9b2c4d
1 changed files with 14 additions and 7 deletions
|
|
@ -27,9 +27,13 @@ namespace psemek::util
|
|||
|
||||
std::size_t size() const { return size_; }
|
||||
|
||||
explicit operator bool() const { return static_cast<bool>(data_); }
|
||||
|
||||
void reset();
|
||||
std::unique_ptr<char[]> release();
|
||||
|
||||
void swap(blob & other);
|
||||
|
||||
using iterator = char *;
|
||||
using const_iterator = char const *;
|
||||
|
||||
|
|
@ -56,8 +60,10 @@ namespace psemek::util
|
|||
}
|
||||
|
||||
inline blob::blob(blob && other)
|
||||
: data_{std::move(other.data_)}
|
||||
, size_{other.size_}
|
||||
{
|
||||
*this = std::move(other);
|
||||
other.size_ = 0;
|
||||
}
|
||||
|
||||
inline blob::blob(std::size_t size)
|
||||
|
|
@ -88,12 +94,7 @@ namespace psemek::util
|
|||
|
||||
inline blob & blob::operator=(blob && other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
data_ = std::move(other.data_);
|
||||
size_ = other.size();
|
||||
other.size_ = 0;
|
||||
}
|
||||
blob(std::move(other)).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
@ -109,6 +110,12 @@ namespace psemek::util
|
|||
return std::move(data_);
|
||||
}
|
||||
|
||||
inline void blob::swap(blob & other)
|
||||
{
|
||||
std::swap(data_, other.data_);
|
||||
std::swap(size_, other.size_);
|
||||
}
|
||||
|
||||
inline std::string blob::string() const
|
||||
{
|
||||
return std::string(data_.get(), data_.get() + size_);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue