summaryrefslogtreecommitdiffstats
path: root/server/src/datex2.cppm
blob: 9c75013aca005ab0898a0a50a645789b773930d8 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
module;

#include <boost/geometry/algorithms/is_empty.hpp>
#include <boost/geometry/srs/epsg.hpp>
#include <boost/geometry/srs/transformation.hpp>

#include <pugixml.hpp>

export module routemon:datex2;

import std;
import :geo;
import :time;
import :util;

using namespace std::literals::string_view_literals;

namespace routemon::datex2 {

export struct situation;

export struct road_closure
{
  std::weak_ptr<situation> parent;
  std::optional<time::period_seq> validity;
  std::vector<geo::point> relevant_points = {};
  std::vector<std::shared_ptr<geo::linestring>> relevant_line_strings = {};
};

export struct situation
{
  std::string id;
  std::optional<geo::point> location =
      std::nullopt; // as shown on the map, not used for querying
  std::vector<std::string> comments = {};
  std::vector<std::shared_ptr<road_closure>> road_closures = {};
};

export struct situation_publication
{
  time::timestamp publication_time;
  std::vector<std::shared_ptr<situation>> situations;
};

export class loader
{
  // ETRS 89 (EPSG:4258) -> WGS 84 (EPSG:4326)
  bgeo::srs::
      transformation<bgeo::srs::static_epsg<4258>, bgeo::srs::static_epsg<4326>>
          etrs89_to_wgs84_{};

  std::multiset<std::string> warnings_;

  auto add_location_from_xml(road_closure& rc, pugi::xml_node const& loc_xml)
      -> void;

  auto handle_road_or_carriageway_or_lane_management(
      pugi::xml_node const& record_xml, std::weak_ptr<situation> parent)
      -> std::optional<std::shared_ptr<road_closure>>;

public:
  [[nodiscard]] auto load_situation_publication(std::string const& filename)
      -> situation_publication;
  [[nodiscard]] auto warnings() const -> std::multiset<std::string> const&;
};

} // namespace routemon::datex2