Build: add GCC-13, Clang-14, Clang-15, Clang-16, Clang-17
[marnav.git] / src / marnav / nmea / r00.cpp
blob0a949258b3764f87e59d00f45b0b70fb26a6f90f
1 #include <marnav/nmea/r00.hpp>
2 #include <marnav/nmea/io.hpp>
3 #include <stdexcept>
5 namespace marnav::nmea
7 constexpr sentence_id r00::ID;
8 constexpr const char * r00::TAG;
9 constexpr int r00::max_waypoint_ids;
11 r00::r00()
12 : sentence(ID, TAG, talker::global_positioning_system)
16 r00::r00(talker talk, fields::const_iterator first, fields::const_iterator last)
17 : sentence(ID, TAG, talk)
19 if (std::distance(first, last) != r00::max_waypoint_ids)
20 throw std::invalid_argument{"invalid number of fields in r00"};
22 for (auto i = 0; i < max_waypoint_ids; ++i) {
23 waypoint id;
24 read(*(first + i), id);
25 set_waypoint_id(i, id);
29 void r00::append_data_to(std::string & s, const version &) const
31 for (auto i = 0; i < max_waypoint_ids; ++i) {
32 if (waypoint_id_[i]) {
33 append(s, waypoint_id_[i].value());
34 } else {
35 append(s, "");
40 void r00::check_index(int index) const
42 if ((index < 0) || (index >= max_waypoint_ids))
43 throw std::out_of_range{"waypoint ID out of range"};
46 std::optional<waypoint> r00::get_waypoint_id(int index) const
48 check_index(index);
49 return waypoint_id_[index];
52 void r00::set_waypoint_id(int index, const waypoint & id)
54 check_index(index);
55 waypoint_id_[index] = id;