1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. 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). 5 // 6 #pragma once 7 8 #ifdef FAILED 9 #undef FAILED 10 #endif 11 12 namespace ROCKSDB_NAMESPACE { 13 14 class LDBCommandExecuteResult { 15 public: 16 enum State { 17 EXEC_NOT_STARTED = 0, 18 EXEC_SUCCEED = 1, 19 EXEC_FAILED = 2, 20 }; 21 LDBCommandExecuteResult()22 LDBCommandExecuteResult() : state_(EXEC_NOT_STARTED), message_("") {} 23 LDBCommandExecuteResult(State state,std::string & msg)24 LDBCommandExecuteResult(State state, std::string& msg) 25 : state_(state), message_(msg) {} 26 ToString()27 std::string ToString() { 28 std::string ret; 29 switch (state_) { 30 case EXEC_SUCCEED: 31 break; 32 case EXEC_FAILED: 33 ret.append("Failed: "); 34 break; 35 case EXEC_NOT_STARTED: 36 ret.append("Not started: "); 37 } 38 if (!message_.empty()) { 39 ret.append(message_); 40 } 41 return ret; 42 } 43 Reset()44 void Reset() { 45 state_ = EXEC_NOT_STARTED; 46 message_ = ""; 47 } 48 IsSucceed()49 bool IsSucceed() { return state_ == EXEC_SUCCEED; } 50 IsNotStarted()51 bool IsNotStarted() { return state_ == EXEC_NOT_STARTED; } 52 IsFailed()53 bool IsFailed() { return state_ == EXEC_FAILED; } 54 Succeed(std::string msg)55 static LDBCommandExecuteResult Succeed(std::string msg) { 56 return LDBCommandExecuteResult(EXEC_SUCCEED, msg); 57 } 58 Failed(std::string msg)59 static LDBCommandExecuteResult Failed(std::string msg) { 60 return LDBCommandExecuteResult(EXEC_FAILED, msg); 61 } 62 63 private: 64 State state_; 65 std::string message_; 66 67 bool operator==(const LDBCommandExecuteResult&); 68 bool operator!=(const LDBCommandExecuteResult&); 69 }; 70 71 } // namespace ROCKSDB_NAMESPACE 72