+ add get_optional to mapnik::feature_impl
returns -> boost::optional<mapnik::value const&> + use get_optional in feature_kv_iterator to avoid throwing exceptions
This commit is contained in:
parent
63735982ee
commit
c6a091937f
2 changed files with 17 additions and 12 deletions
|
@ -159,24 +159,26 @@ public:
|
|||
value_type const& get(context_type::key_type const& key) const
|
||||
{
|
||||
context_type::map_type::const_iterator itr = ctx_->mapping_.find(key);
|
||||
if (itr != ctx_->mapping_.end()
|
||||
&& itr->second < data_.size())
|
||||
{
|
||||
return data_[itr->second];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::out_of_range(std::string("Key does not exist: '") + key + "'");
|
||||
}
|
||||
if (itr != ctx_->mapping_.end())
|
||||
return get(itr->second);
|
||||
else
|
||||
throw std::out_of_range(std::string("Key does not exist: '") + key + "'");
|
||||
}
|
||||
|
||||
|
||||
value_type const& get(std::size_t index) const
|
||||
{
|
||||
if (index < data_.size())
|
||||
return data_[index];
|
||||
throw std::out_of_range("Index out of range");
|
||||
}
|
||||
|
||||
|
||||
boost::optional<value_type const&> get_optional(std::size_t index) const
|
||||
{
|
||||
if (index < data_.size())
|
||||
return boost::optional<value_type const&>(data_[index]);
|
||||
return boost::optional<value_type const&>();
|
||||
}
|
||||
|
||||
std::size_t size() const
|
||||
{
|
||||
return data_.size();
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <mapnik/feature_kv_iterator.hpp>
|
||||
#include <mapnik/feature.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
|
@ -44,7 +45,9 @@ bool feature_kv_iterator::equal( feature_kv_iterator const& other) const
|
|||
feature_kv_iterator::value_type const& feature_kv_iterator::dereference() const
|
||||
{
|
||||
boost::get<0>(kv_) = itr_->first;
|
||||
boost::get<1>(kv_) = f_.get(itr_->first);
|
||||
boost::optional<mapnik::value const&> val = f_.get_optional(itr_->second);
|
||||
if (val) boost::get<1>(kv_) = *val;
|
||||
else boost::get<1>(kv_) = value_null();
|
||||
return kv_;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue