[04cc7e] | 1 | /*
|
---|
| 2 | * writeDistanceEnergyTable.hpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Nov 20, 2012
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #ifndef WRITEDISTANCEENERGYTABLE_HPP_
|
---|
| 9 | #define WRITEDISTANCEENERGYTABLE_HPP_
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | // include config.h
|
---|
| 13 | #ifdef HAVE_CONFIG_H
|
---|
| 14 | #include <config.h>
|
---|
| 15 | #endif
|
---|
| 16 |
|
---|
| 17 | #include <vector>
|
---|
| 18 | #include <sstream>
|
---|
| 19 | #include <string>
|
---|
| 20 |
|
---|
| 21 | namespace _detail {
|
---|
| 22 |
|
---|
| 23 | typedef std::vector<double> values_t;
|
---|
| 24 | typedef std::vector< values_t > DistanceEnergyTable_t;
|
---|
| 25 |
|
---|
| 26 | /** Gets the number of column entries, i.e. number of rows.
|
---|
| 27 | *
|
---|
| 28 | * \note ASSERT's that all columns have equal number of entries
|
---|
| 29 | *
|
---|
| 30 | * @param table table to check
|
---|
| 31 | * @return number of column entries
|
---|
| 32 | */
|
---|
| 33 | const size_t checkNumberOfColumnEntries(const DistanceEnergyTable_t &table)
|
---|
| 34 | {
|
---|
| 35 | size_t index = table[0].size();
|
---|
| 36 | for (DistanceEnergyTable_t::const_iterator coliter = table.begin();
|
---|
| 37 | coliter != table.end(); ++coliter)
|
---|
| 38 | ASSERT( (*coliter).size() == index,
|
---|
| 39 | "writeDistanceEnergyTable() - mismatch in column sizes.");
|
---|
| 40 | return index;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | /** Pretty prints the given distance-energy table.
|
---|
| 44 | *
|
---|
| 45 | * @param table table to print
|
---|
| 46 | * @return string containing pretty-printed table
|
---|
| 47 | */
|
---|
| 48 | const std::string writeDistanceEnergyTable(const DistanceEnergyTable_t &table)
|
---|
| 49 | {
|
---|
| 50 | std::stringstream returnstream;
|
---|
| 51 |
|
---|
| 52 | if (table.size() > 0) {
|
---|
| 53 | /// check each column for equal number of entries
|
---|
| 54 | const size_t indices = checkNumberOfColumnEntries(table);
|
---|
| 55 |
|
---|
| 56 | /// print header line
|
---|
| 57 | for (size_t index = 0; index < indices-1; ++index)
|
---|
| 58 | returnstream << "distance" << index+1 << "\t";
|
---|
| 59 | returnstream << "energy" << std::endl;
|
---|
| 60 |
|
---|
| 61 | /// print each row
|
---|
| 62 | for (DistanceEnergyTable_t::const_iterator coliter = table.begin();
|
---|
| 63 | coliter != table.end(); ++coliter) {
|
---|
| 64 | for (DistanceEnergyTable_t::value_type::const_iterator rowiter = (*coliter).begin();
|
---|
| 65 | rowiter != (*coliter).end(); ++rowiter) {
|
---|
| 66 | returnstream << (*rowiter) << "\t";
|
---|
| 67 | }
|
---|
| 68 | returnstream << std::endl;
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | return returnstream.str();
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | }; /* namespace _detail */
|
---|
| 76 |
|
---|
| 77 | #endif /* WRITEDISTANCEENERGYTABLE_HPP_ */
|
---|