From e57b03b23e1aa44703988998a58113aae52c082a Mon Sep 17 00:00:00 2001 From: Fahad Alrashed Date: Sat, 14 Mar 2015 07:39:14 +0300 Subject: [PATCH] Added clear_current_row() to TableHandler in case the current time step is rejected. --- include/deal.II/base/table_handler.h | 13 ++++++++++--- source/base/table_handler.cc | 16 ++++++++++++++++ tests/base/table_handler_13.cc | 11 +++++++++++ tests/base/table_handler_13.output | 12 ++++++++---- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/include/deal.II/base/table_handler.h b/include/deal.II/base/table_handler.h index a597068393..02c86f98fb 100644 --- a/include/deal.II/base/table_handler.h +++ b/include/deal.II/base/table_handler.h @@ -461,9 +461,16 @@ public: void clear (); /** - * Read or write the data of this object to or from a stream for the purpose - * of serialization. - */ + * Remove all values added at the current row. This is useful when, + * for example, a time-step is rejected and all data recorded about + * it needs to be discarded. + */ + void clear_current_row (); + + /** + * Read or write the data of this object to or from a stream for the purpose + * of serialization. + */ template void serialize(Archive &ar, const unsigned int version); diff --git a/source/base/table_handler.cc b/source/base/table_handler.cc index a3de0f38f4..fa49131bf0 100644 --- a/source/base/table_handler.cc +++ b/source/base/table_handler.cc @@ -730,4 +730,20 @@ void TableHandler::get_selected_columns(std::vector &sel_columns) c } +void TableHandler::clear_current_row () +{ + // Figure out what is the currect (max) length of the columns + // so that we "shave" one off. + unsigned long n = 0; + for (std::map< std::string, Column >::iterator p = columns.begin(); p != columns.end(); ++p) + n = std::max(n, p->second.entries.size()); + + // shave the top most element + if (n != 0) + for (std::map< std::string, Column >::iterator p = columns.begin(); p != columns.end(); ++p) + if (p->second.entries.size() == n) + p->second.entries.pop_back(); +} + + DEAL_II_NAMESPACE_CLOSE diff --git a/tests/base/table_handler_13.cc b/tests/base/table_handler_13.cc index 591c1f1c3a..db379420b8 100644 --- a/tests/base/table_handler_13.cc +++ b/tests/base/table_handler_13.cc @@ -51,8 +51,19 @@ int main () // now again fill row 4 partially table.add_value(keys[0], 1); + // now clear the partial row above + table.clear_current_row(); + // produce output. hope that row 4 is // completely padded table.write_text(deallog.get_file_stream(), TableHandler::org_mode_table); + + // now again fill row 4 partially + table.add_value(keys[0], 1); + + // produce output. hope that we get 3 rows + table.write_text(deallog.get_file_stream(), + TableHandler::org_mode_table); + } diff --git a/tests/base/table_handler_13.output b/tests/base/table_handler_13.output index 22555388a3..69b4eb580f 100644 --- a/tests/base/table_handler_13.output +++ b/tests/base/table_handler_13.output @@ -1,6 +1,10 @@ | key1 | key2 | key3 | -| 0 | 0 | "" | -| 1 | 0 | "" | -| 2 | 113 | a | -| 1 | 0 | "" | +| 0 | 0 | "" | +| 1 | 0 | "" | +| 2 | 113 | a | +| key1 | key2 | key3 | +| 0 | 0 | "" | +| 1 | 0 | "" | +| 2 | 113 | a | +| 1 | 0 | "" | -- 2.39.5