diff --git a/mmros/include/mmros/archetype/exception.hpp b/mmros/include/mmros/archetype/exception.hpp index b53aec7..8f964ec 100644 --- a/mmros/include/mmros/archetype/exception.hpp +++ b/mmros/include/mmros/archetype/exception.hpp @@ -65,7 +65,7 @@ class MmRosException : public std::exception * * @param error `MmRosError` object. */ - explicit MmRosException(const MmRosError & error) : error_(error) { appendMessagePrefix(); } + explicit MmRosException(const MmRosError & error) : error_(error) { append_message_prefix(); } /** * @brief Construct a new MmRosException object with error kind and message. @@ -75,7 +75,7 @@ class MmRosException : public std::exception */ MmRosException(const MmRosError_t & kind, const std::string & msg) : error_(kind, msg) { - appendMessagePrefix(); + append_message_prefix(); } /** @@ -87,7 +87,7 @@ class MmRosException : public std::exception /** * @brief Append prefix to the error message depending on its kind. */ - void appendMessagePrefix() noexcept + void append_message_prefix() noexcept { switch (error_.kind) { case MmRosError_t::TENSORRT: diff --git a/mmros/include/mmros/archetype/result.hpp b/mmros/include/mmros/archetype/result.hpp index 245d5dd..9f41a35 100644 --- a/mmros/include/mmros/archetype/result.hpp +++ b/mmros/include/mmros/archetype/result.hpp @@ -48,14 +48,14 @@ class Result /** * @brief Check whether holding value is expected type. */ - bool isOk() const noexcept { return std::holds_alternative(value_); } + bool is_ok() const noexcept { return std::holds_alternative(value_); } /** * @brief Return the expected value if it holds, otherwise throw `MmRosException`. */ T unwrap() const { - if (isOk()) { + if (is_ok()) { return std::get(value_); } else { throw MmRosException(std::get(value_)); @@ -74,7 +74,7 @@ class Result */ template -Result Ok(const T & value) noexcept +Result make_ok(const T & value) noexcept { return Result(value); } @@ -86,7 +86,7 @@ Result Ok(const T & value) noexcept * @param error `MmRosError` object. */ template -Result Err(const MmRosError & error) noexcept +Result make_err(const MmRosError & error) noexcept { return Result(error); } @@ -98,7 +98,7 @@ Result Err(const MmRosError & error) noexcept * @param kind Error kind. */ template -Result Err(const MmRosError_t & kind) noexcept +Result make_err(const MmRosError_t & kind) noexcept { MmRosError error(kind); return Result(error); @@ -112,7 +112,7 @@ Result Err(const MmRosError_t & kind) noexcept * @param msg Error message. */ template -Result Err(const MmRosError_t & kind, const std::string & msg) noexcept +Result make_err(const MmRosError_t & kind, const std::string & msg) noexcept { MmRosError error(kind, msg); return Result(error); diff --git a/mmros/src/detector/detector2d.cpp b/mmros/src/detector/detector2d.cpp index f330070..d6dc69e 100644 --- a/mmros/src/detector/detector2d.cpp +++ b/mmros/src/detector/detector2d.cpp @@ -77,21 +77,21 @@ archetype::Result Detector2D::doInference( const std::vector & images) noexcept { if (images.empty()) { - return archetype::Err(archetype::MmRosError_t::UNKNOWN, "No image."); + return archetype::make_err(archetype::MmRosError_t::UNKNOWN, "No image."); } // 1. Init CUDA pointers try { initCudaPtr(images.size()); } catch (const archetype::MmRosException & e) { - return archetype::Err(archetype::MmRosError_t::CUDA, e.what()); + return archetype::make_err(archetype::MmRosError_t::CUDA, e.what()); } // 2. Execute preprocess try { preprocess(images); } catch (const archetype::MmRosException & e) { - return archetype::Err(archetype::MmRosError_t::CUDA, e.what()); + return archetype::make_err(archetype::MmRosError_t::CUDA, e.what()); } // 3. Set tensors @@ -99,14 +99,14 @@ archetype::Result Detector2D::doInference( if (!trt_common_->setTensorsAddresses(buffers)) { std::ostringstream os; os << "@" << __FILE__ << ", #F:" << __FUNCTION__ << ", #L:" << __LINE__; - return archetype::Err(archetype::MmRosError_t::TENSORRT, os.str()); + return archetype::make_err(archetype::MmRosError_t::TENSORRT, os.str()); } // 4. Execute inference if (!trt_common_->enqueueV3(stream_)) { std::ostringstream os; os << "@" << __FILE__ << ", #F:" << __FUNCTION__ << ", #L:" << __LINE__; - return archetype::Err(archetype::MmRosError_t::TENSORRT, os.str()); + return archetype::make_err(archetype::MmRosError_t::TENSORRT, os.str()); } // 5. Execute postprocess @@ -184,7 +184,7 @@ archetype::Result Detector2D::postprocess( sizeof(int) * batch_size * num_detection * class_dim, ::cudaMemcpyDeviceToHost, stream_)); CHECK_CUDA_ERROR(cudaStreamSynchronize(stream_)); } catch (const archetype::MmRosException & e) { - return archetype::Err(archetype::MmRosError_t::CUDA, e.what()); + return archetype::make_err(archetype::MmRosError_t::CUDA, e.what()); } outputs_type output; @@ -210,6 +210,6 @@ archetype::Result Detector2D::postprocess( output.push_back(std::move(boxes)); } - return archetype::Ok(output); + return archetype::make_ok(output); } } // namespace mmros::detector diff --git a/mmros/src/detector/instance_segmeter2d.cpp b/mmros/src/detector/instance_segmeter2d.cpp index 6c66833..ae9cb46 100644 --- a/mmros/src/detector/instance_segmeter2d.cpp +++ b/mmros/src/detector/instance_segmeter2d.cpp @@ -79,33 +79,33 @@ archetype::Result InstanceSegmenter2D::doInference( const std::vector & images) noexcept { if (images.empty()) { - return archetype::Err(archetype::MmRosError_t::UNKNOWN, "No image."); + return archetype::make_err(archetype::MmRosError_t::UNKNOWN, "No image."); } // 1. Init CUDA pointers try { initCudaPtr(images.size()); } catch (const archetype::MmRosException & e) { - return archetype::Err(archetype::MmRosError_t::CUDA, e.what()); + return archetype::make_err(archetype::MmRosError_t::CUDA, e.what()); } // 2. Execute preprocess try { preprocess(images); } catch (const archetype::MmRosException & e) { - return archetype::Err(archetype::MmRosError_t::CUDA, e.what()); + return archetype::make_err(archetype::MmRosError_t::CUDA, e.what()); } // 3. Set tensors std::vector buffers{ input_d_.get(), out_boxes_d_.get(), out_labels_d_.get(), out_segments_d_.get()}; if (!trt_common_->setTensorsAddresses(buffers)) { - return archetype::Err(archetype::MmRosError_t::TENSORRT); + return archetype::make_err(archetype::MmRosError_t::TENSORRT); } // 4. Execute inference if (!trt_common_->enqueueV3(stream_)) { - return archetype::Err(archetype::MmRosError_t::TENSORRT); + return archetype::make_err(archetype::MmRosError_t::TENSORRT); } // 5. Execute postprocess @@ -196,7 +196,7 @@ archetype::Result InstanceSegmenter2D::postprocess( ::cudaMemcpyDeviceToHost, stream_)); CHECK_CUDA_ERROR(::cudaStreamSynchronize(stream_)); } catch (const archetype::MmRosException & e) { - return archetype::Err(archetype::MmRosError_t::CUDA, e.what()); + return archetype::make_err(archetype::MmRosError_t::CUDA, e.what()); } outputs_type outputs; @@ -234,6 +234,6 @@ archetype::Result InstanceSegmenter2D::postprocess( outputs.emplace_back(std::move(boxes), std::move(masks)); } - return archetype::Ok(outputs); + return archetype::make_ok(outputs); } } // namespace mmros::detector diff --git a/mmros/src/detector/panoptic_segmenter2d.cpp b/mmros/src/detector/panoptic_segmenter2d.cpp index 2f8a3c6..bb1cd2d 100644 --- a/mmros/src/detector/panoptic_segmenter2d.cpp +++ b/mmros/src/detector/panoptic_segmenter2d.cpp @@ -76,21 +76,21 @@ archetype::Result PanopticSegmenter2D::doInference( const std::vector & images) noexcept { if (images.empty()) { - return archetype::Err(archetype::MmRosError_t::UNKNOWN, "No image."); + return archetype::make_err(archetype::MmRosError_t::UNKNOWN, "No image."); } // 1. Init CUDA pointers try { initCudaPtr(images.size()); } catch (const archetype::MmRosException & e) { - return archetype::Err(archetype::MmRosError_t::CUDA, e.what()); + return archetype::make_err(archetype::MmRosError_t::CUDA, e.what()); } // 2. Execute preprocess try { preprocess(images); } catch (const archetype::MmRosException & e) { - return archetype::Err(archetype::MmRosError_t::CUDA, e.what()); + return archetype::make_err(archetype::MmRosError_t::CUDA, e.what()); } // 3. Set tensors @@ -100,14 +100,14 @@ archetype::Result PanopticSegmenter2D::doInference( if (!trt_common_->setTensorsAddresses(buffers)) { std::ostringstream os; os << "@" << __FILE__ << ", #F:" << __FUNCTION__ << ", #L:" << __LINE__; - return archetype::Err(archetype::MmRosError_t::TENSORRT, os.str()); + return archetype::make_err(archetype::MmRosError_t::TENSORRT, os.str()); } // 4. Execute inference if (!trt_common_->enqueueV3(stream_)) { std::ostringstream os; os << "@" << __FILE__ << ", #F:" << __FUNCTION__ << ", #L:" << __LINE__; - return archetype::Err(archetype::MmRosError_t::TENSORRT, os.str()); + return archetype::make_err(archetype::MmRosError_t::TENSORRT, os.str()); } // 5. Execute postprocess @@ -216,7 +216,7 @@ archetype::Result PanopticSegmenter2D::postprocess( ::cudaMemcpyDeviceToHost, stream_)); CHECK_CUDA_ERROR(cudaStreamSynchronize(stream_)); } catch (const archetype::MmRosException & e) { - return archetype::Err(archetype::MmRosError_t::CUDA, e.what()); + return archetype::make_err(archetype::MmRosError_t::CUDA, e.what()); } outputs_type output; @@ -248,6 +248,6 @@ archetype::Result PanopticSegmenter2D::postprocess( output.emplace_back(std::move(boxes), std::move(mask)); } - return archetype::Ok(output); + return archetype::make_ok(output); } } // namespace mmros::detector diff --git a/mmros/src/detector/semantic_segmenter2d.cpp b/mmros/src/detector/semantic_segmenter2d.cpp index bf184f9..cba227d 100644 --- a/mmros/src/detector/semantic_segmenter2d.cpp +++ b/mmros/src/detector/semantic_segmenter2d.cpp @@ -78,21 +78,21 @@ archetype::Result SemanticSegmenter2D::doInference( const std::vector & images) noexcept { if (images.empty()) { - return archetype::Err(archetype::MmRosError_t::UNKNOWN, "No image."); + return archetype::make_err(archetype::MmRosError_t::UNKNOWN, "No image."); } // 1. Init CUDA pointers try { initCudaPtr(images.size()); } catch (const archetype::MmRosException & e) { - return archetype::Err(archetype::MmRosError_t::CUDA, e.what()); + return archetype::make_err(archetype::MmRosError_t::CUDA, e.what()); } // 2. Execute preprocess try { preprocess(images); } catch (const archetype::MmRosException & e) { - return archetype::Err(archetype::MmRosError_t::CUDA, e.what()); + return archetype::make_err(archetype::MmRosError_t::CUDA, e.what()); } // 3. Set tensors @@ -100,14 +100,14 @@ archetype::Result SemanticSegmenter2D::doInference( if (!trt_common_->setTensorsAddresses(buffers)) { std::ostringstream os; os << "@" << __FILE__ << ", #F:" << __FUNCTION__ << ", #L:" << __LINE__; - return archetype::Err(archetype::MmRosError_t::TENSORRT, os.str()); + return archetype::make_err(archetype::MmRosError_t::TENSORRT, os.str()); } // 4. Execute inference if (!trt_common_->enqueueV3(stream_)) { std::ostringstream os; os << "@" << __FILE__ << ", #F:" << __FUNCTION__ << ", #L:" << __LINE__; - return archetype::Err(archetype::MmRosError_t::TENSORRT, os.str()); + return archetype::make_err(archetype::MmRosError_t::TENSORRT, os.str()); } // 5. Execute postprocess @@ -160,7 +160,7 @@ archetype::Result SemanticSegmenter2D::postprocess( output_h.data(), output_d_.get(), sizeof(int64_t) * batch_size * 1 * output_width * output_height, ::cudaMemcpyDeviceToHost)); } catch (const archetype::MmRosException & e) { - return archetype::Err(archetype::MmRosError_t::CUDA, e.what()); + return archetype::make_err(archetype::MmRosError_t::CUDA, e.what()); } outputs_type output; @@ -197,6 +197,6 @@ archetype::Result SemanticSegmenter2D::postprocess( output.push_back(std::move(final_mask)); } - return archetype::Ok(output); + return archetype::make_ok(output); } } // namespace mmros::detector