|
@ -13,6 +13,7 @@ |
|
|
#ifndef STORAGE_LEVELDB_INCLUDE_STATUS_H_ |
|
|
#ifndef STORAGE_LEVELDB_INCLUDE_STATUS_H_ |
|
|
#define STORAGE_LEVELDB_INCLUDE_STATUS_H_ |
|
|
#define STORAGE_LEVELDB_INCLUDE_STATUS_H_ |
|
|
|
|
|
|
|
|
|
|
|
#include <algorithm> |
|
|
#include <string> |
|
|
#include <string> |
|
|
#include "leveldb/export.h" |
|
|
#include "leveldb/export.h" |
|
|
#include "leveldb/slice.h" |
|
|
#include "leveldb/slice.h" |
|
@ -22,12 +23,14 @@ namespace leveldb { |
|
|
class LEVELDB_EXPORT Status { |
|
|
class LEVELDB_EXPORT Status { |
|
|
public: |
|
|
public: |
|
|
// Create a success status. |
|
|
// Create a success status. |
|
|
Status() : state_(nullptr) { } |
|
|
|
|
|
|
|
|
Status() noexcept : state_(nullptr) { } |
|
|
~Status() { delete[] state_; } |
|
|
~Status() { delete[] state_; } |
|
|
|
|
|
|
|
|
// Copy the specified status. |
|
|
|
|
|
Status(const Status& s); |
|
|
|
|
|
void operator=(const Status& s); |
|
|
|
|
|
|
|
|
Status(const Status& rhs); |
|
|
|
|
|
Status& operator=(const Status& rhs); |
|
|
|
|
|
|
|
|
|
|
|
Status(Status&& rhs) noexcept : state_(rhs.state_) { rhs.state_ = nullptr; } |
|
|
|
|
|
Status& operator=(Status&& rhs) noexcept; |
|
|
|
|
|
|
|
|
// Return a success status. |
|
|
// Return a success status. |
|
|
static Status OK() { return Status(); } |
|
|
static Status OK() { return Status(); } |
|
@ -96,16 +99,21 @@ class LEVELDB_EXPORT Status { |
|
|
static const char* CopyState(const char* s); |
|
|
static const char* CopyState(const char* s); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
inline Status::Status(const Status& s) { |
|
|
|
|
|
state_ = (s.state_ == nullptr) ? nullptr : CopyState(s.state_); |
|
|
|
|
|
|
|
|
inline Status::Status(const Status& rhs) { |
|
|
|
|
|
state_ = (rhs.state_ == nullptr) ? nullptr : CopyState(rhs.state_); |
|
|
} |
|
|
} |
|
|
inline void Status::operator=(const Status& s) { |
|
|
|
|
|
// The following condition catches both aliasing (when this == &s), |
|
|
|
|
|
// and the common case where both s and *this are ok. |
|
|
|
|
|
if (state_ != s.state_) { |
|
|
|
|
|
|
|
|
inline Status& Status::operator=(const Status& rhs) { |
|
|
|
|
|
// The following condition catches both aliasing (when this == &rhs), |
|
|
|
|
|
// and the common case where both rhs and *this are ok. |
|
|
|
|
|
if (state_ != rhs.state_) { |
|
|
delete[] state_; |
|
|
delete[] state_; |
|
|
state_ = (s.state_ == nullptr) ? nullptr : CopyState(s.state_); |
|
|
|
|
|
|
|
|
state_ = (rhs.state_ == nullptr) ? nullptr : CopyState(rhs.state_); |
|
|
} |
|
|
} |
|
|
|
|
|
return *this; |
|
|
|
|
|
} |
|
|
|
|
|
inline Status& Status::operator=(Status&& rhs) noexcept { |
|
|
|
|
|
std::swap(state_, rhs.state_); |
|
|
|
|
|
return *this; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} // namespace leveldb |
|
|
} // namespace leveldb |
|
|