include/cvw/algorithms/detail.hpp
Shared algorithm error codes and input validation helpers. More...
Namespaces
| Name |
|---|
| cvw |
| cvw::detail Internal validation helpers used by algorithm implementations. |
Detailed Description
Shared algorithm error codes and input validation helpers.
Author: Charliechen114514
Version: 1.0.0
Since: 1.0.0
Date: 2026-05-15
Defines the AlgorithmError enum used across all algorithm functions and a set of lightweight validators that return expected<void> for composable error reporting.
Source code
cpp
#pragma once
#include "../base/expected.hpp"
#include "../image.hpp"
#include "../image_view.hpp"
#include <cstdint>
namespace cvw {
enum class AlgorithmError : uint8_t {
EmptyInput,
InvalidParameter,
InternalError,
SaveFailed,
LoadFailed,
};
namespace detail {
template <is_pixel_format F> inline auto check_non_empty(const Image<F>& img)
-> expected<void, AlgorithmError> {
if (img.empty()) {
return unexpected(AlgorithmError::EmptyInput);
}
return {};
}
template <is_pixel_format F>
inline auto check_non_empty(const ImageView<F>& view)
-> expected<void, AlgorithmError> {
if (view.empty()) {
return unexpected(AlgorithmError::EmptyInput);
}
return {};
}
inline auto require_odd(int k) -> expected<void, AlgorithmError> {
if (k <= 0 || k % 2 == 0) {
return unexpected(AlgorithmError::InvalidParameter);
}
return {};
}
inline auto require_positive_dim(int w, int h)
-> expected<void, AlgorithmError> {
if (w <= 0 || h <= 0) {
return unexpected(AlgorithmError::InvalidParameter);
}
return {};
}
} // namespace detail
} // namespace cvwUpdated on 2026-05-17 at 13:22:38 +0000