add has_name(std::string const& name) const method

This commit is contained in:
artemp 2015-10-16 13:14:41 +01:00
parent 2437473e74
commit e88ecb86c4

View file

@ -30,6 +30,7 @@
// stl // stl
#include <iosfwd> #include <iosfwd>
#include <vector> #include <vector>
#include <algorithm>
namespace mapnik namespace mapnik
{ {
@ -40,13 +41,13 @@ public:
layer_descriptor(std::string const& name, std::string const& encoding) layer_descriptor(std::string const& name, std::string const& encoding)
: name_(name), : name_(name),
encoding_(encoding), encoding_(encoding),
desc_ar_(), descriptors_(),
extra_params_() {} extra_params_() {}
layer_descriptor(layer_descriptor const& other) layer_descriptor(layer_descriptor const& other)
: name_(other.name_), : name_(other.name_),
encoding_(other.encoding_), encoding_(other.encoding_),
desc_ar_(other.desc_ar_), descriptors_(other.descriptors_),
extra_params_(other.extra_params_) {} extra_params_(other.extra_params_) {}
void set_name(std::string const& name) void set_name(std::string const& name)
@ -71,17 +72,17 @@ public:
void add_descriptor(attribute_descriptor const& desc) void add_descriptor(attribute_descriptor const& desc)
{ {
desc_ar_.push_back(desc); descriptors_.push_back(desc);
} }
std::vector<attribute_descriptor> const& get_descriptors() const std::vector<attribute_descriptor> const& get_descriptors() const
{ {
return desc_ar_; return descriptors_;
} }
std::vector<attribute_descriptor>& get_descriptors() std::vector<attribute_descriptor>& get_descriptors()
{ {
return desc_ar_; return descriptors_;
} }
parameters const& get_extra_parameters() const parameters const& get_extra_parameters() const
@ -93,11 +94,16 @@ public:
{ {
return extra_params_; return extra_params_;
} }
bool has_name(std::string const& name) const
{
auto result = std::find_if(std::begin(descriptors_), std::end(descriptors_),
[&name](attribute_descriptor const& desc) { return name == desc.get_name();});
return result != std::end(descriptors_);
}
private: private:
std::string name_; std::string name_;
std::string encoding_; std::string encoding_;
std::vector<attribute_descriptor> desc_ar_; std::vector<attribute_descriptor> descriptors_;
parameters extra_params_; parameters extra_params_;
}; };