Add json logger to map_matching
This adds additional data to the json response, when OSRM is compiled in debug mode.
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2015, Project OSRM, Dennis Luxen, others
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef JSON_LOGGER_HPP
|
||||
#define JSON_LOGGER_HPP
|
||||
|
||||
#include <osrm/json_container.hpp>
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace json
|
||||
{
|
||||
|
||||
class Logger
|
||||
{
|
||||
using MapT = std::unordered_map<std::string, osrm::json::Value>;
|
||||
|
||||
public:
|
||||
static Logger* get()
|
||||
{
|
||||
static Logger logger;
|
||||
|
||||
#ifdef NDEBUG
|
||||
return nullptr;
|
||||
#else
|
||||
return &logger;
|
||||
#endif
|
||||
}
|
||||
|
||||
void initialize(const std::string& name)
|
||||
{
|
||||
if (!map.get())
|
||||
{
|
||||
map.reset(new MapT());
|
||||
}
|
||||
(*map)[name] = Object();
|
||||
}
|
||||
|
||||
void render(const std::string& name, Object& obj) const
|
||||
{
|
||||
obj.values["debug"] = map->at(name);
|
||||
}
|
||||
|
||||
boost::thread_specific_ptr<MapT> map;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SIMPLE_LOGGER_HPP */
|
||||
+32
-6
@@ -41,7 +41,8 @@ namespace osrm
|
||||
namespace json
|
||||
{
|
||||
|
||||
template <typename T> T clampFloat(T d)
|
||||
// Make sure we don't have inf and NaN values
|
||||
template <typename T> T clamp_float(T d)
|
||||
{
|
||||
if (std::isnan(d) || std::numeric_limits<T>::infinity() == d)
|
||||
{
|
||||
@@ -55,21 +56,46 @@ template <typename T> T clampFloat(T d)
|
||||
return d;
|
||||
}
|
||||
|
||||
void appendToArray(osrm::json::Array &a) {}
|
||||
void append_to_array(osrm::json::Array &a) {}
|
||||
template <typename T, typename... Args>
|
||||
void appendToArray(osrm::json::Array &a, T value, Args... args)
|
||||
void append_to_array(osrm::json::Array &a, T value, Args... args)
|
||||
{
|
||||
a.values.emplace_back(value);
|
||||
appendToJSONArray(a, args...);
|
||||
append_to_array(a, args...);
|
||||
}
|
||||
|
||||
template <typename... Args> osrm::json::Array makeArray(Args... args)
|
||||
template <typename... Args> osrm::json::Array make_array(Args... args)
|
||||
{
|
||||
osrm::json::Array a;
|
||||
appendToJSONArray(a, args...);
|
||||
append_to_array(a, args...);
|
||||
return a;
|
||||
}
|
||||
|
||||
template <typename T> osrm::json::Array make_array(const std::vector<T>& vector)
|
||||
{
|
||||
osrm::json::Array a;
|
||||
for (const auto& v : vector)
|
||||
a.values.emplace_back(v);
|
||||
return a;
|
||||
}
|
||||
|
||||
// Easy acces to object hierachies
|
||||
osrm::json::Value& get(osrm::json::Value& value) { return value; }
|
||||
|
||||
template<typename... Keys>
|
||||
osrm::json::Value& get(osrm::json::Value& value, const char* key, Keys... keys)
|
||||
{
|
||||
using recursive_object_t = mapbox::util::recursive_wrapper<osrm::json::Object>;
|
||||
return get(value.get<recursive_object_t>().get().values[key], keys...);
|
||||
}
|
||||
|
||||
template<typename... Keys>
|
||||
osrm::json::Value& get(osrm::json::Value& value, unsigned key, Keys... keys)
|
||||
{
|
||||
using recursive_array_t = mapbox::util::recursive_wrapper<osrm::json::Array>;
|
||||
return get(value.get<recursive_array_t>().get().values[key], keys...);
|
||||
}
|
||||
|
||||
} // namespace json
|
||||
} // namespace osrm
|
||||
#endif // JSON_RENDERER_HPP
|
||||
|
||||
Reference in New Issue
Block a user