canonical swap and operator==

This commit is contained in:
artemp 2014-05-27 12:34:35 +01:00
parent f6a79ecaec
commit 7b9ba0db31
2 changed files with 21 additions and 17 deletions

View file

@ -58,7 +58,7 @@ public:
double max_scale_denominator = std::numeric_limits<double>::infinity());
rule(const rule& rhs);
rule& operator=(rule rhs);
bool operator==(rule const& other);
bool operator==(rule const& rhs) const;
void set_max_scale(double scale);
double get_max_scale() const;
void set_min_scale(double scale);
@ -88,8 +88,7 @@ public:
}
private:
void swap(rule& rhs) throw();
friend void swap(rule & lhs, rule & rhs);
};
}

View file

@ -64,30 +64,35 @@ rule::rule(rule const& rhs)
syms_(rhs.syms_),
filter_(std::make_shared<expr_node>(*rhs.filter_)),
else_filter_(rhs.else_filter_),
also_filter_(rhs.also_filter_)
{
}
also_filter_(rhs.also_filter_) {}
rule& rule::operator=(rule rhs)
{
swap(rhs);
swap(*this, rhs);
return *this;
}
bool rule::operator==(rule const& other)
bool rule::operator==(rule const& rhs) const
{
return (this == &other);
return (name_ == rhs.name_) &&
(min_scale_ == rhs.min_scale_) &&
(max_scale_ == rhs.max_scale_) &&
(syms_ == rhs.syms_) &&
(filter_ == rhs.filter_) &&
(else_filter_ == rhs.else_filter_) &&
(also_filter_ == rhs.also_filter_);
}
void rule::swap(rule& rhs) throw()
void swap(rule & lhs, rule & rhs)
{
name_=rhs.name_;
min_scale_=rhs.min_scale_;
max_scale_=rhs.max_scale_;
syms_=rhs.syms_;
filter_=rhs.filter_;
else_filter_=rhs.else_filter_;
also_filter_=rhs.also_filter_;
using std::swap;
swap(lhs.name_, rhs.name_);
swap(lhs.min_scale_, rhs.min_scale_);
swap(lhs.max_scale_, rhs.max_scale_);
swap(lhs.syms_, rhs.syms_);
swap(lhs.filter_, rhs.filter_);
swap(lhs.else_filter_, rhs.else_filter_);
swap(lhs.also_filter_, rhs.also_filter_);
}
void rule::set_max_scale(double scale)