1
0
mirror of https://github.com/open-mmlab/mmdeploy.git synced 2025-01-14 08:09:43 +08:00
mmdeploy/csrc/core/status_code.cpp
lzhangzz a494a6f6ff
[SDK] sync changes according to performance benchmarks ()
* sync SDK changes according to performance benchmarks

* fix end-of-file lint

* fix clang-format issue

* fix clang-format by adding 'clang-format off'

* remove useless casts

* remove 'data' argument of 'operator()'

* change 'Tensor2Img' to 'TensorToImg' according to spec

* correct tensor's name according spec

Co-authored-by: lvhan028 <lvhan_028@163.com>
2021-12-16 13:51:22 +08:00

43 lines
1.3 KiB
C++

// Copyright (c) OpenMMLab. All rights reserved.
#include "core/status_code.h"
#include "core/logger.h"
namespace mmdeploy {
void StatusDomain::_do_throw_exception(
const SYSTEM_ERROR2_NAMESPACE::status_code<void> &code) const {
assert(code.domain() == *this);
const auto &c = static_cast<const StatusCode &>(code); // NOLINT
throw SYSTEM_ERROR2_NAMESPACE::status_error(c);
}
using string_ref = SYSTEM_ERROR2_NAMESPACE::status_code_domain::string_ref;
using atomic_refcounted_string_ref =
SYSTEM_ERROR2_NAMESPACE::status_code_domain::atomic_refcounted_string_ref;
string_ref Status::message() const {
std::string ret;
try {
#if MMDEPLOY_STATUS_USE_SOURCE_LOCATION
ret = fmt::format("{} ({}) @ {}:{}", to_string(ec), (int32_t)ec, file, line);
#elif MMDEPLOY_STATUS_USE_STACKTRACE
ret = fmt::format("{} ({}), stacktrace:\n{}", to_string(ec), (int32_t)ec, st.to_string());
#else
ret = fmt::format("{} ({})", to_string(ec), (int32_t)ec);
#endif
} catch (...) {
return string_ref("Failed to retrieve message for status");
}
if (auto p = static_cast<char *>(malloc(ret.size() + 1))) {
memcpy(p, ret.c_str(), ret.size() + 1);
return atomic_refcounted_string_ref(p, ret.size());
} else {
return string_ref("Failed to allocate memory to store error string");
}
}
} // namespace mmdeploy