]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/include/rocksdb/utilities/ldb_cmd_execute_result.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / include / rocksdb / utilities / ldb_cmd_execute_result.h
CommitLineData
7c673cae 1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
11fdf7f2
TL
2// This source code is licensed under both the GPLv2 (found in the
3// COPYING file in the root directory) and Apache 2.0 License
4// (found in the LICENSE.Apache file in the root directory).
7c673cae
FG
5//
6#pragma once
7
8#ifdef FAILED
9#undef FAILED
10#endif
11
12namespace rocksdb {
13
14class LDBCommandExecuteResult {
15public:
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
67private:
68 State state_;
69 std::string message_;
70
71 bool operator==(const LDBCommandExecuteResult&);
72 bool operator!=(const LDBCommandExecuteResult&);
73};
74
75}