Spaces:
Sleeping
Sleeping
File size: 1,981 Bytes
dc2106c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
// Copyright (c) ONNX Project Contributors
/*
* SPDX-License-Identifier: Apache-2.0
*/
#include "status.h"
#include <assert.h>
#include "onnx/string_utils.h"
namespace ONNX_NAMESPACE {
namespace Common {
Status::Status(StatusCategory category, int code, const std::string& msg) {
assert(static_cast<int>(StatusCode::OK) != code);
state_.reset(new State(category, code, msg));
}
Status::Status(StatusCategory category, int code) : Status(category, code, EmptyString()) {}
bool Status::IsOK() const noexcept {
return (state_ == NULL);
}
StatusCategory Status::Category() const noexcept {
return IsOK() ? StatusCategory::NONE : state_->category;
}
int Status::Code() const noexcept {
return IsOK() ? static_cast<int>(StatusCode::OK) : state_->code;
}
const std::string& Status::ErrorMessage() const {
return IsOK() ? EmptyString() : state_->msg;
}
std::string Status::ToString() const {
if (state_ == nullptr) {
return std::string("OK");
}
std::string result;
if (StatusCategory::CHECKER == state_->category) {
result += "[CheckerError]";
} else if (StatusCategory::OPTIMIZER == state_->category) {
result += "[OptimizerError]";
}
result += " : ";
result += ONNX_NAMESPACE::to_string(Code());
std::string msg;
switch (static_cast<StatusCode>(Code())) {
case INVALID_ARGUMENT:
msg = "INVALID_ARGUMENT";
break;
case INVALID_PROTOBUF:
msg = "INVALID_PROTOBUF";
break;
case FAIL:
msg = "FAIL";
break;
default:
msg = "GENERAL ERROR";
break;
}
result += " : ";
result += msg;
result += " : ";
result += state_->msg;
return result;
}
const Status& Status::OK() noexcept {
static Status s_ok;
return s_ok;
}
const std::string& Status::EmptyString() {
static std::string empty_str;
return empty_str;
}
} // namespace Common
} // namespace ONNX_NAMESPACE
|