rocksdb/include/rocksdb/utilities/ldb_cmd_execute_result.h
sdong fdf882ded2 Replace namespace name "rocksdb" with ROCKSDB_NAMESPACE (#6433)
Summary:
When dynamically linking two binaries together, different builds of RocksDB from two sources might cause errors. To provide a tool for user to solve the problem, the RocksDB namespace is changed to a flag which can be overridden in build time.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6433

Test Plan: Build release, all and jtest. Try to build with ROCKSDB_NAMESPACE with another flag.

Differential Revision: D19977691

fbshipit-source-id: aa7f2d0972e1c31d75339ac48478f34f6cfcfb3e
2020-02-20 12:09:57 -08:00

72 lines
1.6 KiB
C++

// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
// This source code is licensed under both the GPLv2 (found in the
// COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory).
//
#pragma once
#ifdef FAILED
#undef FAILED
#endif
namespace ROCKSDB_NAMESPACE {
class LDBCommandExecuteResult {
public:
enum State {
EXEC_NOT_STARTED = 0,
EXEC_SUCCEED = 1,
EXEC_FAILED = 2,
};
LDBCommandExecuteResult() : state_(EXEC_NOT_STARTED), message_("") {}
LDBCommandExecuteResult(State state, std::string& msg)
: state_(state), message_(msg) {}
std::string ToString() {
std::string ret;
switch (state_) {
case EXEC_SUCCEED:
break;
case EXEC_FAILED:
ret.append("Failed: ");
break;
case EXEC_NOT_STARTED:
ret.append("Not started: ");
}
if (!message_.empty()) {
ret.append(message_);
}
return ret;
}
void Reset() {
state_ = EXEC_NOT_STARTED;
message_ = "";
}
bool IsSucceed() { return state_ == EXEC_SUCCEED; }
bool IsNotStarted() { return state_ == EXEC_NOT_STARTED; }
bool IsFailed() { return state_ == EXEC_FAILED; }
static LDBCommandExecuteResult Succeed(std::string msg) {
return LDBCommandExecuteResult(EXEC_SUCCEED, msg);
}
static LDBCommandExecuteResult Failed(std::string msg) {
return LDBCommandExecuteResult(EXEC_FAILED, msg);
}
private:
State state_;
std::string message_;
bool operator==(const LDBCommandExecuteResult&);
bool operator!=(const LDBCommandExecuteResult&);
};
} // namespace ROCKSDB_NAMESPACE