nmealib 0.0.4
NMEA 0183/NMEA 2000 parsing library
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
nmealib::nmea2000::DataType< Traits > Class Template Reference

Strongly typed numeric wrapper for NMEA 2000 custom data types. More...

#include <dataTypes.h>

Public Types

using RawType = typename Traits::RawType
 Raw external type.
 
using TargetType = typename Traits::TargetType
 Target type for higher-level fields that expect a specific physical type.
 

Public Member Functions

constexpr bool isValid () const noexcept
 Checks whether the stored value is within configured bounds.
 
constexpr TargetType getValue () const noexcept
 Returns the normalized physical value.
 
RawType getRaw () const noexcept
 Converts physical value to raw integer representation.
 
std::string toString () const
 Converts the value to a fixed-point string.
 
constexpr bool operator== (const DataType &other) const noexcept
 
constexpr bool operator!= (const DataType &other) const noexcept
 
constexpr bool operator< (const DataType &other) const noexcept
 
constexpr bool operator<= (const DataType &other) const noexcept
 
constexpr bool operator> (const DataType &other) const noexcept
 
constexpr bool operator>= (const DataType &other) const noexcept
 

Static Public Member Functions

static DataType fromValue (TargetType value)
 Constructs from a physical value.
 
static constexpr DataType fromRaw (RawType raw) noexcept
 Constructs from a raw value.
 

Static Public Attributes

static constexpr double MIN = Traits::MIN
 Minimum representable value for this type.
 
static constexpr double MAX = Traits::MAX
 Maximum representable value for this type.
 
static constexpr double RESOLUTION = Traits::RESOLUTION
 Resolution (least significant physical unit step).
 

Detailed Description

template<typename Traits>
class nmealib::nmea2000::DataType< Traits >

Strongly typed numeric wrapper for NMEA 2000 custom data types.

This template models NMEA 2000 custom numeric types where a physical value is represented with:

Internally, values are stored as double and normalized to the configured resolution in the constructor.

Template Parameters
TraitsTraits type defining bounds and resolution.

Traits must define:

static constexpr double MIN = 0.0;
static constexpr double MAX = 4.295e7;
static constexpr double RESOLUTION = 1e-2;
};
// Construct from physical value (meters), auto-rounded to 0.01
Distance d(1234.5678);
// Convert to raw integer for wire format (123456)
std::int64_t raw = d.toRawValue();
// Reconstruct from raw integer
Distance parsed = Distance::fromRawValue(raw);
// Readable formatted value and comparisons
std::string text = parsed.toString(); // "1234.57"
bool farther = parsed > Distance(1000.0);
Strongly typed numeric wrapper for NMEA 2000 custom data types.
Definition dataTypes.h:56
std::string toString() const
Converts the value to a fixed-point string.
Definition dataTypes.h:139
DataType< DistanceTraits > Distance
Custom type representing distances in meters.
Definition dataTypes.h:291

Definition at line 56 of file dataTypes.h.

Member Typedef Documentation

◆ RawType

template<typename Traits >
using nmealib::nmea2000::DataType< Traits >::RawType = typename Traits::RawType

Raw external type.

Definition at line 65 of file dataTypes.h.

◆ TargetType

template<typename Traits >
using nmealib::nmea2000::DataType< Traits >::TargetType = typename Traits::TargetType

Target type for higher-level fields that expect a specific physical type.

Definition at line 67 of file dataTypes.h.

Member Function Documentation

◆ fromRaw()

template<typename Traits >
static constexpr DataType nmealib::nmea2000::DataType< Traits >::fromRaw ( RawType  raw)
inlinestaticconstexprnoexcept

Constructs from a raw value.

The raw value is converted to physical units by multiplying with RESOLUTION.

Parameters
rawRaw integer value representing the physical quantity.

Definition at line 97 of file dataTypes.h.

◆ fromValue()

template<typename Traits >
static DataType nmealib::nmea2000::DataType< Traits >::fromValue ( TargetType  value)
inlinestatic

Constructs from a physical value.

The input is clamped to [MIN, MAX] and rounded to the nearest multiple of RESOLUTION.

Parameters
valuePhysical value.

Definition at line 77 of file dataTypes.h.

◆ getRaw()

template<typename Traits >
RawType nmealib::nmea2000::DataType< Traits >::getRaw ( ) const
inlinenoexcept

Converts physical value to raw integer representation.

The conversion follows: raw = round(value / RESOLUTION).

Returns
Raw integer value suitable for payload encoding.

Definition at line 128 of file dataTypes.h.

◆ getValue()

template<typename Traits >
constexpr TargetType nmealib::nmea2000::DataType< Traits >::getValue ( ) const
inlineconstexprnoexcept

Returns the normalized physical value.

Returns
Value in physical units.

Definition at line 113 of file dataTypes.h.

◆ isValid()

template<typename Traits >
constexpr bool nmealib::nmea2000::DataType< Traits >::isValid ( ) const
inlineconstexprnoexcept

Checks whether the stored value is within configured bounds.

Returns
true if MIN <= value <= MAX, otherwise false.

Definition at line 105 of file dataTypes.h.

◆ operator!=()

template<typename Traits >
constexpr bool nmealib::nmea2000::DataType< Traits >::operator!= ( const DataType< Traits > &  other) const
inlineconstexprnoexcept

Definition at line 153 of file dataTypes.h.

◆ operator<()

template<typename Traits >
constexpr bool nmealib::nmea2000::DataType< Traits >::operator< ( const DataType< Traits > &  other) const
inlineconstexprnoexcept

Definition at line 156 of file dataTypes.h.

◆ operator<=()

template<typename Traits >
constexpr bool nmealib::nmea2000::DataType< Traits >::operator<= ( const DataType< Traits > &  other) const
inlineconstexprnoexcept

Definition at line 159 of file dataTypes.h.

◆ operator==()

template<typename Traits >
constexpr bool nmealib::nmea2000::DataType< Traits >::operator== ( const DataType< Traits > &  other) const
inlineconstexprnoexcept

Definition at line 150 of file dataTypes.h.

◆ operator>()

template<typename Traits >
constexpr bool nmealib::nmea2000::DataType< Traits >::operator> ( const DataType< Traits > &  other) const
inlineconstexprnoexcept

Definition at line 162 of file dataTypes.h.

◆ operator>=()

template<typename Traits >
constexpr bool nmealib::nmea2000::DataType< Traits >::operator>= ( const DataType< Traits > &  other) const
inlineconstexprnoexcept

Definition at line 165 of file dataTypes.h.

◆ toString()

template<typename Traits >
std::string nmealib::nmea2000::DataType< Traits >::toString ( ) const
inline

Converts the value to a fixed-point string.

The number of decimal digits is derived from RESOLUTION.

Returns
String representation of the physical value.

Definition at line 139 of file dataTypes.h.

Member Data Documentation

◆ MAX

template<typename Traits >
constexpr double nmealib::nmea2000::DataType< Traits >::MAX = Traits::MAX
staticconstexpr

Maximum representable value for this type.

Definition at line 61 of file dataTypes.h.

◆ MIN

template<typename Traits >
constexpr double nmealib::nmea2000::DataType< Traits >::MIN = Traits::MIN
staticconstexpr

Minimum representable value for this type.

Definition at line 59 of file dataTypes.h.

◆ RESOLUTION

template<typename Traits >
constexpr double nmealib::nmea2000::DataType< Traits >::RESOLUTION = Traits::RESOLUTION
staticconstexpr

Resolution (least significant physical unit step).

Definition at line 63 of file dataTypes.h.


The documentation for this class was generated from the following file: