MapAppABI.cpp 1.84 KB
Newer Older
1
#include "pi2-view.h"
Martin Kröning's avatar
Martin Kröning committed
2
3
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmismatched-tags"
Martin Kröning's avatar
Martin Kröning committed
4
#include "MapApp.hpp"
Martin Kröning's avatar
Martin Kröning committed
5
#pragma clang diagnostic pop
Martin Kröning's avatar
Martin Kröning committed
6
7
8
9
10
11
12
13
#include <algorithm>
#include <chrono>
#include <gsl/pointers>
#include <gsl/span>
#include <gsl/string_span>
#include <valarray>
#include <vector>

14
15
16
gsl::owner<MapApp *> mapAppCreate(gsl::czstring<> windowTitle) {
  return new MapApp(windowTitle);
}
Martin Kröning's avatar
Martin Kröning committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

void mapAppDestroy(gsl::owner<MapApp *> mapApp) { delete mapApp; }

void mapAppAddJunction(MapApp *mapApp, const double x, const double y) {
  mapApp->addJunction(x, y);
}

void mapAppAddRoad(MapApp *mapApp, gsl::czstring<> laneThereName,
                   gsl::czstring<> laneBackName, const double coordinates[],
                   const size_t coordinateCount) {
  const gsl::span<const double> coordinatesSpan(coordinates, coordinateCount);
  std::vector<std::valarray<double>> coordinateVector(coordinateCount / 2);
  std::generate(coordinateVector.begin(), coordinateVector.end(),
                [&coordinatesSpan, i = 0]() mutable {
                  return std::valarray<double>(
                      {coordinatesSpan.at(i++), coordinatesSpan(i++)});
                });
  mapApp->addRoad(laneThereName, laneBackName, coordinateVector);
}

Martin Kröning's avatar
Martin Kröning committed
37
void mapAppAddOrReplaceVehicle(MapApp *mapApp, gsl::czstring<> vehicleName,
Martin Kröning's avatar
Martin Kröning committed
38
39
40
41
42
43
44
45
46
47
48
                               gsl::czstring<> roadName,
                               const double positionOnLane, const double speed,
                               const double remainingFuel, const double red,
                               const double green, const double blue) {
  mapApp->addOrReplaceVehicle(vehicleName, roadName, positionOnLane, speed,
                              remainingFuel, red, green, blue);
}

void mapAppSetDurationLabel(MapApp *mapApp, int64_t minutes) {
  mapApp->setDurationLabel(std::chrono::minutes(minutes));
}