use SFINAE to check for process(xxx_symbolizer,..) in derived classes

avoid writing dummy process(...) methods
This commit is contained in:
Artem Pavlenko 2012-03-21 09:29:37 +00:00
parent 89877edc67
commit 4aaae73e51

View file

@ -35,7 +35,7 @@
// boost // boost
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <boost/concept_check.hpp>
//stl //stl
#include <vector> #include <vector>
@ -56,6 +56,33 @@
namespace mapnik namespace mapnik
{ {
template <typename T0,typename T1> struct has_process;
template <bool>
struct process_impl
{
template <typename T0, typename T1, typename T2, typename T3>
static void process(T0 & ren, T1 const& sym, T2 const& f, T3 const& tr)
{
ren.process(sym,f,tr);
}
};
template <> // No-op specialization
struct process_impl<false>
{
template <typename T0, typename T1, typename T2, typename T3>
static void process(T0 & ren, T1 const& sym, T2 const& f, T3 const& tr)
{
boost::ignore_unused_variable_warning(ren);
boost::ignore_unused_variable_warning(f);
boost::ignore_unused_variable_warning(tr);
#ifdef MAPNIK_DEBUG
std::clog << "NO-OP ...\n";
#endif
}
};
/** Calls the renderer's process function, /** Calls the renderer's process function,
* \param output Renderer * \param output Renderer
* \param f Feature to process * \param f Feature to process
@ -75,7 +102,7 @@ struct feature_style_processor<Processor>::symbol_dispatch : public boost::stati
template <typename T> template <typename T>
void operator () (T const& sym) const void operator () (T const& sym) const
{ {
output_.process(sym,f_,prj_trans_); process_impl<has_process<Processor,T>::value>::process(output_,sym,f_,prj_trans_);
} }
Processor & output_; Processor & output_;
@ -83,6 +110,24 @@ struct feature_style_processor<Processor>::symbol_dispatch : public boost::stati
proj_transform const& prj_trans_; proj_transform const& prj_trans_;
}; };
typedef char (&no_tag)[1];
typedef char (&yes_tag)[2];
template <typename T0, typename T1, void (T0::*)(T1 const&, mapnik::feature_ptr const&, proj_transform const&) >
struct process_memfun_helper {};
template <typename T0, typename T1> no_tag has_process_helper(...);
template <typename T0, typename T1> yes_tag has_process_helper(process_memfun_helper<T0, T1, &T0::process>* p);
template<typename T0,typename T1>
struct has_process
{
BOOST_STATIC_CONSTANT(bool
, value = sizeof(has_process_helper<T0,T1>(0)) == sizeof(yes_tag)
);
};
template <typename Processor> template <typename Processor>
feature_style_processor<Processor>::feature_style_processor(Map const& m, double scale_factor) feature_style_processor<Processor>::feature_style_processor(Map const& m, double scale_factor)
: m_(m), scale_factor_(scale_factor) : m_(m), scale_factor_(scale_factor)