/Users/deen/code/yugabyte-db/src/yb/rocksdb/tools/ldb_cmd_execute_result.h
Line | Count | Source (jump to first uncovered line) |
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 | | // The following only applies to changes made to this file as part of YugaByte development. |
7 | | // |
8 | | // Portions Copyright (c) YugaByte, Inc. |
9 | | // |
10 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
11 | | // in compliance with the License. You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
16 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
17 | | // or implied. See the License for the specific language governing permissions and limitations |
18 | | // under the License. |
19 | | // |
20 | | #pragma once |
21 | | |
22 | | #ifdef FAILED |
23 | | #undef FAILED |
24 | | #endif |
25 | | |
26 | | namespace rocksdb { |
27 | | |
28 | | class LDBCommandExecuteResult { |
29 | | public: |
30 | | enum State { |
31 | | EXEC_NOT_STARTED = 0, EXEC_SUCCEED = 1, EXEC_FAILED = 2, |
32 | | }; |
33 | | |
34 | 12 | LDBCommandExecuteResult() : state_(EXEC_NOT_STARTED), message_("") {} |
35 | | |
36 | | LDBCommandExecuteResult(State state, std::string& msg) : |
37 | 12 | state_(state), message_(msg) {} |
38 | | |
39 | 4 | std::string ToString() { |
40 | 4 | std::string ret; |
41 | 4 | switch (state_) { |
42 | 4 | case EXEC_SUCCEED: |
43 | 4 | break; |
44 | 0 | case EXEC_FAILED: |
45 | 0 | ret.append("Failed: "); |
46 | 0 | break; |
47 | 0 | case EXEC_NOT_STARTED: |
48 | 0 | ret.append("Not started: "); |
49 | 4 | } |
50 | 4 | if (!message_.empty()) { |
51 | 0 | ret.append(message_); |
52 | 0 | } |
53 | 4 | return ret; |
54 | 4 | } |
55 | | |
56 | 0 | void Reset() { |
57 | 0 | state_ = EXEC_NOT_STARTED; |
58 | 0 | message_ = ""; |
59 | 0 | } |
60 | | |
61 | 8 | bool IsSucceed() { |
62 | 8 | return state_ == EXEC_SUCCEED; |
63 | 8 | } |
64 | | |
65 | 33 | bool IsNotStarted() { |
66 | 33 | return state_ == EXEC_NOT_STARTED; |
67 | 33 | } |
68 | | |
69 | 0 | bool IsFailed() { |
70 | 0 | return state_ == EXEC_FAILED; |
71 | 0 | } |
72 | | |
73 | 12 | static LDBCommandExecuteResult Succeed(std::string msg) { |
74 | 12 | return LDBCommandExecuteResult(EXEC_SUCCEED, msg); |
75 | 12 | } |
76 | | |
77 | 0 | static LDBCommandExecuteResult Failed(std::string msg) { |
78 | 0 | return LDBCommandExecuteResult(EXEC_FAILED, msg); |
79 | 0 | } |
80 | | |
81 | | private: |
82 | | State state_; |
83 | | std::string message_; |
84 | | |
85 | | bool operator==(const LDBCommandExecuteResult&); |
86 | | bool operator!=(const LDBCommandExecuteResult&); |
87 | | }; |
88 | | |
89 | | } |