Skip to content

Commit 561a19c

Browse files
Initial commit
1 parent 646384a commit 561a19c

File tree

8 files changed

+63
-16
lines changed

8 files changed

+63
-16
lines changed

include/engine/api/nearest_api.hpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class NearestAPI final : public BaseAPI
6565
auto &phantom_node = phantom_with_distance.phantom_node;
6666

6767
auto node_values = MakeNodes(phantom_node);
68-
fbresult::Uint64Pair nodes{node_values.first, node_values.second};
68+
fbresult::Uint64Pair nodes{from_alias<uint64_t>(node_values.first),
69+
from_alias<uint64_t>(node_values.second)};
6970

7071
auto waypoint = MakeWaypoint(&fb_result, {phantom_node});
7172
waypoint->add_nodes(&nodes);
@@ -123,10 +124,10 @@ class NearestAPI final : public BaseAPI
123124
const NearestParameters &parameters;
124125

125126
protected:
126-
std::pair<uint64_t, uint64_t> MakeNodes(const PhantomNode &phantom_node) const
127+
std::pair<OSMNodeID, OSMNodeID> MakeNodes(const PhantomNode &phantom_node) const
127128
{
128-
std::uint64_t from_node = 0;
129-
std::uint64_t to_node = 0;
129+
OSMNodeID from_node = OSMNodeID{0};
130+
OSMNodeID to_node = OSMNodeID{0};
130131

131132
datafacade::BaseDataFacade::NodeForwardRange forward_geometry;
132133
if (phantom_node.forward_segment_id.enabled)
@@ -135,26 +136,22 @@ class NearestAPI final : public BaseAPI
135136
const auto geometry_id = facade.GetGeometryIndex(segment_id).id;
136137
forward_geometry = facade.GetUncompressedForwardGeometry(geometry_id);
137138

138-
auto osm_node_id =
139+
to_node =
139140
facade.GetOSMNodeIDOfNode(forward_geometry[phantom_node.fwd_segment_position]);
140-
to_node = static_cast<std::uint64_t>(osm_node_id);
141141
}
142142

143143
if (phantom_node.reverse_segment_id.enabled)
144144
{
145145
auto segment_id = phantom_node.reverse_segment_id.id;
146146
const auto geometry_id = facade.GetGeometryIndex(segment_id).id;
147147
const auto geometry = facade.GetUncompressedForwardGeometry(geometry_id);
148-
auto osm_node_id =
149-
facade.GetOSMNodeIDOfNode(geometry[phantom_node.fwd_segment_position + 1]);
150-
from_node = static_cast<std::uint64_t>(osm_node_id);
148+
from_node = facade.GetOSMNodeIDOfNode(geometry[phantom_node.fwd_segment_position + 1]);
151149
}
152150
else if (phantom_node.forward_segment_id.enabled && phantom_node.fwd_segment_position > 0)
153151
{
154152
// In the case of one way, rely on forward segment only
155-
auto osm_node_id =
153+
from_node =
156154
facade.GetOSMNodeIDOfNode(forward_geometry[phantom_node.fwd_segment_position - 1]);
157-
from_node = static_cast<std::uint64_t>(osm_node_id);
158155
}
159156

160157
return std::make_pair(from_node, to_node);

include/engine/api/route_api.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,8 +842,7 @@ class RouteAPI : public BaseAPI
842842
nodes.values.reserve(leg_geometry.node_ids.size());
843843
for (const auto node_id : leg_geometry.node_ids)
844844
{
845-
nodes.values.push_back(
846-
static_cast<std::uint64_t>(facade.GetOSMNodeIDOfNode(node_id)));
845+
nodes.values.push_back(facade.GetOSMNodeIDOfNode(node_id));
847846
}
848847
annotation.values.emplace("nodes", std::move(nodes));
849848
}

include/nodejs/json_v8_renderer.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ struct V8Renderer
2121
out = Napi::Number::New(env, number.value);
2222
}
2323

24+
void operator()(const osrm::json::OSMID &osmid) const
25+
{
26+
out = Napi::BigInt::New(env, osmid.value);
27+
}
28+
2429
void operator()(const osrm::json::Object &object) const
2530
{
2631
Napi::Object obj = Napi::Object::New(env);

include/util/json_container.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3131
#ifndef JSON_CONTAINER_HPP
3232
#define JSON_CONTAINER_HPP
3333

34+
#include "util/typedefs.hpp"
35+
3436
#include <string>
3537
#include <unordered_map>
3638
#include <utility>
@@ -69,6 +71,17 @@ struct Number
6971
double value;
7072
};
7173

74+
/**
75+
* Typed OSM id.
76+
*/
77+
struct OSMID
78+
{
79+
OSMID() = default;
80+
OSMID(OSMNodeID id) : value{from_alias<uint64_t>(id)} {};
81+
OSMID(OSMWayID id) : value{from_alias<uint64_t>(id)} {};
82+
uint64_t value;
83+
};
84+
7285
/**
7386
* Typed True.
7487
*/
@@ -95,7 +108,7 @@ struct Null
95108
*
96109
* Dispatch on its type by either by using apply_visitor or its get function.
97110
*/
98-
using Value = std::variant<String, Number, Object, Array, True, False, Null>;
111+
using Value = std::variant<String, Number, Object, Array, True, False, Null, OSMID>;
99112

100113
/**
101114
* Typed Object.

include/util/json_deep_compare.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ struct Comparator
4040
return is_same;
4141
}
4242

43+
bool operator()(const OSMID &lhs, const OSMID &rhs) const
44+
{
45+
bool is_same = lhs.value == rhs.value;
46+
if (!is_same)
47+
{
48+
reason = lhs_path + " (= " + std::to_string(lhs.value) + ") != " + rhs_path +
49+
" (= " + std::to_string(rhs.value) + ")";
50+
}
51+
return is_same;
52+
}
53+
4354
bool operator()(const Object &lhs, const Object &rhs) const
4455
{
4556
std::set<std::string_view> lhs_keys;

include/util/json_renderer.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ template <typename Out> struct Renderer
5858
write(buffer.data(), buffer.size());
5959
}
6060

61+
void operator()(const OSMID &osmid)
62+
{
63+
fmt::memory_buffer buffer;
64+
fmt::format_to(std::back_inserter(buffer), FMT_COMPILE("{}"), osmid.value);
65+
66+
write(buffer.data(), buffer.size());
67+
}
68+
6169
void operator()(const Object &object)
6270
{
6371
write('{');

unit_tests/library/nearest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ void test_nearest_response_for_location_in_small_component(bool use_json_only_ap
168168

169169
const auto &nodes = std::get<json::Array>(waypoint_object.values.at("nodes")).values;
170170
BOOST_CHECK(nodes.size() == 2);
171-
BOOST_CHECK(std::get<util::json::Number>(nodes[0]).value != 0);
172-
BOOST_CHECK(std::get<util::json::Number>(nodes[1]).value != 0);
171+
BOOST_CHECK(std::get<util::json::OSMID>(nodes[0]).value != 0);
172+
BOOST_CHECK(std::get<util::json::OSMID>(nodes[1]).value != 0);
173173
}
174174
}
175175
BOOST_AUTO_TEST_CASE(test_nearest_response_for_location_in_small_component_old_api)

unit_tests/util/json_render.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "util/json_container.hpp"
22
#include "util/json_renderer.hpp"
3+
#include "util/typedefs.hpp"
34

45
#include <boost/test/unit_test.hpp>
56

@@ -25,6 +26,19 @@ BOOST_AUTO_TEST_CASE(integer)
2526
BOOST_CHECK_EQUAL(str, "42");
2627
}
2728

29+
BOOST_AUTO_TEST_CASE(osmid)
30+
{
31+
std::string str;
32+
Renderer<std::string> renderer(str);
33+
34+
renderer(OSMNodeID{std::numeric_limits<uint64_t>::min()});
35+
BOOST_CHECK_EQUAL(str, "0");
36+
str.clear();
37+
38+
renderer(OSMNodeID{std::numeric_limits<uint64_t>::max()});
39+
BOOST_CHECK_EQUAL(str, "18446744073709551615");
40+
}
41+
2842
BOOST_AUTO_TEST_CASE(test_json_issue_6531)
2943
{
3044
std::string output;

0 commit comments

Comments
 (0)