Skip to content

Commit

Permalink
Working version of strategy grouping
Browse files Browse the repository at this point in the history
  • Loading branch information
flippmoke committed Apr 17, 2015
1 parent 75ccfdf commit 8ad5648
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
52 changes: 38 additions & 14 deletions include/mapnik/geometry_strategy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,64 @@
namespace mapnik {
namespace geometry {

template <typename Strategy, typename... Strategies>
namespace helper
{
template <std::size_t... Ts>
struct index {};

template <std::size_t N, std::size_t... Ts>
struct gen_seq : gen_seq<N - 1, N - 1, Ts...> {};

template <std::size_t... Ts>
struct gen_seq<0, Ts...> : index<Ts...> {};
}

template <typename... Strategies>
struct strategy_group
{
strategy_group(Strategy const& op, Strategies const& ... ops)
: ops_(op, ops ...) {}
strategy_group(Strategies const& ... ops)
: ops_(ops ...) {}

template <typename P1, typename P2>
inline bool apply(P1 const& p1, P2 & p2) const
{
bool status = true;
p2 = execute_first<0, P1, P2, Strategy, ...Strategies>(p1, status);
p2 = execute_start<P1,P2>(p1, status, ops_);
return status;
}

template <int c, typename P1, typename P2, typename T, typename ...Args>
inline P2 execute_first(P1 const& p, bool & status)
template <typename P1, typename P2, typename... Args, std::size_t... Is>
inline P2 execute_start(P1 const & p1, bool & status, std::tuple<Args const&...> const& tup, helper::index<Is...>) const
{
return execute_first<P1,P2, Args...>(p1, status, std::get<Is>(tup)...);
}

template <typename P1, typename P2>
inline P2 execute_start(P1 const& p, bool & status, std::tuple<Strategies const& ...> const& tup) const
{
return execute_start<P1,P2, Strategies...>(p, status, tup, helper::gen_seq<sizeof...(Strategies)> {} );
}

template <typename P1, typename P2, typename T, typename ...Args>
inline P2 execute_first(P1 const& p, bool & status, T const& strat, Args const& ... args) const
{
return execute_next<c+1,P1,P2,...Args>(std::get<c>(ops_).template execute<P1,P2>(p, status), status);
return execute_next(strat.template execute<P1,P2>(p, status), status, args...);
}

template <int c, typename P2, typename T, typename ...Args>
inline P2 execute_next(P2 const& p, bool & status)
template <typename P2, typename T, typename ...Args>
inline P2 execute_next(P2 const& p, bool & status, T const& strat, Args const& ... args) const
{
return execute_next<c+1, P2, ...Args>(std::get<c>(ops_).template execute<P2,P2>(p, status), status);
return execute_next(strat.template execute<P2,P2>(p, status), status, args...);
}

template <int c, typename P2, typename T>
inline P2 execute_next(P2 const& p, bool & status)
template <typename P2>
inline P2 execute_next(P2 const& p, bool & status) const
{
return std::get<c>(ops_).template execute<P2,P2>(p, status);
return p;
}

private:
std::tuple<Strategy const&, Strategies const& ...> ops_;
std::tuple<Strategies const& ...> ops_;

};

Expand Down
4 changes: 2 additions & 2 deletions tests/cxx/geometry_strategy_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ SECTION("proj and view strategy") {

}
{
// Test that both work streamed together
// Test that both work grouped together
using sg_type = strategy_group<mapnik::proj_strategy, mapnik::view_strategy<double> >;
sg_type sg(ps, vs);
point<double> p1(-97.553098,35.523105);
point<double> r1(58.6287 , 100.945);
geometry<double> p2 = transform<double>(p1, sg);
REQUIRE(p2.is<point<double> >());
point<double> p3 = mapnik::util::get<point<double> >(p2);
std::cout << p3.x << " , " << p3.y << std::endl;
//std::cout << p3.x << " , " << p3.y << std::endl;
assert_g_equal(r1, p3);
}

Expand Down

0 comments on commit 8ad5648

Please sign in to comment.