18 #ifndef SIGNAL_FILTERS__SIGNAL_FILTER_HPP_
19 #define SIGNAL_FILTERS__SIGNAL_FILTER_HPP_
28 #include <type_traits>
36 namespace signal_filters
42 static auto now() {
return std::chrono::steady_clock::now();}
43 using time_point = std::chrono::steady_clock::time_point;
51 template<
typename T,
typename ClockT = DummyClock>
54 static_assert(std::is_floating_point<T>::value,
"Filters require a floating point type");
55 constexpr
static bool8_t use_time_point_api = !std::is_same<ClockT, DummyClock>::value;
70 template<
typename DummyT = T,
typename = std::enable_if_t<use_time_po
int_api, DummyT>>
71 T filter(
T value,
typename clock_type::time_point time_stamp)
73 const auto dt = time_stamp - m_last_observation_stamp;
74 const auto ret = filter_impl_checked(value, dt);
75 m_last_observation_stamp = time_stamp;
85 template<
typename DummyT = T,
typename = std::enable_if_t<!use_time_po
int_api, DummyT>>
86 T filter(
T value, std::chrono::nanoseconds duration)
88 return filter_impl_checked(value, duration);
95 if (decltype(duration)::zero() >= duration) {
96 throw std::domain_error{
"Duration is negative"};
98 if (!std::isfinite(value)) {
99 throw std::domain_error{
"Value is not finite"};
101 return filter_impl(value, duration);
104 virtual T filter_impl(
T value, std::chrono::nanoseconds duration) = 0;
107 typename clock_type::time_point m_last_observation_stamp{};
114 #endif // SIGNAL_FILTERS__SIGNAL_FILTER_HPP_