avoid creating default initialised values if key doesn't exist
This commit is contained in:
parent
c1504f874e
commit
4b65b7259e
3 changed files with 42 additions and 4 deletions
|
@ -23,10 +23,15 @@
|
|||
#ifndef MAPNIK_ATTRIBUTE_HPP
|
||||
#define MAPNIK_ATTRIBUTE_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/value.hpp>
|
||||
// stl
|
||||
#include <string>
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
static mapnik::value _null_value;
|
||||
|
||||
struct attribute
|
||||
{
|
||||
std::string name_;
|
||||
|
@ -34,9 +39,15 @@ struct attribute
|
|||
: name_(name) {}
|
||||
|
||||
template <typename V ,typename F>
|
||||
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_;}
|
||||
};
|
||||
|
|
|
@ -65,6 +65,7 @@ private:
|
|||
std::map<std::string,value> props_;
|
||||
public:
|
||||
typedef std::map<std::string,value>::iterator iterator;
|
||||
typedef std::map<std::string,value>::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;
|
||||
|
|
|
@ -47,11 +47,22 @@ struct placement;
|
|||
class metawriter_property_map
|
||||
{
|
||||
public:
|
||||
typedef std::map<std::string, UnicodeString> 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<std::string, UnicodeString>::const_iterator find(std::string const& key) const
|
||||
{
|
||||
return m_.find(key);
|
||||
}
|
||||
std::map<std::string, UnicodeString>::const_iterator end() const
|
||||
{
|
||||
return m_.end();
|
||||
}
|
||||
private:
|
||||
std::map<std::string, UnicodeString> m_;
|
||||
property_map m_;
|
||||
UnicodeString not_found_;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue