Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ var fs = require('fs');
*/
module.exports =
'# HTTP API\n' +
fs.readFileSync('./content/http.md', 'utf8') + '\n'+
'# libosrm C++ API\n' +
fs.readFileSync('./content/libosrm.md', 'utf8') + '\n';
fs.readFileSync('./content/http.md', 'utf8') + '\n'
// '# libosrm C++ API\n' +
// fs.readFileSync('./content/libosrm.md', 'utf8') + '\n';
3 changes: 1 addition & 2 deletions include/engine/api/route_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,7 @@ class RouteAPI : public BaseAPI
nodes.values.reserve(leg_geometry.node_ids.size());
for (const auto node_id : leg_geometry.node_ids)
{
nodes.values.push_back(
static_cast<std::uint64_t>(facade.GetOSMNodeIDOfNode(node_id)));
nodes.values.push_back(facade.GetOSMNodeIDOfNode(node_id));
}
annotation.values.emplace("nodes", std::move(nodes));
}
Expand Down
10 changes: 10 additions & 0 deletions include/nodejs/json_v8_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ struct V8Renderer
out = Napi::Number::New(env, number.value);
}

void operator()(const osrm::json::Integer &number) const
{
out = Napi::Number::New(env, number.value);
}

void operator()(const osrm::json::Unsigned &number) const
{
out = Napi::Number::New(env, number.value);
}

void operator()(const osrm::json::Object &object) const
{
Napi::Object obj = Napi::Object::New(env);
Expand Down
36 changes: 35 additions & 1 deletion include/util/json_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <variant>
#include <vector>

#include "util/typedefs.hpp"

namespace osrm::util::json
{

Expand Down Expand Up @@ -69,6 +71,38 @@ struct Number
double value;
};

/**
* Typed signed integer.
*
* This one must be explicitly requested. eg.:
*
* util::json::Integer{-42}
*/
struct Integer
{
Integer() = default;
explicit Integer(long long value_) : value{value_} {}
long long value;
};

/**
* Typed unsigned integer.
*
* This one must be explicitly requested for numbers, eg.:
*
* util::json::Unsigned{42}
*
* It will be automatically selected for OSMNodeID and OSMWayID.
*/
struct Unsigned
{
Unsigned() = default;
explicit Unsigned(unsigned long long value_) : value{value_} {}
Unsigned(OSMNodeID value_) : value{from_alias<uint64_t>(value_)} {}
Unsigned(OSMWayID value_) : value{from_alias<uint64_t>(value_)} {}
unsigned long long value;
};

/**
* Typed True.
*/
Expand All @@ -95,7 +129,7 @@ struct Null
*
* Dispatch on its type by either by using apply_visitor or its get function.
*/
using Value = std::variant<String, Number, Object, Array, True, False, Null>;
using Value = std::variant<String, Number, Integer, Unsigned, Object, Array, True, False, Null>;

/**
* Typed Object.
Expand Down
22 changes: 22 additions & 0 deletions include/util/json_deep_compare.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ struct Comparator
return is_same;
}

bool operator()(const Integer &lhs, const Integer &rhs) const
{
bool is_same = lhs.value == rhs.value;
if (!is_same)
{
reason = lhs_path + " (= " + std::to_string(lhs.value) + ") != " + rhs_path +
" (= " + std::to_string(rhs.value) + ")";
}
return is_same;
}

bool operator()(const Unsigned &lhs, const Unsigned &rhs) const
{
bool is_same = lhs.value == rhs.value;
if (!is_same)
{
reason = lhs_path + " (= " + std::to_string(lhs.value) + ") != " + rhs_path +
" (= " + std::to_string(rhs.value) + ")";
}
return is_same;
}

bool operator()(const Object &lhs, const Object &rhs) const
{
std::set<std::string_view> lhs_keys;
Expand Down
14 changes: 14 additions & 0 deletions include/util/json_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ template <typename Out> struct Renderer
write('"');
}

void operator()(const Unsigned &number)
{
fmt::memory_buffer buffer;
fmt::format_to(std::back_inserter(buffer), FMT_COMPILE("{}"), number.value);
write(buffer.data(), buffer.size());
}

void operator()(const Integer &number)
{
fmt::memory_buffer buffer;
fmt::format_to(std::back_inserter(buffer), FMT_COMPILE("{}"), number.value);
write(buffer.data(), buffer.size());
}

void operator()(const Number &number)
{
// we don't want to print NaN or Infinity
Expand Down
10 changes: 6 additions & 4 deletions scripts/check_taginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

valid_strings = [t["key"] for t in taginfo["tags"]]
valid_strings += [t["value"] for t in taginfo["tags"] if "value" in t]
valid_strings += [t["value"].lower() for t in taginfo["tags"] if "value" in t] # lower is for max speed
valid_strings += [
t["value"].lower() for t in taginfo["tags"] if "value" in t
] # lower is for max speed
valid_strings = set(valid_strings)

string_regxp = re.compile("\"([\d\w\_:]+)\"")
string_regxp = re.compile(r"\"([\d\w\_:]+)\"")

profile = None
with open(profile_path) as f:
Expand All @@ -40,7 +42,7 @@
errors = []
for token in tokens:
if token not in WHITELIST and token not in valid_strings:
idx = line.find("\""+token+"\"")
idx = line.find('"' + token + '"')
errors.append((idx, token))
errors = sorted(errors)
n_errors += len(errors)
Expand All @@ -49,7 +51,7 @@
offset = len(prefix)
for idx, token in errors:
sys.stdout.write(prefix + line)
marker = " "*(idx+offset) + "~"*(len(token)+2)
marker = " " * (idx + offset) + "~" * (len(token) + 2)
print(marker)

if n_errors > 0:
Expand Down
49 changes: 44 additions & 5 deletions unit_tests/util/json_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,51 @@ BOOST_AUTO_TEST_CASE(number_truncating)
BOOST_CHECK_EQUAL(str, "42.99959996");
}

BOOST_AUTO_TEST_CASE(integer)
BOOST_AUTO_TEST_CASE(explicit_integer)
{
std::string str;
Renderer<std::string> renderer(str);
renderer(Number{42.0});
BOOST_CHECK_EQUAL(str, "42");
std::string output;
Renderer<std::string> renderer(output);

renderer(Integer{42});
BOOST_CHECK_EQUAL(output, "42");

output.clear();
renderer(Integer{-42});
BOOST_CHECK_EQUAL(output, "-42");

output.clear();
renderer(Integer{std::numeric_limits<int64_t>::min()});
BOOST_CHECK_EQUAL(output, "-9223372036854775808");

output.clear();
renderer(Integer{std::numeric_limits<int64_t>::max()});
BOOST_CHECK_EQUAL(output, "9223372036854775807");
}

BOOST_AUTO_TEST_CASE(explicit_unsigned)
{
std::string output;
osrm::util::json::Renderer<std::string> renderer(output);

renderer(Unsigned{std::numeric_limits<uint64_t>::min()});
BOOST_CHECK_EQUAL(output, "0");

output.clear();
renderer(Unsigned{std::numeric_limits<uint64_t>::max()});
BOOST_CHECK_EQUAL(output, "18446744073709551615");
}

BOOST_AUTO_TEST_CASE(implicit_osm_id)
{
std::string output;
osrm::util::json::Renderer<std::string> renderer(output);

renderer(OSMNodeID{std::numeric_limits<uint64_t>::min()});
BOOST_CHECK_EQUAL(output, "0");

output.clear();
renderer(OSMNodeID{std::numeric_limits<uint64_t>::max()});
BOOST_CHECK_EQUAL(output, "18446744073709551615");
}

BOOST_AUTO_TEST_CASE(test_json_issue_6531)
Expand Down