From: Fahad Alrashed Date: Sat, 14 Mar 2015 04:39:14 +0000 (+0300) Subject: Added clear_current_row() to TableHandler in case the current time step is rejected. X-Git-Tag: v8.3.0-rc1~368^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F664%2Fhead;p=dealii.git Added clear_current_row() to TableHandler in case the current time step is rejected. --- 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 | "" |