In reading the log file, you will find the use of Status
this class, you can use it to get state function returns, such as:
Status s = Function();
if (!s.ok()) return false;
return true
Seriously today to learn about the relevant implementation.
1. Private
-
state_
, A pointer points to a character constant. If it is successfulstate_
is null, otherwise, he is an array, index is 0 to 3 message length, a status code 4, 5 after the message itself. -
Return status is enumerated in the Status class, these states are enumerable private variables
Code
, has defined success, did not find an error, it does not support, legal parameters, IO error six cases. -
function code, and the fourth state by state_ return value is a value which enumerable
-
The constructor with no arguments. This is a very important function, because the public function mainly use this function returns the status and type.
Status::Status(Code code, const Slice& msg, const Slice& msg2)
Primarily using a memcpy
memory copy, the msg in bytes copied to the returned results, the specific process is as follows:
CopyState
Function, the state of deep copy, which opened up a new memory.
You can see here also use memcpy function, I checked the official documents , there is a comment:
std :: memcpy is supposed to be the fastest memory to memory copy routine. It is usually more than copying data to scan its std :: strcpy, or must be prevented to process overlapping input std :: memmove more efficient.
2. public
2.1 the big three
- Constructor
- Destructor
- The copy constructor - is a parameter passing const
- Mutator - mass participation is const
- The copy constructor - pass non-const reference
- Assignment Constructor - pass non-const reference
2.2 is not a certain kind of state
We have said before, a total of 6 enumerable state, so there are six public member function that returns a Boolean type is to determine the state is not OK or wrong and so on. The main use of what we said before Code
function.
2.3 and certain status information return package
The constructor function is six, using what we said before with parameters.
2.4 to String
State to turn into a string, easy to print.