]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/utilities/ldb_cmd_execute_result.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rocksdb / include / rocksdb / utilities / ldb_cmd_execute_result.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
5 //
6 #pragma once
7
8 #ifdef FAILED
9 #undef FAILED
10 #endif
11
12 namespace rocksdb {
13
14 class LDBCommandExecuteResult {
15 public:
16 enum State {
17 EXEC_NOT_STARTED = 0, EXEC_SUCCEED = 1, EXEC_FAILED = 2,
18 };
19
20 LDBCommandExecuteResult() : state_(EXEC_NOT_STARTED), message_("") {}
21
22 LDBCommandExecuteResult(State state, std::string& msg) :
23 state_(state), message_(msg) {}
24
25 std::string ToString() {
26 std::string ret;
27 switch (state_) {
28 case EXEC_SUCCEED:
29 break;
30 case EXEC_FAILED:
31 ret.append("Failed: ");
32 break;
33 case EXEC_NOT_STARTED:
34 ret.append("Not started: ");
35 }
36 if (!message_.empty()) {
37 ret.append(message_);
38 }
39 return ret;
40 }
41
42 void Reset() {
43 state_ = EXEC_NOT_STARTED;
44 message_ = "";
45 }
46
47 bool IsSucceed() {
48 return state_ == EXEC_SUCCEED;
49 }
50
51 bool IsNotStarted() {
52 return state_ == EXEC_NOT_STARTED;
53 }
54
55 bool IsFailed() {
56 return state_ == EXEC_FAILED;
57 }
58
59 static LDBCommandExecuteResult Succeed(std::string msg) {
60 return LDBCommandExecuteResult(EXEC_SUCCEED, msg);
61 }
62
63 static LDBCommandExecuteResult Failed(std::string msg) {
64 return LDBCommandExecuteResult(EXEC_FAILED, msg);
65 }
66
67 private:
68 State state_;
69 std::string message_;
70
71 bool operator==(const LDBCommandExecuteResult&);
72 bool operator!=(const LDBCommandExecuteResult&);
73 };
74
75 }