From 00787ec12d53729bc6a3f528fb4e15264ce95577 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Thu, 23 Feb 2012 10:21:29 +0000 Subject: [PATCH] + implement 'filter' iterator to output key/value pairs where value is not value_null(). + use it in json::feature_generator to have more compact json --- include/mapnik/feature_kv_iterator.hpp | 34 +++++++++++++++++-- .../mapnik/json/feature_generator_grammar.hpp | 11 +++--- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/include/mapnik/feature_kv_iterator.hpp b/include/mapnik/feature_kv_iterator.hpp index 7717c5462..1cc46a566 100644 --- a/include/mapnik/feature_kv_iterator.hpp +++ b/include/mapnik/feature_kv_iterator.hpp @@ -23,12 +23,16 @@ #ifndef MAPNIK_FEATURE_KV_ITERATOR_HPP #define MAPNIK_FEATURE_KV_ITERATOR_HPP +// mapnik +#include +// boost #include #include - +#include +#include +// stl #include -//#include -#include + namespace mapnik { @@ -57,6 +61,30 @@ private: }; +struct is_null : public boost::static_visitor +{ + bool operator() (value_null const& val) const + { + return true; + } + + template + bool operator() (T val) const + { + return false; + } +}; + +struct value_not_null +{ + bool operator() (feature_kv_iterator::value_type const& kv) const + { + return !boost::apply_visitor(is_null(),boost::get<1>(kv).base()); + } +}; + +typedef boost::filter_iterator feature_kv_iterator2; + } #endif // MAPNIK_FEATURE_KV_ITERATOR_HPP diff --git a/include/mapnik/json/feature_generator_grammar.hpp b/include/mapnik/json/feature_generator_grammar.hpp index 292b3518a..5295b4493 100644 --- a/include/mapnik/json/feature_generator_grammar.hpp +++ b/include/mapnik/json/feature_generator_grammar.hpp @@ -27,6 +27,7 @@ #include #include #include +#include // boost #include @@ -47,26 +48,26 @@ struct is_container : mpl::false_ {} ; template <> struct container_iterator { - typedef mapnik::feature_kv_iterator type; + typedef mapnik::feature_kv_iterator2 type; }; template <> struct begin_container { - static mapnik::feature_kv_iterator + static mapnik::feature_kv_iterator2 call (mapnik::Feature const& f) { - return f.begin(); + return mapnik::feature_kv_iterator2(mapnik::value_not_null(),f.begin(),f.end()); } }; template <> struct end_container { - static mapnik::feature_kv_iterator + static mapnik::feature_kv_iterator2 call (mapnik::Feature const& f) { - return f.end(); + return mapnik::feature_kv_iterator2(mapnik::value_not_null(),f.end(),f.end()); } };