xLnt. Implemented operator less for: rich_text, rich_text_run, color, font, optional.

This commit is contained in:
Andrii Tkachenko 2018-02-08 08:05:41 +01:00
parent 55cf7a2bed
commit 3246d602c2
9 changed files with 167 additions and 13 deletions

View File

@ -119,6 +119,10 @@ public:
/// </summary>
bool operator!=(const std::string &rhs) const;
/// <summary>
/// Returns true if this text is less to rhs.
/// </summary>
bool operator<(const rich_text &rhs) const;
private:
/// <summary>
/// The runs that make up this rich text.

View File

@ -39,6 +39,8 @@ struct rich_text_run
std::string first;
optional<font> second;
bool operator<(const rich_text_run &other) const;
bool operator==(const rich_text_run &other) const;
bool operator!=(const rich_text_run &other) const;

View File

@ -276,10 +276,15 @@ public:
/// </summary>
void tint(double tint);
/// <summary>
/// Returns true if this color is equivalent to other
/// </summary>
bool operator==(const color &other) const;
/// <summary>
/// Returns true if this color is less to other
/// </summary>
bool operator<(const color &other) const;
/// <summary>
/// Returns true if this color is equivalent to other
/// </summary>
bool operator==(const color &other) const;
/// <summary>
/// Returns true if this color is not equivalent to other

View File

@ -224,10 +224,15 @@ public:
/// </summary>
std::string scheme() const;
/// <summary>
/// Returns true if left is exactly equal to right.
/// </summary>
bool operator==(const font &other) const;
/// <summary>
/// Returns true if left is exactly equal to right.
/// </summary>
bool operator==(const font &other) const;
/// <summary>
/// Returns true if left is less to right.
/// </summary>
bool operator<(const font &other) const;
/// <summary>
/// Returns true if left is not exactly equal to right.

View File

@ -123,11 +123,20 @@ public:
/// or both have a value and those values are equal according to
/// their equality operator.
/// </summary>
bool operator==(const optional<T> &other) const
{
return has_value_ == other.has_value_
&& (!has_value_ || (has_value_ && value_ == other.value_));
}
bool operator==(const optional<T> &other) const
{
return has_value_ == other.has_value_
&& (!has_value_ || (has_value_ && value_ == other.value_));
}
/// <summary>
/// Returns true if this is less to other
/// </summary>
bool operator<(const optional<T> &other) const
{
return has_value_ < other.has_value_
&& (!has_value_ || (has_value_ && value_ < other.value_));
}
private:
bool has_value_;

View File

@ -85,6 +85,23 @@ void rich_text::add_run(const rich_text_run &t)
runs_.push_back(t);
}
bool rich_text::operator<(const rich_text &rhs) const
{
if (runs_.size() < rhs.runs_.size())
return true;
if (runs_.size() > rhs.runs_.size())
return false;
for (std::size_t i = 0; i < runs_.size(); i++)
{
if (runs_[i] != rhs.runs_[i])
return runs_[i] < rhs.runs_[i];
}
return false;
}
bool rich_text::operator==(const rich_text &rhs) const
{
if (runs_.size() != rhs.runs_.size()) return false;

View File

@ -25,6 +25,11 @@
namespace xlnt {
bool rich_text_run::operator<(const rich_text_run &other) const
{
return first < other.first && second < other.second;
}
bool rich_text_run::operator==(const rich_text_run &other) const
{
return first == other.first && second == other.second;

View File

@ -259,6 +259,34 @@ void color::assert_type(color_type t) const
}
}
bool color::operator<(const xlnt::color &other) const
{
if (type_ != other.type_)
{
return type_ < other.type_;
}
if (std::fabs(tint_ - other.tint_) != 0.0)
{
return tint_ < other.tint_;
}
if (auto__ != other.auto__)
return auto__ < other.auto__;
switch (type_)
{
case color_type::indexed:
return indexed_.index() < other.indexed_.index();
case color_type::theme:
return theme_.index() < other.theme_.index();
case color_type::rgb:
return rgb_.hex_string() < other.rgb_.hex_string();
}
return false;
}
bool color::operator==(const xlnt::color &other) const
{
if (type_ != other.type_ || std::fabs(tint_ - other.tint_) != 0.0 || auto__ != other.auto__)

View File

@ -286,4 +286,83 @@ bool font::operator==(const font &other) const
return true;
}
bool font::operator<(const font &other) const
{
if (bold() != other.bold())
{
return bold() < other.bold();
}
if (has_color() != other.has_color())
{
return has_color() < other.has_color();
}
if (has_color())
{
if (color() != other.color())
{
return color() < other.color();
}
}
if (has_family() != other.has_family())
{
return has_family() < other.has_family();
}
if (has_family())
{
if (family() != other.family())
{
return family() < other.family();
}
}
if (italic() != other.italic())
{
return italic() < other.italic();
}
if (name() != other.name())
{
return name() < other.name();
}
if (has_scheme() != other.has_scheme())
{
return has_scheme() < other.has_scheme();
}
if (has_scheme())
{
if (scheme() != other.scheme())
{
return scheme() < other.scheme();
}
}
if (std::fabs(size() - other.size()) != 0.0)
{
return size() < other.size();
}
if (strikethrough() != other.strikethrough())
{
return strikethrough() < other.strikethrough();
}
if (superscript() != other.superscript())
{
return superscript() < other.superscript();
}
if (underline() != other.underline())
{
return underline() < other.underline();
}
return false;
}
} // namespace xlnt