1 #ifndef MARNAV__NMEA__CHECKS__HPP
2 #define MARNAV__NMEA__CHECKS__HPP
4 #include <marnav/nmea/constants.hpp>
5 #include <marnav/nmea/string.hpp>
6 #include <marnav/utils/optional.hpp>
19 static void throw_elaborated_invalid_argument(
20 T value
, std::initializer_list
<T
> options
, const char * name
= nullptr)
24 text
+= "invalid argument, value '";
25 text
+= to_string(value
);
26 text
+= "' not in options:{";
27 for (auto const & opt
: options
) {
29 text
+= to_string(opt
);
37 throw std::invalid_argument
{text
};
42 /// Checks the value agains a list of possible values.
44 /// @param[in] value Value to check.
45 /// @param[in] options Possible values to check against.
46 /// @param[in] name Optional name of the value to check. This name will be mentioned
47 /// in thrown exception, if the value is invalid.
49 /// @exception std::invalid_argument The value is not listed in the options.
51 void check_value(T value
, std::initializer_list
<T
> options
, const char * name
= nullptr)
54 if (find_if(begin(options
), end(options
), [value
](T opt
) { return value
== opt
; })
58 throw_elaborated_invalid_argument(value
, options
, name
);
62 void check_value(const utils::optional
<T
> & value
, std::initializer_list
<T
> options
,
63 const char * name
= nullptr)
66 check_value(value
.value(), options
, name
);
69 void check_status(status value
, const char * name
= nullptr);
71 void check_status(const utils::optional
<status
> & value
, const char * name
= nullptr);