remove potentially problematic methods on optional, fix windows build

This commit is contained in:
Thomas Fussell 2016-12-29 19:00:27 -05:00
parent 294fc8f3b7
commit 398bf7a3bb
8 changed files with 50 additions and 92 deletions

View File

@ -40,7 +40,7 @@ public:
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
optional<bool> shrink() const; bool shrink() const;
/// <summary> /// <summary>
/// ///
@ -50,7 +50,7 @@ public:
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
optional<bool> wrap() const; bool wrap() const;
/// <summary> /// <summary>
/// ///
@ -111,12 +111,12 @@ public:
} }
private: private:
optional<bool> shrink_to_fit_; bool shrink_to_fit_ = false;
optional<bool> wrap_text_; bool wrap_text_ = false;
optional<int> indent_; optional<int> indent_;
optional<int> text_rotation_; optional<int> text_rotation_;
optional<horizontal_alignment> horizontal_ = horizontal_alignment::general; optional<horizontal_alignment> horizontal_;
optional<vertical_alignment> vertical_ = vertical_alignment::bottom; optional<vertical_alignment> vertical_;
}; };
} // namespace xlnt } // namespace xlnt

View File

@ -47,7 +47,7 @@ public:
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
optional(const T &value) : has_value_(true), value_(value) explicit optional(const T &value) : has_value_(true), value_(value)
{ {
} }
@ -76,38 +76,6 @@ public:
value_ = value; value_ = value;
} }
/// <summary>
///
/// </summary>
T &operator*()
{
return get();
}
/// <summary>
///
/// </summary>
const T &operator*() const
{
return get();
}
/// <summary>
///
/// </summary>
T *operator->()
{
return &get();
}
/// <summary>
///
/// </summary>
const T *operator->() const
{
return &get();
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -143,6 +111,14 @@ public:
value_ = T(); value_ = T();
} }
optional &operator=(const T &rhs)
{
has_value_ = true;
value_ = rhs;
return *this;
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>

View File

@ -910,7 +910,7 @@ format cell::modifiable_format()
throw invalid_attribute(); throw invalid_attribute();
} }
return xlnt::format(*d_->format_); return xlnt::format(d_->format_.get());
} }
const format cell::format() const const format cell::format() const
@ -920,7 +920,7 @@ const format cell::format() const
throw invalid_attribute(); throw invalid_attribute();
} }
return xlnt::format(*d_->format_); return xlnt::format(d_->format_.get());
} }
alignment cell::alignment() const alignment cell::alignment() const

View File

@ -1002,14 +1002,14 @@ void xlsx_producer::write_styles(const relationship & /*rel*/)
if (pattern.foreground()) if (pattern.foreground())
{ {
serializer().start_element(xmlns, "fgColor"); serializer().start_element(xmlns, "fgColor");
write_color(*pattern.foreground()); write_color(pattern.foreground().get());
serializer().end_element(xmlns, "fgColor"); serializer().end_element(xmlns, "fgColor");
} }
if (pattern.background()) if (pattern.background())
{ {
serializer().start_element(xmlns, "bgColor"); serializer().start_element(xmlns, "bgColor");
write_color(*pattern.background()); write_color(pattern.background().get());
serializer().end_element(xmlns, "bgColor"); serializer().end_element(xmlns, "bgColor");
} }
@ -1081,12 +1081,12 @@ void xlsx_producer::write_styles(const relationship & /*rel*/)
if (current_border.diagonal()) if (current_border.diagonal())
{ {
auto up = *current_border.diagonal() == diagonal_direction::both auto up = current_border.diagonal().get() == diagonal_direction::both
|| *current_border.diagonal() == diagonal_direction::up; || current_border.diagonal().get() == diagonal_direction::up;
serializer().attribute("diagonalUp", write_bool(up)); serializer().attribute("diagonalUp", write_bool(up));
auto down = *current_border.diagonal() == diagonal_direction::both auto down = current_border.diagonal().get() == diagonal_direction::both
|| *current_border.diagonal() == diagonal_direction::down; || current_border.diagonal().get() == diagonal_direction::down;
serializer().attribute("diagonalDown", write_bool(down)); serializer().attribute("diagonalDown", write_bool(down));
} }
@ -1094,20 +1094,20 @@ void xlsx_producer::write_styles(const relationship & /*rel*/)
{ {
if (current_border.side(side)) if (current_border.side(side))
{ {
const auto current_side = *current_border.side(side); const auto current_side = current_border.side(side).get();
auto side_name = to_string(side); auto side_name = to_string(side);
serializer().start_element(xmlns, side_name); serializer().start_element(xmlns, side_name);
if (current_side.style()) if (current_side.style())
{ {
serializer().attribute("style", *current_side.style()); serializer().attribute("style", current_side.style().get());
} }
if (current_side.color()) if (current_side.color())
{ {
serializer().start_element(xmlns, "color"); serializer().start_element(xmlns, "color");
write_color(*current_side.color()); write_color(current_side.color().get());
serializer().end_element(xmlns, "color"); serializer().end_element(xmlns, "color");
} }
@ -1189,7 +1189,7 @@ void xlsx_producer::write_styles(const relationship & /*rel*/)
if (current_alignment.wrap()) if (current_alignment.wrap())
{ {
serializer().attribute("wrapText", write_bool(current_alignment.wrap().get())); serializer().attribute("wrapText", write_bool(current_alignment.wrap()));
} }
if (current_alignment.indent()) if (current_alignment.indent())
@ -1199,7 +1199,7 @@ void xlsx_producer::write_styles(const relationship & /*rel*/)
if (current_alignment.shrink()) if (current_alignment.shrink())
{ {
serializer().attribute("shrinkToFit", write_bool(current_alignment.shrink().get())); serializer().attribute("shrinkToFit", write_bool(current_alignment.shrink()));
} }
serializer().end_element(xmlns, "alignment"); serializer().end_element(xmlns, "alignment");
@ -1301,7 +1301,7 @@ void xlsx_producer::write_styles(const relationship & /*rel*/)
if (current_alignment.wrap()) if (current_alignment.wrap())
{ {
serializer().attribute("wrapText", write_bool(current_alignment.wrap().get())); serializer().attribute("wrapText", write_bool(current_alignment.wrap()));
} }
if (current_alignment.indent()) if (current_alignment.indent())
@ -1311,7 +1311,7 @@ void xlsx_producer::write_styles(const relationship & /*rel*/)
if (current_alignment.shrink()) if (current_alignment.shrink())
{ {
serializer().attribute("shrinkToFit", write_bool(current_alignment.shrink().get())); serializer().attribute("shrinkToFit", write_bool(current_alignment.shrink()));
} }
serializer().end_element(xmlns, "alignment"); serializer().end_element(xmlns, "alignment");

View File

@ -26,7 +26,7 @@
namespace xlnt { namespace xlnt {
optional<bool> alignment::wrap() const bool alignment::wrap() const
{ {
return wrap_text_; return wrap_text_;
} }
@ -37,7 +37,7 @@ alignment &alignment::wrap(bool wrap_text)
return *this; return *this;
} }
optional<bool> alignment::shrink() const bool alignment::shrink() const
{ {
return shrink_to_fit_; return shrink_to_fit_;
} }
@ -133,19 +133,11 @@ XLNT_API bool operator==(const alignment &left, const alignment &right)
} }
} }
if (left.shrink().is_set() != right.shrink().is_set()) if (left.shrink() != right.shrink())
{ {
return false; return false;
} }
if (left.shrink().is_set())
{
if (left.shrink().get() != right.shrink().get())
{
return false;
}
}
if (left.vertical().is_set() != right.vertical().is_set()) if (left.vertical().is_set() != right.vertical().is_set())
{ {
return false; return false;
@ -159,19 +151,11 @@ XLNT_API bool operator==(const alignment &left, const alignment &right)
} }
} }
if (left.wrap().is_set() != right.wrap().is_set()) if (left.wrap() != right.wrap())
{ {
return false; return false;
} }
if (left.wrap().is_set())
{
if (left.wrap().get() != right.wrap().get())
{
return false;
}
}
return true; return true;
} }

View File

@ -12,10 +12,8 @@ public:
{ {
xlnt::alignment alignment; xlnt::alignment alignment;
TS_ASSERT(alignment.horizontal()); TS_ASSERT(!alignment.horizontal().is_set());
TS_ASSERT_EQUALS(*alignment.horizontal(), xlnt::horizontal_alignment::general); TS_ASSERT(!alignment.vertical().is_set());
TS_ASSERT(alignment.vertical());
TS_ASSERT_EQUALS(*alignment.vertical(), xlnt::vertical_alignment::bottom);
TS_ASSERT(!alignment.shrink()); TS_ASSERT(!alignment.shrink());
TS_ASSERT(!alignment.wrap()); TS_ASSERT(!alignment.wrap());
} }

View File

@ -32,11 +32,11 @@ public:
fill = fill.pattern_fill().foreground(xlnt::color::black()); fill = fill.pattern_fill().foreground(xlnt::color::black());
TS_ASSERT(fill.pattern_fill().foreground()); TS_ASSERT(fill.pattern_fill().foreground());
TS_ASSERT_EQUALS((*fill.pattern_fill().foreground()).rgb().hex_string(), xlnt::color::black().rgb().hex_string()); TS_ASSERT_EQUALS(fill.pattern_fill().foreground().get().rgb().hex_string(), xlnt::color::black().rgb().hex_string());
fill = fill.pattern_fill().background(xlnt::color::green()); fill = fill.pattern_fill().background(xlnt::color::green());
TS_ASSERT(fill.pattern_fill().background()); TS_ASSERT(fill.pattern_fill().background());
TS_ASSERT_EQUALS((*fill.pattern_fill().background()).rgb().hex_string(), xlnt::color::green().rgb().hex_string()); TS_ASSERT_EQUALS(fill.pattern_fill().background().get().rgb().hex_string(), xlnt::color::green().rgb().hex_string());
const auto &const_fill = fill; const auto &const_fill = fill;
TS_ASSERT(const_fill.pattern_fill().foreground()); TS_ASSERT(const_fill.pattern_fill().foreground());

View File

@ -286,7 +286,7 @@ workbook::workbook(detail::workbook_impl *impl)
{ {
if (d_->stylesheet_.is_set()) if (d_->stylesheet_.is_set())
{ {
d_->stylesheet_->parent = this; d_->stylesheet_.get().parent = this;
} }
} }
} }
@ -903,7 +903,7 @@ void swap(workbook &left, workbook &right)
if (left.d_->stylesheet_.is_set()) if (left.d_->stylesheet_.is_set())
{ {
left.d_->stylesheet_->parent = &left; left.d_->stylesheet_.get().parent = &left;
} }
} }
@ -916,7 +916,7 @@ void swap(workbook &left, workbook &right)
if (right.d_->stylesheet_.is_set()) if (right.d_->stylesheet_.is_set())
{ {
right.d_->stylesheet_->parent = &right; right.d_->stylesheet_.get().parent = &right;
} }
} }
} }
@ -924,7 +924,7 @@ void swap(workbook &left, workbook &right)
workbook &workbook::operator=(workbook other) workbook &workbook::operator=(workbook other)
{ {
swap(*this, other); swap(*this, other);
d_->stylesheet_->parent = this; d_->stylesheet_.get().parent = this;
return *this; return *this;
} }
@ -945,7 +945,7 @@ workbook::workbook(const workbook &other)
ws.parent(*this); ws.parent(*this);
} }
d_->stylesheet_->parent = this; d_->stylesheet_.get().parent = this;
} }
workbook::~workbook() workbook::~workbook()
@ -986,12 +986,12 @@ std::vector<named_range> workbook::named_ranges() const
format workbook::create_format(bool default_format) format workbook::create_format(bool default_format)
{ {
register_stylesheet_in_manifest(); register_stylesheet_in_manifest();
return d_->stylesheet_->create_format(default_format); return d_->stylesheet_.get().create_format(default_format);
} }
bool workbook::has_style(const std::string &name) const bool workbook::has_style(const std::string &name) const
{ {
return d_->stylesheet_->has_style(name); return d_->stylesheet_.get().has_style(name);
} }
void workbook::clear_styles() void workbook::clear_styles()
@ -1023,12 +1023,12 @@ void workbook::apply_to_cells(std::function<void(cell)> f)
format workbook::format(std::size_t format_index) format workbook::format(std::size_t format_index)
{ {
return d_->stylesheet_->format(format_index); return d_->stylesheet_.get().format(format_index);
} }
const format workbook::format(std::size_t format_index) const const format workbook::format(std::size_t format_index) const
{ {
return d_->stylesheet_->format(format_index); return d_->stylesheet_.get().format(format_index);
} }
manifest &workbook::manifest() manifest &workbook::manifest()
@ -1099,17 +1099,17 @@ const std::vector<std::uint8_t> &workbook::thumbnail() const
style workbook::create_style(const std::string &name) style workbook::create_style(const std::string &name)
{ {
return d_->stylesheet_->create_style(name); return d_->stylesheet_.get().create_style(name);
} }
style workbook::style(const std::string &name) style workbook::style(const std::string &name)
{ {
return d_->stylesheet_->style(name); return d_->stylesheet_.get().style(name);
} }
const style workbook::style(const std::string &name) const const style workbook::style(const std::string &name) const
{ {
return d_->stylesheet_->style(name); return d_->stylesheet_.get().style(name);
} }
calendar workbook::base_date() const calendar workbook::base_date() const