Vanetza
Loading...
Searching...
No Matches
country_database.hpp
1#pragma once
2#include <vanetza/geodesy/country_polygon.hpp>
3#include <vanetza/geodesy/m49_code.hpp>
4#include <vanetza/geodesy/position.hpp>
5#include <cstddef>
6#include <string>
7#include <unordered_map>
8
9namespace vanetza
10{
11namespace geodesy
12{
13
15{
16public:
17 /**
18 * Create a CountryDatabase from embedded country data.
19 * Only available when built with VANETZA_WITH_EMBEDDED_COUNTRY_DATA.
20 * \param[out] error optional error message
21 * \return loaded database, or empty database on failure
22 */
23 static CountryDatabase embedded(std::string* error = nullptr);
24
25 /**
26 * Load country data from a file.
27 * \param[in] path path to the binary country data file
28 * \param[out] error optional error message
29 * \return true on success
30 */
31 bool load(const std::string& path, std::string* error = nullptr);
32
33 /**
34 * Load country data from a memory buffer.
35 * \param[in] data pointer to binary data
36 * \param[in] length size of data in bytes
37 * \param[out] error optional error message
38 * \return true on success
39 */
40 bool load(const uint8_t* data, std::size_t length, std::string* error = nullptr);
41
42 /**
43 * Check if a geodetic position lies within a country.
44 * \param country M.49 country code
45 * \param position geodetic position to check
46 * \return true if position is inside the country's boundaries
47 */
48 bool is_inside(M49Code country, const GeodeticPosition& position) const;
49
50 /**
51 * Check if the database contains any country data.
52 * \return true if no countries are loaded
53 */
54 bool empty() const;
55
56private:
57 std::unordered_map<M49Code, CountryPolygon> m_countries;
58};
59
60} // namespace geodesy
61} // namespace vanetza
bool is_inside(M49Code country, const GeodeticPosition &position) const
bool load(const std::string &path, std::string *error=nullptr)
bool load(const uint8_t *data, std::size_t length, std::string *error=nullptr)
static CountryDatabase embedded(std::string *error=nullptr)