Skip to content

Commit

Permalink
Preserve column order in FormattedTable
Browse files Browse the repository at this point in the history
(closes idaholab#8974)
  • Loading branch information
aeslaughter committed Apr 20, 2017
1 parent 179c2ed commit 4011e41
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 25 deletions.
18 changes: 9 additions & 9 deletions framework/include/utils/FormattedTable.h
Expand Up @@ -115,24 +115,24 @@ class FormattedTable
void printTablePiece(std::ostream & out,
unsigned int last_n_entries,
std::map<std::string, unsigned short> & col_widths,
std::set<std::string>::iterator & col_begin,
std::set<std::string>::iterator & col_end);
std::vector<std::string>::iterator & col_begin,
std::vector<std::string>::iterator & col_end);

void printOmittedRow(std::ostream & out,
std::map<std::string, unsigned short> & col_widths,
std::set<std::string>::iterator & col_begin,
std::set<std::string>::iterator & col_end) const;
std::vector<std::string>::iterator & col_begin,
std::vector<std::string>::iterator & col_end) const;
void printRowDivider(std::ostream & out,
std::map<std::string, unsigned short> & col_widths,
std::set<std::string>::iterator & col_begin,
std::set<std::string>::iterator & col_end) const;
std::vector<std::string>::iterator & col_begin,
std::vector<std::string>::iterator & col_end) const;

void printNoDataRow(char intersect_char,
char fill_char,
std::ostream & out,
std::map<std::string, unsigned short> & col_widths,
std::set<std::string>::iterator & col_begin,
std::set<std::string>::iterator & col_end) const;
std::vector<std::string>::iterator & col_begin,
std::vector<std::string>::iterator & col_end) const;

/**
* Returns the width of the terminal using sys/ioctl
Expand All @@ -147,7 +147,7 @@ class FormattedTable
std::map<Real, std::map<std::string, Real>> _data;

/// The set of column names updated when data is inserted through the setter methods
std::set<std::string> _column_names;
std::vector<std::string> _column_names;

/// The single cell width used for all columns in the table
static const unsigned short _column_width;
Expand Down
Expand Up @@ -98,6 +98,10 @@ class VectorPostprocessorData : public Restartable

std::set<std::string> _requested_items;
std::set<std::string> _supplied_items;

/// Lambda for looking at names in the std::pair of _values
// std::function< auto _compare_lambda = [&name](const std::pair<std::string,
// VectorPostprocessorState> & pair){ return pair.first == name; };
};

#endif // VECTORPOSTPROCESSORDATA_H
31 changes: 16 additions & 15 deletions framework/src/utils/FormattedTable.C
Expand Up @@ -112,7 +112,8 @@ void
FormattedTable::addData(const std::string & name, Real value, Real time)
{
_data[time][name] = value;
_column_names.insert(name);
if (std::find(_column_names.begin(), _column_names.end(), name) == _column_names.end())
_column_names.push_back(name);
_last_key = time;
}

Expand All @@ -131,17 +132,17 @@ FormattedTable::getLastData(const std::string & name)
void
FormattedTable::printOmittedRow(std::ostream & out,
std::map<std::string, unsigned short> & col_widths,
std::set<std::string>::iterator & col_begin,
std::set<std::string>::iterator & col_end) const
std::vector<std::string>::iterator & col_begin,
std::vector<std::string>::iterator & col_end) const
{
printNoDataRow(':', ' ', out, col_widths, col_begin, col_end);
}

void
FormattedTable::printRowDivider(std::ostream & out,
std::map<std::string, unsigned short> & col_widths,
std::set<std::string>::iterator & col_begin,
std::set<std::string>::iterator & col_end) const
std::vector<std::string>::iterator & col_begin,
std::vector<std::string>::iterator & col_end) const
{
printNoDataRow('+', '-', out, col_widths, col_begin, col_end);
}
Expand All @@ -151,12 +152,12 @@ FormattedTable::printNoDataRow(char intersect_char,
char fill_char,
std::ostream & out,
std::map<std::string, unsigned short> & col_widths,
std::set<std::string>::iterator & col_begin,
std::set<std::string>::iterator & col_end) const
std::vector<std::string>::iterator & col_begin,
std::vector<std::string>::iterator & col_end) const
{
out.fill(fill_char);
out << std::right << intersect_char << std::setw(_column_width + 2) << intersect_char;
for (std::set<std::string>::iterator header = col_begin; header != col_end; ++header)
for (std::vector<std::string>::iterator header = col_begin; header != col_end; ++header)
out << std::setw(col_widths[*header] + 2) << intersect_char;
out << "\n";

Expand Down Expand Up @@ -194,11 +195,11 @@ FormattedTable::printTable(std::ostream & out,
if (term_width < _min_pps_width)
term_width = _min_pps_width;

std::set<std::string>::iterator col_it = _column_names.begin();
std::set<std::string>::iterator col_end = _column_names.end();
std::vector<std::string>::iterator col_it = _column_names.begin();
std::vector<std::string>::iterator col_end = _column_names.end();

std::set<std::string>::iterator curr_begin = col_it;
std::set<std::string>::iterator curr_end;
std::vector<std::string>::iterator curr_begin = col_it;
std::vector<std::string>::iterator curr_end;
while (col_it != col_end)
{
std::map<std::string, unsigned short> col_widths;
Expand Down Expand Up @@ -231,11 +232,11 @@ void
FormattedTable::printTablePiece(std::ostream & out,
unsigned int last_n_entries,
std::map<std::string, unsigned short> & col_widths,
std::set<std::string>::iterator & col_begin,
std::set<std::string>::iterator & col_end)
std::vector<std::string>::iterator & col_begin,
std::vector<std::string>::iterator & col_end)
{
std::map<Real, std::map<std::string, Real>>::iterator i;
std::set<std::string>::iterator header;
std::vector<std::string>::iterator header;

/**
* Print out the header row
Expand Down
2 changes: 1 addition & 1 deletion test/tests/vectorpostprocessors/line_value_sampler/tests
Expand Up @@ -18,6 +18,6 @@
type = 'CheckFiles'
input = 'csv_delimiter.i'
check_files = 'csv_delimiter_csv_line_sample_0001.csv'
file_expect_out = 'id u v x y z\n0 0 1\.2346 0 0\.5 0\n0\.1 0\.1 1\.2346 0\.1 0\.5 0\n0\.2 0.2 1\.2346 0\.2 0.5 0'
file_expect_out = "x y z id u v\n0 0.5 0 0 0 1.2346\n0.1 0.5 0 0.1 0.1 1.2346"
[../]
[]

0 comments on commit 4011e41

Please sign in to comment.