nmealib 0.0.4
NMEA 0183/NMEA 2000 parsing library
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
nmealib::Message Class Referenceabstract

Defines a base class for NMEA messages, encapsulating common properties and behaviors. More...

#include <message.h>

Inheritance diagram for nmealib::Message:
Inheritance graph
[legend]

Public Types

enum class  Type { Unknown , NMEA0183 , NMEA2000 }
 Defines the type of NMEA message, allowing for differentiation between various standards. More...
 
using TimePoint = std::chrono::system_clock::time_point
 

Public Member Functions

 Message ()
 
 Message (std::string raw, Type type=Type::Unknown, TimePoint ts=std::chrono::system_clock::now()) noexcept
 
virtual ~Message ()
 
 Message (const Message &)=default
 
Messageoperator= (const Message &)=default
 
 Message (Message &&) noexcept=default
 
Messageoperator= (Message &&) noexcept=default
 
Type getType () const noexcept
 Returns the message type.
 
const std::string & getRawData () const noexcept
 Returns the raw, unmodified data string as received.
 
TimePoint getTimestamp () const noexcept
 Returns the timestamp associated with this message.
 
virtual std::unique_ptr< Messageclone () const =0
 Creates a polymorphic deep copy of this message.
 
virtual std::string serialize () const =0
 Produces the wire-format representation of this message.
 
virtual bool validate () const =0
 Validates the message contents (e.g., checksum, length).
 
bool operator== (const Message &other) const noexcept
 Compares two Message objects for equality based on their content.
 

Static Public Member Functions

static std::string typeToString (Type t)
 Converts a Message::Type enum value to its string representation.
 

Protected Member Functions

void setType (Type t) noexcept
 Sets the message type.
 
void setRaw (std::string r) noexcept
 Sets the raw data string.
 
void setTimestamp (TimePoint ts) noexcept
 Sets the message timestamp.
 

Protected Attributes

std::string rawData_
 
Type type_ {Type::Unknown}
 
TimePoint timestamp_ {}
 

Detailed Description

Defines a base class for NMEA messages, encapsulating common properties and behaviors.

This class serves as an abstract interface for specific NMEA message types (e.g., NMEA0183, NMEA2000),

Definition at line 14 of file message.h.

Member Typedef Documentation

◆ TimePoint

using nmealib::Message::TimePoint = std::chrono::system_clock::time_point

Definition at line 30 of file message.h.

Member Enumeration Documentation

◆ Type

enum class nmealib::Message::Type
strong

Defines the type of NMEA message, allowing for differentiation between various standards.

Enumerator
Unknown 
NMEA0183 
NMEA2000 

Definition at line 20 of file message.h.

Constructor & Destructor Documentation

◆ Message() [1/4]

nmealib::Message::Message ( )
default

◆ Message() [2/4]

nmealib::Message::Message ( std::string  raw,
Type  type = Type::Unknown,
TimePoint  ts = std::chrono::system_clock::now() 
)
explicitnoexcept

Definition at line 16 of file message.cpp.

◆ ~Message()

nmealib::Message::~Message ( )
virtualdefault

◆ Message() [3/4]

nmealib::Message::Message ( const Message )
default

◆ Message() [4/4]

nmealib::Message::Message ( Message &&  )
defaultnoexcept

Member Function Documentation

◆ clone()

virtual std::unique_ptr< Message > nmealib::Message::clone ( ) const
pure virtual

◆ getRawData()

const std::string & nmealib::Message::getRawData ( ) const
noexcept

Returns the raw, unmodified data string as received.

Returns
const std::string& A const reference to the raw data string.

Definition at line 25 of file message.cpp.

◆ getTimestamp()

Message::TimePoint nmealib::Message::getTimestamp ( ) const
noexcept

Returns the timestamp associated with this message.

Returns
TimePoint The time point at which this message was created or received.

Definition at line 29 of file message.cpp.

◆ getType()

Message::Type nmealib::Message::getType ( ) const
noexcept

Returns the message type.

Returns
Type The type of this NMEA message.

Definition at line 21 of file message.cpp.

◆ operator=() [1/2]

Message & nmealib::Message::operator= ( const Message )
default

◆ operator=() [2/2]

Message & nmealib::Message::operator= ( Message &&  )
defaultnoexcept

◆ operator==()

bool nmealib::Message::operator== ( const Message other) const
noexcept

Compares two Message objects for equality based on their content.

Parameters
otherThe other Message to compare against.
Returns
true If type, raw data, and timestamp are all equal.
false Otherwise.

Definition at line 33 of file message.cpp.

◆ serialize()

virtual std::string nmealib::Message::serialize ( ) const
pure virtual

Produces the wire-format representation of this message.

Returns
std::string The serialized string suitable for transmission.

Implemented in nmealib::nmea0183::Message0183, and nmealib::nmea2000::Message2000.

◆ setRaw()

void nmealib::Message::setRaw ( std::string  r)
protectednoexcept

Sets the raw data string.

Parameters
rThe new raw data string.

Definition at line 42 of file message.cpp.

◆ setTimestamp()

void nmealib::Message::setTimestamp ( TimePoint  ts)
protectednoexcept

Sets the message timestamp.

Parameters
tsThe new timestamp.

Definition at line 46 of file message.cpp.

◆ setType()

void nmealib::Message::setType ( Type  t)
protectednoexcept

Sets the message type.

Parameters
tThe new message type.

Definition at line 38 of file message.cpp.

◆ typeToString()

std::string nmealib::Message::typeToString ( Type  t)
static

Converts a Message::Type enum value to its string representation.

Parameters
tThe message type to convert.
Returns
std::string A human-readable string for the given type (e.g., "NMEA0183", "Unknown").

Definition at line 5 of file message.cpp.

◆ validate()

virtual bool nmealib::Message::validate ( ) const
pure virtual

Validates the message contents (e.g., checksum, length).

Returns
true If the message is valid.
false If the message fails validation.

Implemented in nmealib::nmea0183::Message0183, and nmealib::nmea2000::Message2000.

Member Data Documentation

◆ rawData_

std::string nmealib::Message::rawData_
protected

Definition at line 97 of file message.h.

◆ timestamp_

TimePoint nmealib::Message::timestamp_ {}
protected

Definition at line 99 of file message.h.

◆ type_

Type nmealib::Message::type_ {Type::Unknown}
protected

Definition at line 98 of file message.h.


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