const unsigned int nrows = n_rows();
const unsigned int n_cols = sel_columns.size();
- // handle the simple format separately first
- if (format==simple_table_with_separate_column_description)
+ // cache the columns and compute the widths of each column for alignment
+ std::vector<const Column *> cols;
+ std::vector<unsigned int> column_widths (n_cols, 0);
+ for (unsigned int j=0; j<n_cols; ++j)
+ {
+ std::string key=sel_columns[j];
+ const std::map<std::string, Column>::const_iterator
+ col_iter=columns.find(key);
+ Assert(col_iter!=columns.end(), ExcInternalError());
+ cols.push_back(&(col_iter->second));
+
+ column_widths[j] = col_iter->second.max_length;
+ }
+
+ switch (format)
+ {
+ case org_mode_table:
{
// write the captions
+ out << "| " << std::left;
for (unsigned int j=0; j<n_cols; ++j)
{
const std::string &key = sel_columns[j];
- out << "# " << j+1 << ": " << key << '\n';
+ out << std::setw(column_widths[j]);
+ out << key << " | ";
+ }
+ out << std::endl;
+
+ // write the body
+ for (unsigned int i=0; i<nrows; ++i)
+ {
+ out << "| ";
+ for (unsigned int j=0; j<n_cols; ++j)
+ {
+ const Column &column=*(cols[j]);
+
+ out << std::setw(column_widths[j]);
+ out << column.entries[i].get_cached_string();
+ out << " | ";
+ }
+ out << '\n';
}
- // cache the columns
- std::vector<const Column *> cols;
+ out << std::flush;
+ return;
+ }
+
+ case simple_table_with_separate_column_description:
+ {
+ // write the captions
for (unsigned int j=0; j<n_cols; ++j)
{
- std::string key=sel_columns[j];
- const std::map<std::string, Column>::const_iterator
- col_iter=columns.find(key);
- Assert(col_iter!=columns.end(), ExcInternalError());
- cols.push_back(&(col_iter->second));
+ const std::string &key = sel_columns[j];
+ out << "# " << j+1 << ": " << key << '\n';
}
// write the body
out << std::flush;
return;
}
-
- // cache the columns and compute the widths of each column for alignment
- std::vector<const Column *> cols;
- std::vector<unsigned int> column_widths (n_cols, 0);
- for (unsigned int j=0; j<n_cols; ++j)
- {
- std::string key=sel_columns[j];
- const std::map<std::string, Column>::const_iterator
- col_iter=columns.find(key);
- Assert(col_iter!=columns.end(), ExcInternalError());
- cols.push_back(&(col_iter->second));
-
- column_widths[j] = col_iter->second.max_length;
- }
-
- // writing the captions for table_with_separate_column_description
- // means that we ignore supercolumns and output the column
- // header for each column. enumerate columns starting with 1
- if (format == table_with_separate_column_description)
+
+ case table_with_separate_column_description:
{
+ // writing the captions for table_with_separate_column_description
+ // means that we ignore supercolumns and output the column
+ // header for each column. enumerate columns starting with 1
for (unsigned int j=0; j<n_cols; ++j)
{
std::string key=sel_columns[j];
out << "# " << j+1 << ": " << key << '\n';
}
+ break;
}
- else if (format == table_with_headers)
+
+ case table_with_headers:
{
// This format output supercolumn headers and aligns them centered
// over all the columns that belong to it.
out << ' ';
}
out << '\n';
+ break;
+ }
+
+ default:
+ Assert (false, ExcInternalError());
}
- else
- Assert (false, ExcInternalError());
-
- // finally output the data itself
+
+ // finally output the data itself for
+ // table_with_headers or table_with_separate_column_description:
for (unsigned int i=0; i<nrows; ++i)
{
for (unsigned int j=0; j<n_cols; ++j)
--- /dev/null
+// ---------------------------------------------------------------------
+// $Id$
+//
+// Copyright (C) 2010 - 2013 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+// use the org-mode in TableHandler::write_text
+
+
+#include "../tests.h"
+#include <deal.II/base/data_out_base.h>
+#include <deal.II/base/table_handler.h>
+#include <deal.II/base/logstream.h>
+
+#include <vector>
+#include <iomanip>
+#include <fstream>
+#include <string>
+
+
+int main ()
+{
+ std::ofstream logfile("table_handler_13/output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ TableHandler table;
+ table.set_auto_fill_mode (true);
+
+ std::string keys[3] = { "key1", "key2", "key3" };
+
+ // fill rows 1 and 2 partially
+ table.add_value(keys[0], 0);
+ table.add_value(keys[0], 1);
+ // now fill row 3 completely
+ table.add_value(keys[0], 2);
+ table.add_value(keys[1], 113);
+ table.add_value(keys[2], std::string("a"));
+
+ // now again fill row 4 partially
+ table.add_value(keys[0], 1);
+
+ // produce output. hope that row 4 is
+ // completely padded
+ table.write_text(deallog.get_file_stream(),
+ TableHandler::org_mode_table);
+}