xlnt/source/styles/style.cpp

160 lines
3.6 KiB
C++
Raw Normal View History

2015-10-19 03:30:46 +08:00
#include <xlnt/cell/cell.hpp>
2015-10-26 12:44:55 +08:00
#include <xlnt/styles/font.hpp>
#include <xlnt/styles/number_format.hpp>
#include <xlnt/styles/protection.hpp>
2014-08-14 06:56:34 +08:00
#include <xlnt/styles/style.hpp>
2015-10-19 03:30:46 +08:00
namespace {
2015-10-19 03:30:46 +08:00
template <class T>
void hash_combine(std::size_t &seed, const T &v)
{
2015-10-19 03:30:46 +08:00
std::hash<T> hasher;
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
2015-10-19 03:30:46 +08:00
}
namespace xlnt {
2015-11-03 05:45:05 +08:00
const color color::black()
{
return color(color::type::rgb, "ff000000");
}
const color color::white()
{
return color(color::type::rgb, "ffffffff");
}
2015-10-24 02:42:36 +08:00
style::style()
: id_(0),
alignment_apply_(false),
border_apply_(false),
border_id_(0),
fill_apply_(false),
fill_id_(0),
font_apply_(false),
font_id_(0),
number_format_apply_(false),
number_format_id_(0),
protection_apply_(false),
pivot_button_(false),
quote_prefix_(false)
2015-10-24 02:42:36 +08:00
{
}
style::style(const style &other)
: id_(other.id_),
alignment_apply_(other.alignment_apply_),
alignment_(other.alignment_),
border_apply_(other.border_apply_),
border_id_(other.border_id_),
border_(other.border_),
fill_apply_(other.fill_apply_),
fill_id_(other.fill_id_),
fill_(other.fill_),
font_apply_(other.font_apply_),
font_id_(other.font_id_),
font_(other.font_),
number_format_apply_(other.number_format_apply_),
number_format_id_(other.number_format_id_),
number_format_(other.number_format_),
protection_apply_(other.protection_apply_),
protection_(other.protection_),
pivot_button_(other.pivot_button_),
quote_prefix_(other.quote_prefix_)
{
}
2015-10-24 02:42:36 +08:00
style &style::operator=(const style &other)
{
id_ = other.id_;
alignment_ = other.alignment_;
alignment_apply_ = other.alignment_apply_;
border_ = other.border_;
border_apply_ = other.border_apply_;
border_id_ = other.border_id_;
fill_ = other.fill_;
fill_apply_ = other.fill_apply_;
fill_id_ = other.fill_id_;
font_ = other.font_;
font_apply_ = other.font_apply_;
font_id_ = other.font_id_;
number_format_ = other.number_format_;
number_format_apply_ = other.number_format_apply_;
number_format_id_ = other.number_format_id_;
protection_ = other.protection_;
protection_apply_ = other.protection_apply_;
pivot_button_ = other.pivot_button_;
quote_prefix_ = other.quote_prefix_;
2015-10-24 02:42:36 +08:00
return *this;
}
2015-10-19 03:30:46 +08:00
std::size_t style::hash() const
{
2015-10-24 02:42:36 +08:00
std::size_t seed = 0;
2015-10-29 03:08:54 +08:00
hash_combine(seed, alignment_apply_);
hash_combine(seed, alignment_apply_ ? alignment_.hash() : 0);
2015-10-24 02:42:36 +08:00
hash_combine(seed, border_apply_);
2015-10-29 03:08:54 +08:00
hash_combine(seed, border_apply_ ? border_id_ : 0);
2015-10-24 02:42:36 +08:00
hash_combine(seed, font_apply_);
2015-10-29 03:08:54 +08:00
hash_combine(seed, font_apply_ ? font_id_ : 0);
2015-10-24 02:42:36 +08:00
hash_combine(seed, fill_apply_);
2015-10-29 03:08:54 +08:00
hash_combine(seed, fill_apply_ ? fill_id_ : 0);
2015-10-24 02:42:36 +08:00
hash_combine(seed, number_format_apply_);
2015-10-29 03:08:54 +08:00
hash_combine(seed, number_format_apply_ ? number_format_id_ : 0);
2015-10-24 02:42:36 +08:00
hash_combine(seed, protection_apply_);
2015-10-29 03:08:54 +08:00
hash_combine(seed, protection_apply_ ? get_protection().hash() : 0);
2015-10-19 03:30:46 +08:00
return seed;
}
2015-10-21 01:53:47 +08:00
const number_format style::get_number_format() const
{
2015-10-21 01:53:47 +08:00
return number_format_;
}
2015-10-19 03:30:46 +08:00
2015-10-21 01:53:47 +08:00
const border style::get_border() const
{
2015-10-21 01:53:47 +08:00
return border_;
}
2015-10-21 01:53:47 +08:00
const alignment style::get_alignment() const
2015-10-19 03:30:46 +08:00
{
2015-10-21 01:53:47 +08:00
return alignment_;
2015-10-19 03:30:46 +08:00
}
2015-10-21 01:53:47 +08:00
const fill style::get_fill() const
{
2015-10-21 01:53:47 +08:00
return fill_;
}
2015-10-21 01:53:47 +08:00
const font style::get_font() const
{
2015-10-21 01:53:47 +08:00
return font_;
}
2015-10-21 01:53:47 +08:00
const protection style::get_protection() const
{
2015-10-21 01:53:47 +08:00
return protection_;
}
2015-10-19 03:30:46 +08:00
bool style::pivot_button() const
{
2015-10-21 01:53:47 +08:00
return pivot_button_;
}
2015-10-19 03:30:46 +08:00
bool style::quote_prefix() const
{
2015-10-21 01:53:47 +08:00
return quote_prefix_;
}
} // namespace xlnt