<h3>Specific improvements</h3>
<ol>
+<li> Fixed: In TableHandler::print_text, it can happen that the function
+wants to print an empty string as the element of the table to be printed.
+This can confuse machine readers of this table, for example for visualization,
+since they then do not see this column in that row. To prevent this, we now
+print <code>""</code> in such places.
+<br>
+(Wolfgang Bangerth, 2011/10/18)
+
<li> Fixed: Using Trilinos versions 10.4 and later on Debian failed to
configure due to a different naming scheme of Trilinos libraries on
Debian. This is now fixed.
const std::string &format="c");
/**
- * Write table as formatted text,
- * e.g. to the standard output.
+ * Write table as formatted text to the
+ * given stream. The text is formatted in
+ * such as way that it represents data as
+ * formatted columns of text. To avoid
+ * problems when reading these tables
+ * automatically, for example for
+ * postprocessing, if an entry in a cell
+ * of this table is empty (i.e. it has
+ * been created by calling the
+ * add_value() function with an empty
+ * string), then the entry of the table
+ * is printed as <code>""</code>.
*/
void write_text (std::ostream &out) const;
columns.insert(new_column);
column_order.push_back(key);
}
-
+
const internal::TableEntry entry = { value };
columns[key].entries.push_back (entry);
}
dummy_out << column.entries[i].value;
- // get size, note that we are
- // not interested in the
- // trailing \0
- entry_widths[i][j] = dummy_out.str().length();
+ // get size. as a side note, if the
+ // text printed is in fact the empty
+ // string, then we get into a bit of
+ // trouble since readers would skip
+ // over the resulting whitespaces. as
+ // a consequence, we'll print ""
+ // instead in that case.
+ const unsigned int size = dummy_out.str().length();
+ if (size > 0)
+ entry_widths[i][j] = size;
+ else
+ entry_widths[i][j] = 2;
}
// next compute the width each row
else
out.setf(std::ios::fixed, std::ios::floatfield);
out << std::setw(column_widths[j]);
- out << column.entries[i].value;
+
+ // get the string to write into the
+ // table. we could simply << it
+ // into the stream but we have to
+ // be a bit careful about the case
+ // where the string may be empty,
+ // in which case we'll print it as
+ // ""
+ {
+ std::ostringstream text;
+ text << column.entries[i].value;
+ if (text.str().size() > 0)
+ out << text.str();
+ else
+ out << "\"\"";
+ }
+
+ // pad after this column
out << " ";
}
out << std::endl;
--- /dev/null
+//-----------------------------------------------------------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2010, 2011 by the deal.II authors
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//-----------------------------------------------------------------------------
+
+// make sure we print something at all when an entry in the table corresponds
+// to the empty string
+
+
+#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_03/output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ TableHandler table;
+
+ std::string keys[3] = { "key1", "key2", "key3" };
+
+ table.add_value(keys[0], 0);
+ table.add_value(keys[1], std::string(""));
+ table.add_value(keys[2], std::string("a"));
+
+ table.write_text(deallog.get_file_stream());
+}
--- /dev/null
+
+key1 key2 key3
+0 "" a