diff --git a/include/mapnik/attribute.hpp b/include/mapnik/attribute.hpp index 196874392..62b7a2a75 100644 --- a/include/mapnik/attribute.hpp +++ b/include/mapnik/attribute.hpp @@ -23,10 +23,15 @@ #ifndef MAPNIK_ATTRIBUTE_HPP #define MAPNIK_ATTRIBUTE_HPP +// mapnik +#include +// stl #include namespace mapnik { +static mapnik::value _null_value; + struct attribute { std::string name_; @@ -34,9 +39,15 @@ struct attribute : name_(name) {} template - V value(F const& f) const + V const& value(F const& f) const { - return f[name_]; + typedef typename F::const_iterator const_iterator; + const_iterator itr = f.find(name_); + if (itr != f.end()) + { + return itr->second; + } + return _null_value; } std::string const& name() const { return name_;} }; diff --git a/include/mapnik/feature.hpp b/include/mapnik/feature.hpp index 087776799..fd8347a3e 100644 --- a/include/mapnik/feature.hpp +++ b/include/mapnik/feature.hpp @@ -65,6 +65,7 @@ private: std::map props_; public: typedef std::map::iterator iterator; + typedef std::map::const_iterator const_iterator; explicit feature(int id) : properties(props_), id_(id), @@ -145,7 +146,7 @@ public: { return props_; } - + iterator begin() { return props_.begin(); @@ -155,7 +156,22 @@ public: { return props_.end(); } + + const_iterator begin() const + { + return props_.begin(); + } + const_iterator end() const + { + return props_.end(); + } + + const_iterator find(std::string const& key) const + { + return props_.find(key); + } + std::string to_string() const { std::stringstream ss; diff --git a/include/mapnik/metawriter.hpp b/include/mapnik/metawriter.hpp index 3b2838b5d..fa324cecf 100644 --- a/include/mapnik/metawriter.hpp +++ b/include/mapnik/metawriter.hpp @@ -47,11 +47,22 @@ struct placement; class metawriter_property_map { public: + typedef std::map property_map; + typedef property_map::const_iterator const_iterator; + metawriter_property_map() {} UnicodeString const& operator[](std::string const& key) const; UnicodeString& operator[](std::string const& key) {return m_[key];} + std::map::const_iterator find(std::string const& key) const + { + return m_.find(key); + } + std::map::const_iterator end() const + { + return m_.end(); + } private: - std::map m_; + property_map m_; UnicodeString not_found_; };