osrm-backend/include/engine/hint.hpp

65 lines
1.8 KiB
C++
Raw Normal View History

2016-01-28 10:28:44 -05:00
#ifndef ENGINE_HINT_HPP
#define ENGINE_HINT_HPP
#include "engine/object_encoder.hpp"
#include "engine/phantom_node.hpp"
#include "util/coordinate.hpp"
#include "phantom_node.hpp"
2016-01-28 10:28:44 -05:00
#include <boost/assert.hpp>
2016-02-18 18:54:30 -05:00
#include <cstdint>
2016-01-28 10:28:44 -05:00
#include <cmath>
2016-02-18 18:54:30 -05:00
#include <string>
2016-01-28 10:28:44 -05:00
namespace osrm
{
namespace engine
{
// Is returned as a temporary identifier for snapped coodinates
struct Hint
{
util::Coordinate input_coordinate;
2016-01-28 10:28:44 -05:00
PhantomNode phantom;
std::uint32_t data_checksum;
template <typename DataFacadeT>
bool IsValid(const util::Coordinate new_input_coordinates, DataFacadeT &facade) const
2016-01-28 10:28:44 -05:00
{
auto is_same_input_coordinate = new_input_coordinates.lon == input_coordinate.lon &&
new_input_coordinates.lat == input_coordinate.lat;
2016-01-28 10:28:44 -05:00
return is_same_input_coordinate && phantom.IsValid(facade.GetNumberOfNodes()) &&
facade.GetCheckSum() == data_checksum;
}
2016-02-18 18:54:30 -05:00
std::string ToBase64() const { return encodeBase64(*this); }
2016-01-28 10:28:44 -05:00
static Hint FromBase64(const std::string &base64Hint)
{
BOOST_ASSERT_MSG(base64Hint.size() ==
static_cast<std::size_t>(std::ceil(sizeof(Hint) / 3.) * 4),
"Hint has invalid size");
auto decoded = decodeBase64<Hint>(base64Hint);
return decoded;
}
};
#ifndef _MSC_VER
constexpr std::size_t ENCODED_HINT_SIZE = 88;
static_assert(ENCODED_HINT_SIZE / 4 * 3 >= sizeof(Hint),
"ENCODED_HINT_SIZE does not match size of Hint");
#else
// PhantomNode is bigger under windows because MSVC does not support bit packing
constexpr std::size_t ENCODED_HINT_SIZE = 84;
static_assert(ENCODED_HINT_SIZE / 4 * 3 >= sizeof(Hint),
"ENCODED_HINT_SIZE does not match size of Hint");
#endif
}
}
#endif