leveldb
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
leveldb::Status Class Reference

#include <status.h>

Public Member Functions

 Status ()
 
 ~Status ()
 
 Status (const Status &s)
 
void operator= (const Status &s)
 
bool ok () const
 
bool IsNotFound () const
 
bool IsCorruption () const
 
bool IsIOError () const
 
bool IsNotSupportedError () const
 
bool IsInvalidArgument () const
 
std::string ToString () const
 

Static Public Member Functions

static Status OK ()
 
static Status NotFound (const Slice &msg, const Slice &msg2=Slice())
 
static Status Corruption (const Slice &msg, const Slice &msg2=Slice())
 
static Status NotSupported (const Slice &msg, const Slice &msg2=Slice())
 
static Status InvalidArgument (const Slice &msg, const Slice &msg2=Slice())
 
static Status IOError (const Slice &msg, const Slice &msg2=Slice())
 

Private Types

enum  Code {
  kOk = 0, kNotFound = 1, kCorruption = 2, kNotSupported = 3,
  kInvalidArgument = 4, kIOError = 5
}
 

Private Member Functions

Code code () const
 
 Status (Code code, const Slice &msg, const Slice &msg2)
 

Static Private Member Functions

static const char * CopyState (const char *s)
 

Private Attributes

const char * state_
 

Detailed Description

Definition at line 21 of file status.h.

Member Enumeration Documentation

§ Code

enum leveldb::Status::Code
private
Enumerator
kOk 
kNotFound 
kCorruption 
kNotSupported 
kInvalidArgument 
kIOError 

Definition at line 81 of file status.h.

Constructor & Destructor Documentation

§ Status() [1/3]

leveldb::Status::Status ( )
inline

Definition at line 24 of file status.h.

24 : state_(NULL) { }
const char * state_
Definition: status.h:79
Here is the caller graph for this function:

§ ~Status()

leveldb::Status::~Status ( )
inline

Definition at line 25 of file status.h.

25 { delete[] state_; }
const char * state_
Definition: status.h:79
Here is the call graph for this function:

§ Status() [2/3]

leveldb::Status::Status ( const Status s)
inline

Definition at line 98 of file status.h.

98  {
99  state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
100 }
static const char * CopyState(const char *s)
Definition: status.cc:11
const char * state_
Definition: status.h:79
Here is the call graph for this function:

§ Status() [3/3]

leveldb::Status::Status ( Code  code,
const Slice msg,
const Slice msg2 
)
private

Definition at line 19 of file status.cc.

19  {
20  assert(code != kOk);
21  const uint32_t len1 = msg.size();
22  const uint32_t len2 = msg2.size();
23  const uint32_t size = len1 + (len2 ? (2 + len2) : 0);
24  char* result = new char[size + 5];
25  memcpy(result, &size, sizeof(size));
26  result[4] = static_cast<char>(code);
27  memcpy(result + 5, msg.data(), len1);
28  if (len2) {
29  result[5 + len1] = ':';
30  result[6 + len1] = ' ';
31  memcpy(result + 7 + len1, msg2.data(), len2);
32  }
33  state_ = result;
34 }
const char * state_
Definition: status.h:79
Code code() const
Definition: status.h:90
Here is the call graph for this function:

Member Function Documentation

§ code()

Code leveldb::Status::code ( ) const
inlineprivate

Definition at line 90 of file status.h.

90  {
91  return (state_ == NULL) ? kOk : static_cast<Code>(state_[4]);
92  }
const char * state_
Definition: status.h:79
Here is the call graph for this function:
Here is the caller graph for this function:

§ CopyState()

const char * leveldb::Status::CopyState ( const char *  s)
staticprivate

Definition at line 11 of file status.cc.

11  {
12  uint32_t size;
13  memcpy(&size, state, sizeof(size));
14  char* result = new char[size + 5];
15  memcpy(result, state, size + 5);
16  return result;
17 }
Here is the caller graph for this function:

§ Corruption()

static Status leveldb::Status::Corruption ( const Slice msg,
const Slice msg2 = Slice() 
)
inlinestatic

Definition at line 38 of file status.h.

38  {
39  return Status(kCorruption, msg, msg2);
40  }
Here is the call graph for this function:
Here is the caller graph for this function:

§ InvalidArgument()

static Status leveldb::Status::InvalidArgument ( const Slice msg,
const Slice msg2 = Slice() 
)
inlinestatic

Definition at line 44 of file status.h.

44  {
45  return Status(kInvalidArgument, msg, msg2);
46  }
Here is the call graph for this function:
Here is the caller graph for this function:

§ IOError()

static Status leveldb::Status::IOError ( const Slice msg,
const Slice msg2 = Slice() 
)
inlinestatic

Definition at line 47 of file status.h.

47  {
48  return Status(kIOError, msg, msg2);
49  }
Here is the call graph for this function:
Here is the caller graph for this function:

§ IsCorruption()

bool leveldb::Status::IsCorruption ( ) const
inline

Definition at line 58 of file status.h.

58 { return code() == kCorruption; }
Code code() const
Definition: status.h:90
Here is the call graph for this function:

§ IsInvalidArgument()

bool leveldb::Status::IsInvalidArgument ( ) const
inline

Definition at line 67 of file status.h.

67 { return code() == kInvalidArgument; }
Code code() const
Definition: status.h:90
Here is the call graph for this function:

§ IsIOError()

bool leveldb::Status::IsIOError ( ) const
inline

Definition at line 61 of file status.h.

61 { return code() == kIOError; }
Code code() const
Definition: status.h:90
Here is the call graph for this function:

§ IsNotFound()

bool leveldb::Status::IsNotFound ( ) const
inline

Definition at line 55 of file status.h.

55 { return code() == kNotFound; }
Code code() const
Definition: status.h:90
Here is the call graph for this function:
Here is the caller graph for this function:

§ IsNotSupportedError()

bool leveldb::Status::IsNotSupportedError ( ) const
inline

Definition at line 64 of file status.h.

64 { return code() == kNotSupported; }
Code code() const
Definition: status.h:90
Here is the call graph for this function:
Here is the caller graph for this function:

§ NotFound()

static Status leveldb::Status::NotFound ( const Slice msg,
const Slice msg2 = Slice() 
)
inlinestatic

Definition at line 35 of file status.h.

35  {
36  return Status(kNotFound, msg, msg2);
37  }
Here is the call graph for this function:
Here is the caller graph for this function:

§ NotSupported()

static Status leveldb::Status::NotSupported ( const Slice msg,
const Slice msg2 = Slice() 
)
inlinestatic

Definition at line 41 of file status.h.

41  {
42  return Status(kNotSupported, msg, msg2);
43  }
Here is the call graph for this function:
Here is the caller graph for this function:

§ OK()

static Status leveldb::Status::OK ( )
inlinestatic

Definition at line 32 of file status.h.

32 { return Status(); }
Here is the call graph for this function:

§ ok()

bool leveldb::Status::ok ( ) const
inline

Definition at line 52 of file status.h.

52 { return (state_ == NULL); }
const char * state_
Definition: status.h:79

§ operator=()

void leveldb::Status::operator= ( const Status s)
inline

Definition at line 101 of file status.h.

101  {
102  // The following condition catches both aliasing (when this == &s),
103  // and the common case where both s and *this are ok.
104  if (state_ != s.state_) {
105  delete[] state_;
106  state_ = (s.state_ == NULL) ? NULL : CopyState(s.state_);
107  }
108 }
static const char * CopyState(const char *s)
Definition: status.cc:11
const char * state_
Definition: status.h:79
Here is the call graph for this function:
Here is the caller graph for this function:

§ ToString()

std::string leveldb::Status::ToString ( ) const

Definition at line 36 of file status.cc.

36  {
37  if (state_ == NULL) {
38  return "OK";
39  } else {
40  char tmp[30];
41  const char* type;
42  switch (code()) {
43  case kOk:
44  type = "OK";
45  break;
46  case kNotFound:
47  type = "NotFound: ";
48  break;
49  case kCorruption:
50  type = "Corruption: ";
51  break;
52  case kNotSupported:
53  type = "Not implemented: ";
54  break;
55  case kInvalidArgument:
56  type = "Invalid argument: ";
57  break;
58  case kIOError:
59  type = "IO error: ";
60  break;
61  default:
62  snprintf(tmp, sizeof(tmp), "Unknown code(%d): ",
63  static_cast<int>(code()));
64  type = tmp;
65  break;
66  }
67  std::string result(type);
68  uint32_t length;
69  memcpy(&length, state_, sizeof(length));
70  result.append(state_ + 5, length);
71  return result;
72  }
73 }
const char * state_
Definition: status.h:79
Code code() const
Definition: status.h:90
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

§ state_

const char* leveldb::Status::state_
private

Definition at line 79 of file status.h.


The documentation for this class was generated from the following files: