ROSaic
Public Member Functions
BaseParser< T > Class Template Referenceabstract

Base class for parsing NMEA messages and SBF blocks. More...

#include <parser_base_class.hpp>

Public Member Functions

 BaseParser ()=default
 Default constructor of the class BaseParser. More...
 
virtual ~BaseParser ()=default
 Default destructor of the class BaseParser. More...
 
virtual const std::string getMessageID () const =0
 Returns the ASCII message name. More...
 
template<typename SBFStructT >
parseBinary (const SBFStructT &bin_msg) noexcept(false)
 Converts bin_msg into a ROS message pointer (e.g. nmea_msgs::GpggaPtr) and returns it. More...
 
virtual T parseASCII (const NMEASentence &sentence) noexcept(false)
 Converts an NMEA sentence - both standardized and proprietary ones - into a ROS message pointer (e.g. nmea_msgs::GpggaPtr) and returns it. More...
 

Detailed Description

template<typename T>
class BaseParser< T >

Base class for parsing NMEA messages and SBF blocks.

Subclasses that parse NMEA messages should implement ParseASCII(const NMEASentence&); subclasses that parse SBF blocks should implement ParseBinary(const SBFBlock&). The base class is implemented as a template, which is a simple and yet very powerful tool in C++. The simple idea is to pass data type as a parameter so that we don’t need to write the same code for different data types. Like function templates, class templates are useful when a class defines something that is independent of the data type, as here the notion of parsing.

Template Parameters
TThe ROS message pointer type that the parser should produce, e.g. nmea_msgs::GpggaPtr.

Definition at line 62 of file parser_base_class.hpp.

Constructor & Destructor Documentation

◆ BaseParser()

template<typename T>
BaseParser< T >::BaseParser ( )
default

Default constructor of the class BaseParser.

Adding the "default" keyword to the constructor declaration is a new feature since C++11 for creating a default constructor (a constructor which can be called with no arguments). Strictly speaking, it is not the same as when the keyword is omitted, but the differences are miniscule.

Also note that in C++, the constructor cannot be virtual, because when a constructor of a class is executed, there is no virtual table in the memory, i.e. no virtual pointer defined yet.

◆ ~BaseParser()

template<typename T>
virtual BaseParser< T >::~BaseParser ( )
virtualdefault

Default destructor of the class BaseParser.

As opposed to the constructor, a destructor can be virtual, as here.

Member Function Documentation

◆ getMessageID()

template<typename T>
virtual const std::string BaseParser< T >::getMessageID ( ) const
pure virtual

Returns the ASCII message name.

GetMessageID() is a pure virtual function, i.e. a function for which writing a function declaration suffices. It is declared by assigning the value 0 in the declaration. Since we now have at least 1 pure virtual function, our class BaseParser thus becomes an "abstract" one.

Returns
The ASCII message name.

Implemented in GpggaParser, GprmcParser, GpgsaParser, and GpgsvParser.

◆ parseASCII()

template<typename T>
virtual T BaseParser< T >::parseASCII ( const NMEASentence sentence)
inlinevirtualnoexcept

Converts an NMEA sentence - both standardized and proprietary ones - into a ROS message pointer (e.g. nmea_msgs::GpggaPtr) and returns it.

The returned value should not be NULL. ParseException will be thrown if there are any issues parsing the message.

Parameters
[in]sentenceThe standardized NMEA sentence to convert, of type NMEASentence
Returns
A valid ROS message pointer

Reimplemented in GpggaParser, GprmcParser, GpgsaParser, and GpgsvParser.

Definition at line 122 of file parser_base_class.hpp.

123  {
124  throw ParseException("ParseASCII not implemented.");
125  };
Class to declare error message format when parsing, derived from the public class "std::runtime_error...

◆ parseBinary()

template<typename T>
template<typename SBFStructT >
T BaseParser< T >::parseBinary ( const SBFStructT &  bin_msg)
inlinenoexcept

Converts bin_msg into a ROS message pointer (e.g. nmea_msgs::GpggaPtr) and returns it.

The returned value should not be NULL. ParseException will be thrown if there are any issues parsing the block.

Parameters
[in]bin_msgThe message to convert, of type const SBFStructT
Returns
A valid ROS message pointer

Definition at line 109 of file parser_base_class.hpp.

110  {
111  throw ParseException("ParseBinary not implemented.");
112  };
Class to declare error message format when parsing, derived from the public class "std::runtime_error...

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