Files
MicrOBU/obu-firmware/external/vanetza-idf/vanetza/common/confident_quantity.hpp
T
Ashin Walpola d107534eb2 Keep vanetza-idf in obu-firmware, so a plain clone builds the firmware
obu-firmware builds against the vanetza-idf C-ITS library, which until now
came from the colleague's microbu-esp32c5 tree beside the repository and was
not tracked here, so a clone of this repository could not build the firmware
it ships. The library alone is now part of obu-firmware, as
obu-firmware/external/vanetza-idf: their external/vanetza-idf at commit
cf4b99f, unchanged (9775 files; see its PROVENANCE.md). CMake takes it from
there by default; -DVANETZA_IDF_DIR still points the build elsewhere.

The rest of the colleague's tree (their own VAM firmware, PKI tooling,
station-link Python tools, the V2X2MAP bridge) stays out of this repository
and gitignored; nothing is pushed to their repository. NOTES.md, docs/06,
TODO.md and the pcap verifier's usage line point at the new location.
2026-09-24 10:56:05 +02:00

78 lines
2.1 KiB
C++

#ifndef CONFIDENT_QUANTITY_HPP_B2XVJERI
#define CONFIDENT_QUANTITY_HPP_B2XVJERI
#include <limits>
namespace vanetza
{
/**
* ConfidentQuantity combines a boost::quantity value with a confidence level.
*
* Usually, a confidence level of 95% is used in ITS specifications.
* If no confidence level is explicitly given a worst case value is used, i.e.
* the maximum value representable by the underlying type or infinity.
*/
template<typename T>
class ConfidentQuantity
{
public:
constexpr T worst_confidence() const
{
using value_type = typename T::value_type;
return T::from_value(std::numeric_limits<value_type>::has_infinity ?
std::numeric_limits<value_type>::infinity() :
std::numeric_limits<value_type>::max());
}
constexpr T default_value() const
{
using value_type = typename T::value_type;
return T::from_value(std::numeric_limits<value_type>::has_quiet_NaN ?
std::numeric_limits<value_type>::quiet_NaN() : value_type());
}
constexpr bool is_nan(const T& t) const
{
return t.value() != t.value();
}
ConfidentQuantity() :
m_value(default_value()), m_confidence(worst_confidence()) {}
ConfidentQuantity(const T& value) :
m_value(value), m_confidence(worst_confidence()) {}
ConfidentQuantity(const T& value, const T& confidence) :
m_value(value), m_confidence(!is_nan(confidence) ? confidence : worst_confidence()) {}
ConfidentQuantity(const ConfidentQuantity&) = default;
ConfidentQuantity& operator=(const ConfidentQuantity&) = default;
ConfidentQuantity(ConfidentQuantity&&) = default;
ConfidentQuantity& operator=(ConfidentQuantity&&) = default;
void assign(const T& value, const T& confidence)
{
m_value = value;
m_confidence = !is_nan(confidence) ? confidence : worst_confidence();
}
const T& value() const
{
return m_value;
}
const T& confidence() const
{
return m_confidence;
}
private:
T m_value;
T m_confidence;
};
} // namespace vanetza
#endif /* CONFIDENT_QUANTITY_HPP_B2XVJERI */