From fa1dd5c120048808e4429eda36893ebb83518a36 Mon Sep 17 00:00:00 2001 From: FrancoisCarouge Date: Fri, 25 Oct 2024 22:09:22 -0700 Subject: [PATCH] [filter] kalman filter concept --- include/fcarouge/internal/format.hpp | 20 ++++++++------------ include/fcarouge/internal/utility.hpp | 8 ++++++++ include/fcarouge/utility.hpp | 6 ++++++ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/include/fcarouge/internal/format.hpp b/include/fcarouge/internal/format.hpp index 3789e05fd..8fd5c65e1 100644 --- a/include/fcarouge/internal/format.hpp +++ b/include/fcarouge/internal/format.hpp @@ -44,17 +44,13 @@ For more information, please refer to */ #include #include -namespace fcarouge { -template class kalman; -} // namespace fcarouge - -template +template // It is allowed to add template specializations for any standard library class // template to the namespace std only if the declaration depends on at least one // program-defined type and the specialization satisfies all requirements for // the original template, except where such specializations are prohibited. // NOLINTNEXTLINE(cert-dcl58-cpp) -struct std::formatter, Char> { +struct std::formatter { constexpr auto parse(std::basic_format_parse_context &parse_context) { return parse_context.begin(); } @@ -62,24 +58,24 @@ struct std::formatter, Char> { //! @todo P2585 may be useful in simplifying and standardizing the support. template constexpr auto - format(const fcarouge::kalman &filter, + format(const Filter &filter, std::basic_format_context &format_context) const -> OutputIterator { format_context.advance_to( std::format_to(format_context.out(), R"({{)", filter.f())); - if constexpr (fcarouge::has_state_transition) { + if constexpr (fcarouge::internal::has_state_transition_method) { format_context.advance_to( std::format_to(format_context.out(), R"("f": {}, )", filter.f())); } - if constexpr (fcarouge::has_input_control) { + if constexpr (fcarouge::internal::has_input_control_method) { format_context.advance_to( std::format_to(format_context.out(), R"("g": {}, )", filter.g())); } - if constexpr (fcarouge::has_output_model) { + if constexpr (fcarouge::internal::has_output_model_method) { format_context.advance_to( std::format_to(format_context.out(), R"("h": {}, )", filter.h())); } @@ -100,7 +96,7 @@ struct std::formatter, Char> { }); } - if constexpr (fcarouge::has_process_uncertainty) { + if constexpr (fcarouge::internal::has_process_uncertainty_method) { format_context.advance_to( std::format_to(format_context.out(), R"("q": {}, )", filter.q())); } @@ -115,7 +111,7 @@ struct std::formatter, Char> { //! @todo Generalize out internal method concept when MSVC has better //! if-constexpr-requires support. - if constexpr (fcarouge::has_input) { + if constexpr (fcarouge::internal::has_input_method) { format_context.advance_to( std::format_to(format_context.out(), R"("u": {}, )", filter.u())); } diff --git a/include/fcarouge/internal/utility.hpp b/include/fcarouge/internal/utility.hpp index 556a582b1..6e9c33ecd 100644 --- a/include/fcarouge/internal/utility.hpp +++ b/include/fcarouge/internal/utility.hpp @@ -43,6 +43,14 @@ For more information, please refer to */ #include namespace fcarouge::internal { +template +concept kalman_filter = requires(Type value) { + //! @todo What should be a better concept of the Kalman filter of this + //! library? + typename Type::state; + typename Type::output; +}; + template concept arithmetic = std::integral || std::floating_point; diff --git a/include/fcarouge/utility.hpp b/include/fcarouge/utility.hpp index 32ce5fd15..0873d4168 100644 --- a/include/fcarouge/utility.hpp +++ b/include/fcarouge/utility.hpp @@ -49,6 +49,12 @@ For more information, please refer to */ namespace fcarouge { //! @name Concepts //! @{ +//! @brief Kalman filter concept. +//! +//! @details This library's Kalman filters. +template +concept kalman_filter = internal::kalman_filter; + //! @brief Arithmetic concept. //! //! @details Any integer or floating point type.