From f6a79ecaececc4f953cc0ad5fce73dea0835e4ff Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 27 May 2014 12:33:20 +0100 Subject: [PATCH] font_set: add operator== and 'swap' impl --- include/mapnik/font_set.hpp | 10 ++++++++-- src/font_set.cpp | 21 +++++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/include/mapnik/font_set.hpp b/include/mapnik/font_set.hpp index 81221638d..19f0f8119 100644 --- a/include/mapnik/font_set.hpp +++ b/include/mapnik/font_set.hpp @@ -35,16 +35,22 @@ namespace mapnik class MAPNIK_DECL font_set { public: + // ctor/copy/move/dtor font_set(std::string const& name); font_set(font_set const& rhs); - font_set& operator=(font_set const& rhs); + font_set(font_set &&) = default; + font_set& operator=(font_set rhs); + ~font_set(); + // comparison + bool operator==(font_set const& rhs) const; std::size_t size() const; void set_name(std::string const& name); std::string const& get_name() const; void add_face_name(std::string const& face_name); std::vector const& get_face_names() const; - ~font_set(); + private: + friend void swap(font_set & lhs, font_set & rhs); std::string name_; std::vector face_names_; }; diff --git a/src/font_set.cpp b/src/font_set.cpp index 3ae8e1df2..4ef5274eb 100644 --- a/src/font_set.cpp +++ b/src/font_set.cpp @@ -36,16 +36,25 @@ font_set::font_set(font_set const& rhs) : name_(rhs.name_), face_names_(rhs.face_names_) {} -font_set& font_set::operator=(font_set const& other) +font_set& font_set::operator=(font_set other) { - if (this == &other) - return *this; - name_ = other.name_; - face_names_ = other.face_names_; - + swap(*this, other); return *this; } +void swap(font_set & lhs, font_set & rhs) +{ + using std::swap; + swap(lhs.name_, rhs.name_); + swap(lhs.face_names_, rhs.face_names_); +} + +bool font_set::operator==(font_set const& rhs) const +{ + return name_ == rhs.name_ && + face_names_ == rhs.face_names_; +} + font_set::~font_set() {} std::size_t font_set::size() const