]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
new TextOutputFormat::simple_table_with_separate_column_description
authorheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 10 Sep 2012 14:25:52 +0000 (14:25 +0000)
committerheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 10 Sep 2012 14:25:52 +0000 (14:25 +0000)
git-svn-id: https://svn.dealii.org/trunk@26266 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/include/deal.II/base/table_handler.h
deal.II/source/base/table_handler.cc

index 48e7670d5c8d319707e0e3139da959b37bc1c968..649e991a9670b5670a901685d68906abfa8a7c7d 100644 (file)
@@ -50,6 +50,11 @@ never working correctly and it is not used.
 <h3>Specific improvements</h3>
 
 <ol>
+<li> New: TableHandler TextOutputFormat::simple_table_with_separate_column_description
+that skips aligning the columns for increased performance.
+<br>
+(Timo Heister, 2012/09/10)
+
 <li> Fixed: The Clang C++ compiler had some trouble dealing with obtaining
 the return value of a Threads::Task object, due to a compiler bug in
 dealing with friend declarations. This is now fixed.
index 034bd82542398a29b9deb1554b0a4e9f010b5b71..8200af5b2229b691d110d6cbcdbab5147b701ea3 100644 (file)
@@ -280,11 +280,26 @@ class TableHandler
      *     2 13 a
      *     1 0  ""
      *   @endcode
+     * - <code>simple_table_with_separate_column_description</code>: This format
+     *   is very similar to <code>table_with_separate_column_description</code>,
+     *   but it skips aligning the columns with additional white space. This
+     *   increases the performance o fwrite_text() for large tables. Example output:
+     *   @code
+     *     # 1: key1
+     *     # 2: key2
+     *     # 3: key3
+     *     0 0 ""
+     *     1 0 ""
+     *     2 13 a
+     *     1 0 ""
+     *   @endcode
+     *
      **/
     enum TextOutputFormat
     {
       table_with_headers,
-      table_with_separate_column_description
+      table_with_separate_column_description,
+      simple_table_with_separate_column_description,
     };
 
                                      /**
index 6a98b15fa3f0e8962511b40804ffff9a3ee66b38..ee91075742ad33c508d7fdc6f56e273906a1b25c 100644 (file)
@@ -290,9 +290,60 @@ void TableHandler::write_text(std::ostream &out,
   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)
+    {
+      // write the captions
+      for (unsigned int j=0; j<column_order.size(); ++j)
+        {
+          const std::string & key = column_order[j];
+          out << "# " << j+1 << ": " << key << '\n';
+        }
+
+      // cache the columns
+      std::vector<const Column*> cols;
+      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));
+        }
+
+      // write the body
+      for (unsigned int i=0; i<nrows; ++i)
+        {
+          for (unsigned int j=0; j<n_cols; ++j)
+            {
+              const Column &column=*(cols[j]);
+
+              out << std::setprecision(column.precision);
+
+              if (column.scientific)
+                out.setf(std::ios::scientific, std::ios::floatfield);
+              else
+                out.setf(std::ios::fixed, std::ios::floatfield);
+
+              // write "" instead of an empty string
+              const std::string * val = boost::get<std::string>(&(column.entries[i].value));
+              if (val!=NULL && val->length()==0)
+                out << "\"\"";
+              else
+                out << column.entries[i].value;
+
+              out << ' ';
+            }
+          out << '\n';
+        }
+
+      out << std::flush;
+      return;
+    }
+
                                    // first compute the widths of each
                                    // entry of the table, in order to
-                                   // have a nicer alignement
+                                   // have a nicer alignment
   Table<2,unsigned int> entry_widths (nrows, n_cols);
   for (unsigned int i=0; i<nrows; ++i)
     for (unsigned int j=0; j<n_cols; ++j)
@@ -386,7 +437,7 @@ void TableHandler::write_text(std::ostream &out,
       }
     }
   if (format == table_with_headers)
-    out << std::endl;
+    out << '\n';
 
   for (unsigned int i=0; i<nrows; ++i)
     {

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.