From 7d2c627ad28b130b719fa7c2137ca9308dd40f7c Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 26 Jun 2014 15:08:52 +0200 Subject: [PATCH] replace boost::variant w/ mapbox::util::variant --- DataStructures/JSONContainer.h | 64 ++++++++++++++++++---------------- DataStructures/StaticRTree.h | 35 ++++++++++--------- 2 files changed, 51 insertions(+), 48 deletions(-) diff --git a/DataStructures/JSONContainer.h b/DataStructures/JSONContainer.h index 47dc34b27..db9ac5d6d 100644 --- a/DataStructures/JSONContainer.h +++ b/DataStructures/JSONContainer.h @@ -30,9 +30,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef JSON_CONTAINER_H #define JSON_CONTAINER_H +#include "../ThirdParty/variant/variant.hpp" #include "../Util/StringUtil.h" -#include +// #include #include #include @@ -42,21 +43,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace JSON { -struct String; -struct Number; +// struct String; +// struct Number; struct Object; struct Array; -struct True; -struct False; -struct Null; +// struct True; +// struct False; +// struct Null; -typedef boost::variant, - boost::recursive_wrapper, - boost::recursive_wrapper, - boost::recursive_wrapper, - boost::recursive_wrapper, - boost::recursive_wrapper, - boost::recursive_wrapper > Value; struct String { @@ -73,16 +67,6 @@ struct Number double value; }; -struct Object -{ - std::unordered_map values; -}; - -struct Array -{ - std::vector values; -}; - struct True { }; @@ -95,7 +79,25 @@ struct Null { }; -struct Renderer : boost::static_visitor<> +typedef mapbox::util::variant, + mapbox::util::recursive_wrapper, + True, + False, + Null > Value; + +struct Object +{ + std::unordered_map values; +}; + +struct Array +{ + std::vector values; +}; + +struct Renderer : mapbox::util::static_visitor<> { Renderer(std::ostream &_out) : out(_out) {} @@ -114,7 +116,7 @@ struct Renderer : boost::static_visitor<> while (iterator != object.values.end()) { out << "\"" << (*iterator).first << "\":"; - boost::apply_visitor(Renderer(out), (*iterator).second); + mapbox::util::apply_visitor(Renderer(out), (*iterator).second); if (++iterator != object.values.end()) { out << ","; @@ -130,7 +132,7 @@ struct Renderer : boost::static_visitor<> iterator = array.values.begin(); while (iterator != array.values.end()) { - boost::apply_visitor(Renderer(out), *iterator); + mapbox::util::apply_visitor(Renderer(out), *iterator); if (++iterator != array.values.end()) { out << ","; @@ -149,7 +151,7 @@ struct Renderer : boost::static_visitor<> std::ostream &out; }; -struct ArrayRenderer : boost::static_visitor<> +struct ArrayRenderer : mapbox::util::static_visitor<> { ArrayRenderer(std::vector &_out) : out(_out) {} @@ -176,7 +178,7 @@ struct ArrayRenderer : boost::static_visitor<> 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()) { out.push_back(','); @@ -192,7 +194,7 @@ struct ArrayRenderer : boost::static_visitor<> iterator = array.values.begin(); while (iterator != array.values.end()) { - boost::apply_visitor(ArrayRenderer(out), *iterator); + mapbox::util::apply_visitor(ArrayRenderer(out), *iterator); if (++iterator != array.values.end()) { out.push_back(','); @@ -223,13 +225,13 @@ struct ArrayRenderer : boost::static_visitor<> inline void render(std::ostream &out, const Object &object) { Value value = object; - boost::apply_visitor(Renderer(out), value); + mapbox::util::apply_visitor(Renderer(out), value); } inline void render(std::vector &out, const Object &object) { Value value = object; - boost::apply_visitor(ArrayRenderer(out), value); + mapbox::util::apply_visitor(ArrayRenderer(out), value); } } // namespace JSON diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 1e7eba625..425be3a6b 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -35,6 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "SharedMemoryFactory.h" #include "SharedMemoryVectorWrapper.h" +#include "../ThirdParty/variant/variant.hpp" #include "../Util/MercatorUtil.h" #include "../Util/NumericUtil.h" #include "../Util/OSRMException.h" @@ -48,7 +49,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include +// #include #include #include @@ -307,7 +308,7 @@ class StaticRTree } }; - typedef boost::variant IncrementalQueryNodeType; + typedef mapbox::util::variant IncrementalQueryNodeType; struct IncrementalQueryCandidate { explicit IncrementalQueryCandidate(const float dist, const IncrementalQueryNodeType &node) @@ -323,23 +324,23 @@ class StaticRTree return other.min_dist < min_dist; } - inline bool RepresentsTreeNode() const - { - return boost::apply_visitor(decide_type_visitor(), node); - } + // inline bool RepresentsTreeNode() const + // { + // return mapbox::util::apply_visitor(decide_type_visitor(), node); + // } float min_dist; IncrementalQueryNodeType node; - private: - class decide_type_visitor : public boost::static_visitor - { - public: - bool operator()(const TreeNode &) const { return true; } + // private: + // class decide_type_visitor : public mapbox::util::static_visitor + // { + // public: + // bool operator()(const TreeNode &) const { return true; } - template - bool operator()(const AnotherType &) const { return false; } - }; + // template + // bool operator()(const AnotherType &) const { return false; } + // }; }; typename ShM::vector m_search_tree; @@ -700,9 +701,9 @@ class StaticRTree continue; } - if (current_query_node.RepresentsTreeNode()) + if (current_query_node.node.template is()) { - const TreeNode & current_tree_node = boost::get(current_query_node.node); + const TreeNode & current_tree_node = current_query_node.node.template get(); if (current_tree_node.child_is_on_disk) { ++loaded_leafs; @@ -775,7 +776,7 @@ class StaticRTree { ++inspected_segments; // inspecting an actual road segment - const EdgeDataT & current_segment = boost::get(current_query_node.node); + const EdgeDataT & current_segment = current_query_node.node.template get(); // 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)