Skip to content

Commit

Permalink
Revert moving status.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannic committed Mar 4, 2021
1 parent a5cc5b7 commit 3000a23
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 123 deletions.
2 changes: 1 addition & 1 deletion BUILD
Expand Up @@ -183,7 +183,7 @@ cc_library(
"src/google/protobuf/stubs/bytestream.cc",
"src/google/protobuf/stubs/common.cc",
"src/google/protobuf/stubs/int128.cc",
"src/google/protobuf/stubs/internal/status.cc",
"src/google/protobuf/stubs/status.cc",
"src/google/protobuf/stubs/statusor.cc",
"src/google/protobuf/stubs/stringpiece.cc",
"src/google/protobuf/stubs/stringprintf.cc",
Expand Down
2 changes: 1 addition & 1 deletion cmake/libprotobuf-lite.cmake
Expand Up @@ -20,7 +20,7 @@ set(libprotobuf_lite_files
${protobuf_source_dir}/src/google/protobuf/stubs/bytestream.cc
${protobuf_source_dir}/src/google/protobuf/stubs/common.cc
${protobuf_source_dir}/src/google/protobuf/stubs/int128.cc
${protobuf_source_dir}/src/google/protobuf/stubs/internal/status.cc
${protobuf_source_dir}/src/google/protobuf/stubs/status.cc
${protobuf_source_dir}/src/google/protobuf/stubs/statusor.cc
${protobuf_source_dir}/src/google/protobuf/stubs/stringpiece.cc
${protobuf_source_dir}/src/google/protobuf/stubs/stringprintf.cc
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.am
Expand Up @@ -185,7 +185,7 @@ libprotobuf_lite_la_SOURCES = \
google/protobuf/io/io_win32.cc \
google/protobuf/stubs/map_util.h \
google/protobuf/stubs/mathutil.h \
google/protobuf/stubs/internal/status.cc \
google/protobuf/stubs/status.cc \
google/protobuf/stubs/status.h \
google/protobuf/stubs/status_macros.h \
google/protobuf/stubs/statusor.cc \
Expand Down
119 changes: 0 additions & 119 deletions src/google/protobuf/stubs/internal/status.h

This file was deleted.

File renamed without changes.
78 changes: 77 additions & 1 deletion src/google/protobuf/stubs/status.h
Expand Up @@ -31,11 +31,85 @@
#ifndef GOOGLE_PROTOBUF_STUBS_STATUS_H_
#define GOOGLE_PROTOBUF_STUBS_STATUS_H_

#include <google/protobuf/stubs/internal/status.h>
#include <string>

#include <google/protobuf/stubs/stringpiece.h>

#include <google/protobuf/port_def.inc>

namespace google {
namespace protobuf {
namespace util {
namespace status_internal {

// These values must match error codes defined in google/rpc/code.proto.
enum class StatusCode : int {
kOk = 0,
kCancelled = 1,
kUnknown = 2,
kInvalidArgument = 3,
kDeadlineExceeded = 4,
kNotFound = 5,
kAlreadyExists = 6,
kPermissionDenied = 7,
kUnauthenticated = 16,
kResourceExhausted = 8,
kFailedPrecondition = 9,
kAborted = 10,
kOutOfRange = 11,
kUnimplemented = 12,
kInternal = 13,
kUnavailable = 14,
kDataLoss = 15,
};

class PROTOBUF_EXPORT Status {
public:
// Creates a "successful" status.
Status();

// Create a status in the canonical error space with the specified
// code, and error message. If "code == 0", error_message is
// ignored and a Status object identical to Status::kOk is
// constructed.
Status(StatusCode error_code, StringPiece error_message);
Status(const Status&);
Status& operator=(const Status& x);
~Status() {}

// Some pre-defined Status objects
static const Status OK; // Identical to 0-arg constructor
static const Status CANCELLED;
static const Status UNKNOWN;

// Accessor
bool ok() const {
return error_code_ == StatusCode::kOk;
}
StatusCode code() const {
return error_code_;
}
StringPiece message() const {
return error_message_;
}

bool operator==(const Status& x) const;
bool operator!=(const Status& x) const {
return !operator==(x);
}

// Return a combination of the error code name and message.
std::string ToString() const;

private:
StatusCode error_code_;
std::string error_message_;
};

// Prints a human-readable representation of 'x' to 'os'.
PROTOBUF_EXPORT std::ostream& operator<<(std::ostream& os, const Status& x);

} // namespace status_internal

using ::google::protobuf::util::status_internal::Status;
using ::google::protobuf::util::status_internal::StatusCode;
Expand All @@ -55,4 +129,6 @@ constexpr StatusCode INTERNAL = StatusCode::kInternal;
} // namespace protobuf
} // namespace google

#include <google/protobuf/port_undef.inc>

#endif // GOOGLE_PROTOBUF_STUBS_STATUS_H_

0 comments on commit 3000a23

Please sign in to comment.