microsoft/onnxruntime-extensions

Public

mirrored fromhttps://github.com/microsoft/onnxruntime-extensionsAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
rel-0.11

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

base/status.cc

60lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4#include "status.h"
5#include "ort_c_to_cpp.h"
6
7struct OrtxStatus::Rep {
8 extError_t code{kOrtxOK};
9 std::string error_message;
10};
11
12OrtxStatus::OrtxStatus() = default;
13OrtxStatus::~OrtxStatus() = default;
14
15OrtxStatus::OrtxStatus(extError_t code, std::string_view error_message)
16 : rep_(new Rep) {
17 rep_->code = code;
18 rep_->error_message = std::string(error_message);
19}
20
21OrtxStatus::OrtxStatus(extError_t code, const std::string& error_message)
22 : rep_(new Rep) {
23 rep_->code = code;
24 rep_->error_message = std::string(error_message);
25}
26
27OrtxStatus::OrtxStatus(const OrtxStatus& s)
28 : rep_((s.rep_ == nullptr) ? nullptr : new Rep(*s.rep_)) {}
29
30OrtxStatus& OrtxStatus::operator=(const OrtxStatus& s) {
31 if (rep_ != s.rep_)
32 rep_.reset((s.rep_ == nullptr) ? nullptr : new Rep(*s.rep_));
33
34 return *this;
35}
36
37bool OrtxStatus::operator==(const OrtxStatus& s) const { return (rep_ == s.rep_); }
38
39bool OrtxStatus::operator!=(const OrtxStatus& s) const { return (rep_ != s.rep_); }
40
41const char* OrtxStatus::Message() const {
42 return IsOk() ? "" : rep_->error_message.c_str();
43}
44
45void OrtxStatus::SetErrorMessage(const char* str) {
46 if (rep_ == nullptr)
47 rep_ = std::make_unique<Rep>();
48 rep_->error_message = str;
49}
50
51extError_t OrtxStatus::Code() const { return IsOk() ? extError_t() : rep_->code; }
52
53OrtStatus* OrtxStatus::CreateOrtStatus() const {
54 if (IsOk()) {
55 return nullptr;
56 }
57
58 OrtStatus* status = OrtW::CreateStatus(Message(), OrtErrorCode::ORT_RUNTIME_EXCEPTION);
59 return status;
60}
61