From fce3bb180c56d0fc70d439c8e943cd6a3003363b Mon Sep 17 00:00:00 2001 From: "Daniel J. Hofmann" Date: Mon, 9 Jan 2017 11:28:00 +0530 Subject: [PATCH] Provides OSRM_ASSERT_WITH_LOC macros for asserting with location, resolves #3533 --- include/util/assert.hpp | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 include/util/assert.hpp diff --git a/include/util/assert.hpp b/include/util/assert.hpp new file mode 100644 index 000000000..f6761cc64 --- /dev/null +++ b/include/util/assert.hpp @@ -0,0 +1,45 @@ +#ifndef OSRM_UTIL_ASSERT_HPP +#define OSRM_UTIL_ASSERT_HPP + +#include +#include + +#include "util/coordinate.hpp" + +#include + +// Enhances BOOST_ASSERT / BOOST_ASSERT_MSG with convenience location printing +// - OSRM_ASSERT(cond, coordinate) +// - OSRM_ASSERT_MSG(cond, coordinate, msg) + +#ifdef BOOST_ENABLE_ASSERT_HANDLER + +#define OSRM_ASSERT_MSG(cond, loc, msg) \ + do \ + { \ + if (!static_cast(cond)) \ + { \ + ::osrm::util::FloatCoordinate c_(loc); \ + std::cerr << "[Location] " \ + << "http://www.openstreetmap.org/?mlat=" << c_.lat << "&mlon=" << c_.lon \ + << "#map=19/" << c_.lat << "/" << c_.lon << '\n'; \ + } \ + BOOST_ASSERT_MSG(cond, msg); \ + } while (0) + +#define OSRM_ASSERT(cond, loc) OSRM_ASSERT_MSG(cond, loc, "") + +#else + +#define OSRM_ASSERT_MSG(cond, coordinate, msg) \ + do \ + { \ + (void)cond; \ + (void)coordinate; \ + (void)msg; \ + } while (0) +#define OSRM_ASSERT(cond, coordinate) OSRM_ASSERT_MSG(cond, coordinate, "") + +#endif + +#endif