Skip to content

Commit

Permalink
Merge pull request #41 from marimeireles/Fix-10.9
Browse files Browse the repository at this point in the history
Make tabulate compatible with mac's SDK 10.9
  • Loading branch information
p-ranav committed Apr 22, 2020
2 parents ff9dc4c + ce77eb9 commit 4fa3c66
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 70 deletions.
2 changes: 1 addition & 1 deletion include/tabulate/cell.hpp
Expand Up @@ -53,7 +53,7 @@ class Cell {
return get_sequence_length(data_, locale(), is_multi_byte_character_support_enabled());
}

std::string locale() { return format().locale_.value(); }
std::string locale() { return *format().locale_; }

Format &format();

Expand Down
6 changes: 3 additions & 3 deletions include/tabulate/column.hpp
Expand Up @@ -96,7 +96,7 @@ class Column {
auto cell = cells_[i];
auto format = cell.get().format();
if (format.width_.has_value())
result = std::max(result, format.width_.value());
result = std::max(result, *format.width_);
}
return result;
}
Expand Down Expand Up @@ -124,7 +124,7 @@ class Column {
Cell &cell = cells_[cell_index].get();
auto format = cell.format();
if (format.padding_left_.has_value())
result += format.padding_left_.value();
result += *format.padding_left_;

// Check if input text has newlines
auto text = cell.get_text();
Expand All @@ -148,7 +148,7 @@ class Column {
}

if (format.padding_right_.has_value())
result += format.padding_right_.value();
result += *format.padding_right_;

return result;
}
Expand Down
14 changes: 7 additions & 7 deletions include/tabulate/format.hpp
Expand Up @@ -332,7 +332,7 @@ class Format {
Format &font_style(const std::vector<FontStyle> &style) {
if (font_style_.has_value()) {
for (auto &s : style)
font_style_.value().push_back(s);
font_style_->push_back(s);
} else {
font_style_ = style;
}
Expand Down Expand Up @@ -459,15 +459,15 @@ class Format {

if (first.font_style_.has_value()) {
// Merge font styles using std::set_union
std::vector<FontStyle> merged_font_style(first.font_style_.value().size() +
second.font_style_.value().size());
std::vector<FontStyle> merged_font_style(first.font_style_->size() +
second.font_style_->size());
#if defined(_WIN32) || defined(_WIN64)
// Fixes error in Windows - Sequence not ordered
std::sort(first.font_style_.value().begin(), first.font_style_.value().end());
std::sort(second.font_style_.value().begin(), second.font_style_.value().end());
std::sort(first.font_style_->begin(), first.font_style_->end());
std::sort(second.font_style_->begin(), second.font_style_->end());
#endif
std::set_union(first.font_style_.value().begin(), first.font_style_.value().end(),
second.font_style_.value().begin(), second.font_style_.value().end(),
std::set_union(first.font_style_->begin(), first.font_style_->end(),
second.font_style_->begin(), second.font_style_->end(),
merged_font_style.begin());
result.font_style_ = merged_font_style;
} else
Expand Down
24 changes: 12 additions & 12 deletions include/tabulate/printer.hpp
Expand Up @@ -75,13 +75,13 @@ class Printer {
size_t column_width) {

// Apply font style
apply_element_style(stream, format.font_color_.value(), format.font_background_color_.value(),
format.font_style_.value());
apply_element_style(stream, *format.font_color_, *format.font_background_color_,
*format.font_style_);
stream << cell_content;
// Only apply font_style to the font
// Not the padding. So calling apply_element_style with font_style = {}
reset_element_style(stream);
apply_element_style(stream, format.font_color_.value(), format.font_background_color_.value(),
apply_element_style(stream, *format.font_color_, *format.font_background_color_,
{});

if (text_with_padding_size < column_width) {
Expand All @@ -101,13 +101,13 @@ class Printer {
stream << " ";

// Apply font style
apply_element_style(stream, format.font_color_.value(), format.font_background_color_.value(),
format.font_style_.value());
apply_element_style(stream, *format.font_color_, *format.font_background_color_,
*format.font_style_);
stream << cell_content;
// Only apply font_style to the font
// Not the padding. So calling apply_element_style with font_style = {}
reset_element_style(stream);
apply_element_style(stream, format.font_color_.value(), format.font_background_color_.value(),
apply_element_style(stream, *format.font_color_, *format.font_background_color_,
{});

for (size_t j = 0; j < num_spaces / 2; ++j)
Expand All @@ -118,13 +118,13 @@ class Printer {
stream << " ";

// Apply font style
apply_element_style(stream, format.font_color_.value(), format.font_background_color_.value(),
format.font_style_.value());
apply_element_style(stream, *format.font_color_, *format.font_background_color_,
*format.font_style_);
stream << cell_content;
// Only apply font_style to the font
// Not the padding. So calling apply_element_style with font_style = {}
reset_element_style(stream);
apply_element_style(stream, format.font_color_.value(), format.font_background_color_.value(),
apply_element_style(stream, *format.font_color_, *format.font_background_color_,
{});

for (size_t j = 0; j < num_spaces - num_spaces_before; ++j)
Expand All @@ -142,13 +142,13 @@ class Printer {
}

// Apply font style
apply_element_style(stream, format.font_color_.value(), format.font_background_color_.value(),
format.font_style_.value());
apply_element_style(stream, *format.font_color_, *format.font_background_color_,
*format.font_style_);
stream << cell_content;
// Only apply font_style to the font
// Not the padding. So calling apply_element_style with font_style = {}
reset_element_style(stream);
apply_element_style(stream, format.font_color_.value(), format.font_background_color_.value(),
apply_element_style(stream, *format.font_color_, *format.font_background_color_,
{});
}

Expand Down
10 changes: 5 additions & 5 deletions include/tabulate/row.hpp
Expand Up @@ -94,7 +94,7 @@ class Row {
auto cell = cells_[i];
auto format = cell->format();
if (format.height_.has_value())
result = std::max(result, format.height_.value());
result = std::max(result, *format.height_);
}
return result;
}
Expand Down Expand Up @@ -136,10 +136,10 @@ class Row {
auto format = cell.format();
auto text = cell.get_text();

auto padding_left = format.padding_left_.value();
auto padding_right = format.padding_right_.value();
auto padding_left = *format.padding_left_;
auto padding_right = *format.padding_right_;

result += format.padding_top_.value();
result += *format.padding_top_;

if (column_width > (padding_left + padding_right)) {
column_width -= (padding_left + padding_right);
Expand Down Expand Up @@ -169,7 +169,7 @@ class Row {

result += estimated_row_height;

result += format.padding_bottom_.value();
result += *format.padding_bottom_;

return result;
}
Expand Down
4 changes: 2 additions & 2 deletions include/tabulate/table.hpp
Expand Up @@ -61,9 +61,9 @@ class Table {
for (size_t i = 0; i < cells.size(); ++i) {
auto cell = cells[i];
if (std::holds_alternative<std::string>(cell)) {
cell_strings[i] = std::get<std::string>(cell);
cell_strings[i] = *std::get_if<std::string>(&cell);
} else {
auto table = std::get<Table>(cell);
auto table = *std::get_if<Table>(&cell);
std::stringstream stream;
table.print(stream);
cell_strings[i] = stream.str();
Expand Down
80 changes: 40 additions & 40 deletions include/tabulate/table_internal.hpp
Expand Up @@ -127,13 +127,13 @@ inline Format &Cell::format() {
} else {
// Cell has formatting
// Merge cell formatting with parent row formatting
format_ = Format::merge(format_.value(), parent->format());
format_ = Format::merge(*format_, parent->format());
}
return format_.value();
return *format_;
}

inline bool Cell::is_multi_byte_character_support_enabled() {
return format().multi_byte_characters_.value();
return (*format().multi_byte_characters_);
}

inline Format &Row::format() {
Expand All @@ -143,9 +143,9 @@ inline Format &Row::format() {
} else {
// Row has formatting rules
// Merge with parent table format
format_ = Format::merge(format_.value(), parent->format());
format_ = Format::merge(*format_, parent->format());
}
return format_.value();
return *format_;
}

inline std::pair<std::vector<size_t>, std::vector<size_t>>
Expand Down Expand Up @@ -228,8 +228,8 @@ inline void Printer::print_table(std::ostream &stream, TableInternal &table) {
for (size_t j = 0; j < num_columns; ++j) {
auto cell = table[i][j];
auto format = cell.format();
auto corner = format.corner_bottom_left_.value();
auto border_bottom = format.border_bottom_.value();
auto corner = *format.corner_bottom_left_;
auto border_bottom = *format.border_bottom_;
if (corner == "" && border_bottom == "") {
bottom_border_needed = false;
break;
Expand Down Expand Up @@ -263,16 +263,16 @@ inline void Printer::print_row_in_cell(std::ostream &stream, TableInternal &tabl
auto word_wrapped_text =
Format::word_wrap(text, column_width, locale, is_multi_byte_character_support_enabled);
auto text_height = std::count(word_wrapped_text.begin(), word_wrapped_text.end(), '\n') + 1;
auto padding_top = format.padding_top_.value();
auto padding_top = *format.padding_top_;

if (format.show_border_left_.value()) {
apply_element_style(stream, format.border_left_color_.value(),
format.border_left_background_color_.value(), {});
stream << format.border_left_.value();
if (*format.show_border_left_) {
apply_element_style(stream, *format.border_left_color_,
*format.border_left_background_color_, {});
stream << *format.border_left_;
reset_element_style(stream);
}

apply_element_style(stream, format.font_color_.value(), format.font_background_color_.value(),
apply_element_style(stream, *format.font_color_, *format.font_background_color_,
{});
if (row_index < padding_top) {
// Padding top
Expand All @@ -283,8 +283,8 @@ inline void Printer::print_row_in_cell(std::ostream &stream, TableInternal &tabl
// Retrieve padding left and right
// (column_width - padding_left - padding_right) is the amount of space
// available for cell text - Use this to word wrap cell contents
auto padding_left = format.padding_left_.value();
auto padding_right = format.padding_right_.value();
auto padding_left = *format.padding_left_;
auto padding_right = *format.padding_right_;

// Check if input text has embedded \n that are to be respected
auto newlines_in_input = Format::split_lines(text, "\n", cell.locale(),
Expand Down Expand Up @@ -326,7 +326,7 @@ inline void Printer::print_row_in_cell(std::ostream &stream, TableInternal &tabl
auto line_with_padding_size =
get_sequence_length(line, cell.locale(), cell.is_multi_byte_character_support_enabled()) +
padding_left + padding_right;
switch (format.font_align_.value()) {
switch (*format.font_align_) {
case FontAlign::left:
print_content_left_aligned(stream, line, format, line_with_padding_size, column_width);
break;
Expand All @@ -352,10 +352,10 @@ inline void Printer::print_row_in_cell(std::ostream &stream, TableInternal &tabl

if (index.second + 1 == num_columns) {
// Print right border after last column
if (format.show_border_right_.value()) {
apply_element_style(stream, format.border_right_color_.value(),
format.border_right_background_color_.value(), {});
stream << format.border_right_.value();
if (*format.show_border_right_) {
apply_element_style(stream, *format.border_right_color_,
*format.border_right_background_color_, {});
stream << *format.border_right_;
reset_element_style(stream);
}
}
Expand All @@ -371,30 +371,30 @@ inline bool Printer::print_cell_border_top(std::ostream &stream, TableInternal &
auto format = cell.format();
auto column_width = dimension.second;

auto corner = format.corner_top_left_.value();
auto corner_color = format.corner_top_left_color_.value();
auto corner_background_color = format.corner_top_left_background_color_.value();
auto border_top = format.border_top_.value();
auto corner = *format.corner_top_left_;
auto corner_color = *format.corner_top_left_color_;
auto corner_background_color = *format.corner_top_left_background_color_;
auto border_top = *format.border_top_;

if ((corner == "" && border_top == "") || !format.show_border_top_.value())
if ((corner == "" && border_top == "") || !*format.show_border_top_)
return false;

apply_element_style(stream, corner_color, corner_background_color, {});
stream << corner;
reset_element_style(stream);

for (size_t i = 0; i < column_width; ++i) {
apply_element_style(stream, format.border_top_color_.value(),
format.border_top_background_color_.value(), {});
apply_element_style(stream, *format.border_top_color_,
*format.border_top_background_color_, {});
stream << border_top;
reset_element_style(stream);
}

if (index.second + 1 == num_columns) {
// Print corner after last column
corner = format.corner_top_right_.value();
corner_color = format.corner_top_right_color_.value();
corner_background_color = format.corner_top_right_background_color_.value();
corner = *format.corner_top_right_;
corner_color = *format.corner_top_right_color_;
corner_background_color = *format.corner_top_right_background_color_;

apply_element_style(stream, corner_color, corner_background_color, {});
stream << corner;
Expand All @@ -413,30 +413,30 @@ inline bool Printer::print_cell_border_bottom(std::ostream &stream, TableInterna
auto format = cell.format();
auto column_width = dimension.second;

auto corner = format.corner_bottom_left_.value();
auto corner_color = format.corner_bottom_left_color_.value();
auto corner_background_color = format.corner_bottom_left_background_color_.value();
auto border_bottom = format.border_bottom_.value();
auto corner = *format.corner_bottom_left_;
auto corner_color = *format.corner_bottom_left_color_;
auto corner_background_color = *format.corner_bottom_left_background_color_;
auto border_bottom = *format.border_bottom_;

if ((corner == "" && border_bottom == "") || !format.show_border_bottom_.value())
if ((corner == "" && border_bottom == "") || !*format.show_border_bottom_)
return false;

apply_element_style(stream, corner_color, corner_background_color, {});
stream << corner;
reset_element_style(stream);

for (size_t i = 0; i < column_width; ++i) {
apply_element_style(stream, format.border_bottom_color_.value(),
format.border_bottom_background_color_.value(), {});
apply_element_style(stream, *format.border_bottom_color_,
*format.border_bottom_background_color_, {});
stream << border_bottom;
reset_element_style(stream);
}

if (index.second + 1 == num_columns) {
// Print corner after last column
corner = format.corner_bottom_right_.value();
corner_color = format.corner_bottom_right_color_.value();
corner_background_color = format.corner_bottom_right_background_color_.value();
corner = *format.corner_bottom_right_;
corner_color = *format.corner_bottom_right_color_;
corner_background_color = *format.corner_bottom_right_background_color_;

apply_element_style(stream, corner_color, corner_background_color, {});
stream << corner;
Expand Down

0 comments on commit 4fa3c66

Please sign in to comment.