replace boost::variant w/ mapbox::util::variant

This commit is contained in:
Dennis Luxen 2014-06-26 15:08:52 +02:00
parent b310e0f718
commit 7d2c627ad2
2 changed files with 51 additions and 48 deletions

View File

@ -30,9 +30,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef JSON_CONTAINER_H #ifndef JSON_CONTAINER_H
#define JSON_CONTAINER_H #define JSON_CONTAINER_H
#include "../ThirdParty/variant/variant.hpp"
#include "../Util/StringUtil.h" #include "../Util/StringUtil.h"
#include <boost/variant.hpp> // #include <boost/variant.hpp>
#include <iostream> #include <iostream>
#include <vector> #include <vector>
@ -42,21 +43,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace JSON namespace JSON
{ {
struct String; // struct String;
struct Number; // struct Number;
struct Object; struct Object;
struct Array; struct Array;
struct True; // struct True;
struct False; // struct False;
struct Null; // struct Null;
typedef boost::variant<boost::recursive_wrapper<String>,
boost::recursive_wrapper<Number>,
boost::recursive_wrapper<Object>,
boost::recursive_wrapper<Array>,
boost::recursive_wrapper<True>,
boost::recursive_wrapper<False>,
boost::recursive_wrapper<Null> > Value;
struct String struct String
{ {
@ -73,16 +67,6 @@ struct Number
double value; double value;
}; };
struct Object
{
std::unordered_map<std::string, Value> values;
};
struct Array
{
std::vector<Value> values;
};
struct True struct True
{ {
}; };
@ -95,7 +79,25 @@ struct Null
{ {
}; };
struct Renderer : boost::static_visitor<> typedef mapbox::util::variant<String,
Number,
mapbox::util::recursive_wrapper<Object>,
mapbox::util::recursive_wrapper<Array>,
True,
False,
Null > Value;
struct Object
{
std::unordered_map<std::string, Value> values;
};
struct Array
{
std::vector<Value> values;
};
struct Renderer : mapbox::util::static_visitor<>
{ {
Renderer(std::ostream &_out) : out(_out) {} Renderer(std::ostream &_out) : out(_out) {}
@ -114,7 +116,7 @@ struct Renderer : boost::static_visitor<>
while (iterator != object.values.end()) while (iterator != object.values.end())
{ {
out << "\"" << (*iterator).first << "\":"; out << "\"" << (*iterator).first << "\":";
boost::apply_visitor(Renderer(out), (*iterator).second); mapbox::util::apply_visitor(Renderer(out), (*iterator).second);
if (++iterator != object.values.end()) if (++iterator != object.values.end())
{ {
out << ","; out << ",";
@ -130,7 +132,7 @@ struct Renderer : boost::static_visitor<>
iterator = array.values.begin(); iterator = array.values.begin();
while (iterator != array.values.end()) while (iterator != array.values.end())
{ {
boost::apply_visitor(Renderer(out), *iterator); mapbox::util::apply_visitor(Renderer(out), *iterator);
if (++iterator != array.values.end()) if (++iterator != array.values.end())
{ {
out << ","; out << ",";
@ -149,7 +151,7 @@ struct Renderer : boost::static_visitor<>
std::ostream &out; std::ostream &out;
}; };
struct ArrayRenderer : boost::static_visitor<> struct ArrayRenderer : mapbox::util::static_visitor<>
{ {
ArrayRenderer(std::vector<char> &_out) : out(_out) {} ArrayRenderer(std::vector<char> &_out) : out(_out) {}
@ -176,7 +178,7 @@ struct ArrayRenderer : boost::static_visitor<>
out.push_back('\"'); out.push_back('\"');
out.push_back(':'); out.push_back(':');
boost::apply_visitor(ArrayRenderer(out), (*iterator).second); mapbox::util::apply_visitor(ArrayRenderer(out), (*iterator).second);
if (++iterator != object.values.end()) if (++iterator != object.values.end())
{ {
out.push_back(','); out.push_back(',');
@ -192,7 +194,7 @@ struct ArrayRenderer : boost::static_visitor<>
iterator = array.values.begin(); iterator = array.values.begin();
while (iterator != array.values.end()) while (iterator != array.values.end())
{ {
boost::apply_visitor(ArrayRenderer(out), *iterator); mapbox::util::apply_visitor(ArrayRenderer(out), *iterator);
if (++iterator != array.values.end()) if (++iterator != array.values.end())
{ {
out.push_back(','); out.push_back(',');
@ -223,13 +225,13 @@ struct ArrayRenderer : boost::static_visitor<>
inline void render(std::ostream &out, const Object &object) inline void render(std::ostream &out, const Object &object)
{ {
Value value = object; Value value = object;
boost::apply_visitor(Renderer(out), value); mapbox::util::apply_visitor(Renderer(out), value);
} }
inline void render(std::vector<char> &out, const Object &object) inline void render(std::vector<char> &out, const Object &object)
{ {
Value value = object; Value value = object;
boost::apply_visitor(ArrayRenderer(out), value); mapbox::util::apply_visitor(ArrayRenderer(out), value);
} }
} // namespace JSON } // namespace JSON

View File

@ -35,6 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "SharedMemoryFactory.h" #include "SharedMemoryFactory.h"
#include "SharedMemoryVectorWrapper.h" #include "SharedMemoryVectorWrapper.h"
#include "../ThirdParty/variant/variant.hpp"
#include "../Util/MercatorUtil.h" #include "../Util/MercatorUtil.h"
#include "../Util/NumericUtil.h" #include "../Util/NumericUtil.h"
#include "../Util/OSRMException.h" #include "../Util/OSRMException.h"
@ -48,7 +49,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/fstream.hpp>
#include <boost/thread.hpp> #include <boost/thread.hpp>
#include <boost/variant.hpp> // #include <boost/variant.hpp>
#include <tbb/parallel_for.h> #include <tbb/parallel_for.h>
#include <tbb/parallel_sort.h> #include <tbb/parallel_sort.h>
@ -307,7 +308,7 @@ class StaticRTree
} }
}; };
typedef boost::variant<TreeNode, EdgeDataT> IncrementalQueryNodeType; typedef mapbox::util::variant<TreeNode, EdgeDataT> IncrementalQueryNodeType;
struct IncrementalQueryCandidate struct IncrementalQueryCandidate
{ {
explicit IncrementalQueryCandidate(const float dist, const IncrementalQueryNodeType &node) explicit IncrementalQueryCandidate(const float dist, const IncrementalQueryNodeType &node)
@ -323,23 +324,23 @@ class StaticRTree
return other.min_dist < min_dist; return other.min_dist < min_dist;
} }
inline bool RepresentsTreeNode() const // inline bool RepresentsTreeNode() const
{ // {
return boost::apply_visitor(decide_type_visitor(), node); // return mapbox::util::apply_visitor(decide_type_visitor(), node);
} // }
float min_dist; float min_dist;
IncrementalQueryNodeType node; IncrementalQueryNodeType node;
private: // private:
class decide_type_visitor : public boost::static_visitor<bool> // class decide_type_visitor : public mapbox::util::static_visitor<bool>
{ // {
public: // public:
bool operator()(const TreeNode &) const { return true; } // bool operator()(const TreeNode &) const { return true; }
template<typename AnotherType> // template<typename AnotherType>
bool operator()(const AnotherType &) const { return false; } // bool operator()(const AnotherType &) const { return false; }
}; // };
}; };
typename ShM<TreeNode, UseSharedMemory>::vector m_search_tree; typename ShM<TreeNode, UseSharedMemory>::vector m_search_tree;
@ -700,9 +701,9 @@ class StaticRTree
continue; continue;
} }
if (current_query_node.RepresentsTreeNode()) if (current_query_node.node.template is<TreeNode>())
{ {
const TreeNode & current_tree_node = boost::get<TreeNode>(current_query_node.node); const TreeNode & current_tree_node = current_query_node.node.template get<TreeNode>();
if (current_tree_node.child_is_on_disk) if (current_tree_node.child_is_on_disk)
{ {
++loaded_leafs; ++loaded_leafs;
@ -775,7 +776,7 @@ class StaticRTree
{ {
++inspected_segments; ++inspected_segments;
// inspecting an actual road segment // inspecting an actual road segment
const EdgeDataT & current_segment = boost::get<EdgeDataT>(current_query_node.node); const EdgeDataT & current_segment = current_query_node.node.template get<EdgeDataT>();
// don't collect too many results from small components // don't collect too many results from small components
if (number_of_results_found_in_big_cc == number_of_results && !current_segment.is_in_tiny_cc) if (number_of_results_found_in_big_cc == number_of_results && !current_segment.is_in_tiny_cc)