NMEA: detectio of the optional tag block in front of a sentence, ignoring it for...
[marnav.git] / src / marnav / nmea / r00.cpp
blobe230e5102d054117b3c12a581c7116916d3af190
1 #include "r00.hpp"
2 #include <marnav/nmea/io.hpp>
4 namespace marnav
6 namespace nmea
8 MARNAV_NMEA_DEFINE_SENTENCE_PARSE_FUNC(r00)
10 constexpr const char * r00::TAG;
12 r00::r00()
13 : sentence(ID, TAG, talker_id::global_positioning_system)
17 r00::r00(talker talk, fields::const_iterator first, fields::const_iterator last)
18 : sentence(ID, TAG, talk)
20 if (std::distance(first, last) != r00::max_waypoint_ids)
21 throw std::invalid_argument{"invalid number of fields in r00"};
23 for (auto i = 0; i < max_waypoint_ids; ++i) {
24 waypoint id;
25 read(*(first + i), id);
26 set_waypoint_id(i, id);
30 std::vector<std::string> r00::get_data() const
32 std::vector<std::string> result;
33 result.reserve(max_waypoint_ids);
35 for (auto i = 0; i < max_waypoint_ids; ++i) {
36 if (waypoint_id[i]) {
37 result.push_back(waypoint_id[i].value());
38 } else {
39 result.push_back("");
43 return result;
46 void r00::check_index(int index) const
48 if ((index < 0) || (index >= max_waypoint_ids))
49 throw std::out_of_range{"waypoint ID out of range"};
52 utils::optional<waypoint> r00::get_waypoint_id(int index) const
54 check_index(index);
55 return waypoint_id[index];
58 void r00::set_waypoint_id(int index, const waypoint & id)
60 check_index(index);
61 waypoint_id[index] = id;