Skip to content

SentenceBuilder

class nmeasim::core::nmea0183::SentenceBuilder · Library API

Builder for one sentence: the address, then fields appended in order and separated by commas.

#include <nmeasim/core/nmea0183/sentence_builder.hpp>

Declared in src/core/include/nmeasim/core/nmea0183/sentence_builder.hpp (line 52)

Every field and empty overload returns the builder, so calls can be chained. Text fields are cleaned of the characters is_text_field_character() rejects, so a field value can never add a field or end the sentence; the address is not validated. The builder does not stop at the length limit; fits_limit tells whether the framed sentence will fit.

See also

  • NMEA 0183, sentence structure.

Summary

Public member functions

Name Description
SentenceBuilder() Starts a sentence with its start delimiter and address, such as $GPRMC.
field() Appends a text field without the characters NMEA 0183 does not allow in it.
field() Appends a single-character field, such as a status or hemisphere letter.
field() Appends a number with a fixed number of decimals, formatted by format_fixed.
field() Appends an integer, formatted by format_padded.
empty() Appends an empty field, which means "no data" in NMEA 0183.
empty() Appends several empty fields.
build() Returns the framed sentence with its checksum.
fits_limit() Tells whether the framed sentence fits the NMEA 0183 length limit.

Private data members

Name Description
body_ The sentence so far: the start delimiter, the address and every appended field with its leading comma, without the *hh checksum.

Public member functions

SentenceBuilder()

SentenceBuilder(std::string_view talker, std::string_view formatter, char delimiter = '$')

Starts a sentence with its start delimiter and address, such as $GPRMC.

Parameters

Name Type Description
talker std::string_view Talker identifier, two characters by convention, such as GP; not checked.
formatter std::string_view Sentence formatter, three characters by convention, such as RMC; not checked.
delimiter char Start delimiter: $ (kStartDelimiter) for a parametric sentence, ! (kEncapsulationDelimiter) for an encapsulated one such as AIS VDM and VDO.

Declared in src/core/include/nmeasim/core/nmea0183/sentence_builder.hpp:63 · defined in src/core/src/nmea0183/sentence_builder.cpp:20

field()

SentenceBuilder& field(std::string_view value)

Appends a text field without the characters NMEA 0183 does not allow in it.

Every character for which is_text_field_character() is false, such as ,, *, CR or LF, is removed; the others are sent unchanged.

Parameters

Name Type Description
value std::string_view The field text; empty, or with no allowed character, appends an empty field.

Returns SentenceBuilder&: This builder.

Declared in src/core/include/nmeasim/core/nmea0183/sentence_builder.hpp:73 · defined in src/core/src/nmea0183/sentence_builder.cpp:28

field()

SentenceBuilder& field(char value)

Appends a single-character field, such as a status or hemisphere letter.

Parameters

Name Type Description
value char The character to send; a character is_text_field_character() rejects appends an empty field instead.

Returns SentenceBuilder&: This builder.

Declared in src/core/include/nmeasim/core/nmea0183/sentence_builder.hpp:79 · defined in src/core/src/nmea0183/sentence_builder.cpp:38

field()

SentenceBuilder& field(double value, int decimals)

Appends a number with a fixed number of decimals, formatted by format_fixed.

Parameters

Name Type Description
value double The number to send.
decimals int Digits after the decimal point, 0 or more.

Returns SentenceBuilder&: This builder.

Throws

Exception Condition
std::format_error if decimals is negative.

Declared in src/core/include/nmeasim/core/nmea0183/sentence_builder.hpp:86 · defined in src/core/src/nmea0183/sentence_builder.cpp:46

field()

SentenceBuilder& field(int value, int width = 0)

Appends an integer, formatted by format_padded.

Parameters

Name Type Description
value int The integer to send.
width int Minimum number of characters, reached by adding leading zeros; 0 or a negative value means no padding.

Returns SentenceBuilder&: This builder.

Declared in src/core/include/nmeasim/core/nmea0183/sentence_builder.hpp:93 · defined in src/core/src/nmea0183/sentence_builder.cpp:50

empty()

SentenceBuilder& empty()

Appends an empty field, which means "no data" in NMEA 0183.

Returns SentenceBuilder&: This builder.

Declared in src/core/include/nmeasim/core/nmea0183/sentence_builder.hpp:97 · defined in src/core/src/nmea0183/sentence_builder.cpp:54

empty()

SentenceBuilder& empty(std::size_t count)

Appends several empty fields.

Parameters

Name Type Description
count std::size_t Number of empty fields to append; 0 appends nothing.

Returns SentenceBuilder&: This builder.

Declared in src/core/include/nmeasim/core/nmea0183/sentence_builder.hpp:102 · defined in src/core/src/nmea0183/sentence_builder.cpp:59

build()

std::string build() const

Returns the framed sentence with its checksum.

The builder is left unchanged, so further fields can still be appended.

Returns std::string: The address and fields followed by *hh, without line terminator; it may exceed the length limit.

Declared in src/core/include/nmeasim/core/nmea0183/sentence_builder.hpp:110 · defined in src/core/src/nmea0183/sentence_builder.cpp:66

fits_limit()

bool fits_limit() const

Tells whether the framed sentence fits the NMEA 0183 length limit.

Returns bool: true when the sentence from build has at most kMaxSentenceLengthWithoutTerminator characters.

Declared in src/core/include/nmeasim/core/nmea0183/sentence_builder.hpp:116 · defined in src/core/src/nmea0183/sentence_builder.cpp:70

Private data members

body_

std::string body_

The sentence so far: the start delimiter, the address and every appended field with its leading comma, without the *hh checksum.

Declared in src/core/include/nmeasim/core/nmea0183/sentence_builder.hpp:121