Skip to content

Commit

Permalink
Only sort the names if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
aeslaughter committed Apr 24, 2017
1 parent 4f68362 commit 2c1d17a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion framework/include/utils/FormattedTable.h
Expand Up @@ -114,7 +114,7 @@ class FormattedTable
/**
* Sorts columns alphabetically.
*/
void sortColumns() { std::sort(_column_names.begin(), _column_names.end()); }
void sortColumns();

protected:
void printTablePiece(std::ostream & out,
Expand Down Expand Up @@ -185,6 +185,9 @@ class FormattedTable
/// *.csv file precision, defaults to 14
unsigned int _csv_precision;

/// Flag indicating that sorting is necessary (used by sortColumns method).
bool _column_names_unsorted = true;

friend void
dataStore<FormattedTable>(std::ostream & stream, FormattedTable & table, void * context);
friend void dataLoad<FormattedTable>(std::istream & stream, FormattedTable & v, void * context);
Expand Down
14 changes: 13 additions & 1 deletion framework/src/utils/FormattedTable.C
Expand Up @@ -91,7 +91,8 @@ FormattedTable::FormattedTable(const FormattedTable & o)
_last_key(o._last_key),
_output_time(o._output_time),
_csv_delimiter(","),
_csv_precision(14)
_csv_precision(14),
_column_names_unsorted(o._column_names_unsorted)
{
if (_stream_open)
mooseError("Copying a FormattedTable with an open stream is not supported");
Expand All @@ -115,6 +116,7 @@ FormattedTable::addData(const std::string & name, Real value, Real time)
if (std::find(_column_names.begin(), _column_names.end(), name) == _column_names.end())
_column_names.push_back(name);
_last_key = time;
_column_names_unsorted = true;
}

Real &
Expand Down Expand Up @@ -540,3 +542,13 @@ FormattedTable::getWidthModes()
{
return MooseEnum("ENVIRONMENT=-1 AUTO=0 80=80 120=120 160=160", "ENVIRONMENT", true);
}

void
FormattedTable::sortColumns()
{
if (_column_names_unsorted)
{
std::sort(_column_names.begin(), _column_names.end());
_column_names_unsorted = false;
}
}

0 comments on commit 2c1d17a

Please sign in to comment.