From e152ecbdf050a1f66e5b05256e9bbe0e7cd7ced3 Mon Sep 17 00:00:00 2001 From: Mariana Meireles Date: Wed, 22 Apr 2020 09:02:31 +0200 Subject: [PATCH] Make tabulate compatible with mac's SDK 10.9 --- include/tabulate/cell.hpp | 2 +- include/tabulate/column.hpp | 6 +-- include/tabulate/format.hpp | 14 ++--- include/tabulate/printer.hpp | 24 ++++----- include/tabulate/row.hpp | 10 ++-- include/tabulate/table.hpp | 4 +- include/tabulate/table_internal.hpp | 82 ++++++++++++++--------------- 7 files changed, 71 insertions(+), 71 deletions(-) diff --git a/include/tabulate/cell.hpp b/include/tabulate/cell.hpp index d14316b..b8c9453 100644 --- a/include/tabulate/cell.hpp +++ b/include/tabulate/cell.hpp @@ -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(); diff --git a/include/tabulate/column.hpp b/include/tabulate/column.hpp index a247a85..fbe43e0 100644 --- a/include/tabulate/column.hpp +++ b/include/tabulate/column.hpp @@ -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; } @@ -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(); @@ -148,7 +148,7 @@ class Column { } if (format.padding_right_.has_value()) - result += format.padding_right_.value(); + result += *format.padding_right_; return result; } diff --git a/include/tabulate/format.hpp b/include/tabulate/format.hpp index 3139734..733443b 100644 --- a/include/tabulate/format.hpp +++ b/include/tabulate/format.hpp @@ -331,7 +331,7 @@ class Format { Format &font_style(const std::vector &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; } @@ -458,15 +458,15 @@ class Format { if (first.font_style_.has_value()) { // Merge font styles using std::set_union - std::vector merged_font_style(first.font_style_.value().size() + - second.font_style_.value().size()); + std::vector 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 diff --git a/include/tabulate/printer.hpp b/include/tabulate/printer.hpp index 15717b2..9aa77d7 100644 --- a/include/tabulate/printer.hpp +++ b/include/tabulate/printer.hpp @@ -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) { @@ -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) @@ -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) @@ -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_, {}); } diff --git a/include/tabulate/row.hpp b/include/tabulate/row.hpp index fea00f4..96e4a34 100644 --- a/include/tabulate/row.hpp +++ b/include/tabulate/row.hpp @@ -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; } @@ -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); @@ -167,7 +167,7 @@ class Row { result += estimated_row_height; - result += format.padding_bottom_.value(); + result += *format.padding_bottom_; return result; } diff --git a/include/tabulate/table.hpp b/include/tabulate/table.hpp index 569327f..de2c31a 100644 --- a/include/tabulate/table.hpp +++ b/include/tabulate/table.hpp @@ -60,9 +60,9 @@ class Table { for (size_t i = 0; i < cells.size(); ++i) { auto cell = cells[i]; if (std::holds_alternative(cell)) { - cell_strings[i] = std::get(cell); + cell_strings[i] = *std::get_if(&cell); } else { - auto table = std::get(cell); + auto table = *std::get_if
(&cell); std::stringstream stream; table.print(stream); cell_strings[i] = stream.str(); diff --git a/include/tabulate/table_internal.hpp b/include/tabulate/table_internal.hpp index 63b2aba..c96b435 100644 --- a/include/tabulate/table_internal.hpp +++ b/include/tabulate/table_internal.hpp @@ -114,13 +114,13 @@ 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_; } bool Cell::is_multi_byte_character_support_enabled() { - return format().multi_byte_characters_.value(); + return (*format().multi_byte_characters_); } Format &Row::format() { @@ -130,9 +130,9 @@ 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_; } std::pair, std::vector> @@ -216,8 +216,8 @@ void Printer::print_table(std::ostream &stream, TableInternal &table) { auto cell = table[i][j]; auto format = cell.format(); auto column_width = column_widths[j]; - 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; @@ -252,17 +252,17 @@ void Printer::print_row_in_cell(std::ostream &stream, TableInternal &table, 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_bottom = format.padding_bottom_.value(); + auto padding_top = *format.padding_top_; + auto padding_bottom = *format.padding_bottom_; - 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 @@ -273,8 +273,8 @@ void Printer::print_row_in_cell(std::ostream &stream, TableInternal &table, // 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(), @@ -316,7 +316,7 @@ void Printer::print_row_in_cell(std::ostream &stream, TableInternal &table, 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; @@ -342,10 +342,10 @@ void Printer::print_row_in_cell(std::ostream &stream, TableInternal &table, 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); } } @@ -361,12 +361,12 @@ bool Printer::print_cell_border_top(std::ostream &stream, TableInternal &table, 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, {}); @@ -374,17 +374,17 @@ bool Printer::print_cell_border_top(std::ostream &stream, TableInternal &table, 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; @@ -403,12 +403,12 @@ bool Printer::print_cell_border_bottom(std::ostream &stream, TableInternal &tabl 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, {}); @@ -416,17 +416,17 @@ bool Printer::print_cell_border_bottom(std::ostream &stream, TableInternal &tabl 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;