+ 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
This commit is contained in:
Artem Pavlenko 2012-02-23 10:21:29 +00:00
parent 8fe79f910f
commit 00787ec12d
2 changed files with 37 additions and 8 deletions

View file

@ -23,12 +23,16 @@
#ifndef MAPNIK_FEATURE_KV_ITERATOR_HPP
#define MAPNIK_FEATURE_KV_ITERATOR_HPP
// mapnik
#include <mapnik/value.hpp>
// boost
#include <boost/tuple/tuple.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/iterator/filter_iterator.hpp>
#include <boost/variant.hpp>
// stl
#include <map>
//#include <mapnik/feature.hpp>
#include <mapnik/value.hpp>
namespace mapnik {
@ -57,6 +61,30 @@ private:
};
struct is_null : public boost::static_visitor<bool>
{
bool operator() (value_null const& val) const
{
return true;
}
template <typename T>
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<value_not_null, feature_kv_iterator> feature_kv_iterator2;
}
#endif // MAPNIK_FEATURE_KV_ITERATOR_HPP

View file

@ -27,6 +27,7 @@
#include <mapnik/global.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/json/geometry_generator_grammar.hpp>
#include <mapnik/feature_kv_iterator.hpp>
// boost
#include <boost/spirit/include/karma.hpp>
@ -47,26 +48,26 @@ struct is_container<mapnik::Feature const> : mpl::false_ {} ;
template <>
struct container_iterator<mapnik::Feature const>
{
typedef mapnik::feature_kv_iterator type;
typedef mapnik::feature_kv_iterator2 type;
};
template <>
struct begin_container<mapnik::Feature const>
{
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<mapnik::Feature const>
{
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());
}
};