Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_TableFormat.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef TEUCHOS_TABLEFORMAT_H
43 #define TEUCHOS_TABLEFORMAT_H
44 
49 #include "Teuchos_ConfigDefs.hpp"
50 #include "Teuchos_TableColumn.hpp"
51 #include <iostream>
52 
53 namespace Teuchos
54 {
55 
66 {
67 public:
70  : pageWidth_(80), precision_(4), columnSpacing_(4),
71  maxNameSize_(40), columnWidths_(), lineInterval_(10)
72  {}
73 
76  int pageWidth() const {return pageWidth_;}
77 
80  int precision() const {return precision_;}
81 
84  int columnSpacing() const {return columnSpacing_;}
85 
89  void setPageWidth(int pw) const {pageWidth_ = pw;}
90 
92  void setPrecision(int p) {precision_ = p;}
93 
95  void setColumnSpacing(int columnSpacing_in) {columnSpacing_ = columnSpacing_in;}
96 
102  void setRowsBetweenLines(int lineInterval) {lineInterval_=lineInterval;}
103 
110  std::string thinline() const ;
111 
114  std::string thickline() const ;
115 
117  std::string blanks(int size) const ;
118 
127  int computeRequiredColumnWidth(const std::string& name,
128  const TableColumn& column) const ;
129 
131  void setColumnWidths(const Array<int>& colWidths)
132  {columnWidths_ = colWidths;}
133 
140  void writeRow(
141  std::ostream& out,
142  const Array<RCP<TableEntry> >& entries
143  ) const;
144 
152  void writeRow(
153  std::ostream& out,
154  int rowIndex,
155  const Array<TableColumn>& columns
156  ) const;
157 
159  void writeWholeTable(
160  std::ostream& out,
161  const std::string& tableTitle,
162  const Array<std::string>& columnNames,
163  const Array<TableColumn>& columns
164  ) const ;
165 
166 protected:
167 
168  int defaultColumnWidth() const {return 20;}
169 
170 private:
171 
172  mutable int pageWidth_;
173  int precision_;
174  int columnSpacing_;
175  int maxNameSize_;
176  Array<int> columnWidths_;
177  int lineInterval_;
178 };
179 
180 
181 } // namespace Teuchos
182 
183 
184 #endif
void setColumnWidths(const Array< int > &colWidths)
Set the column widths to be used for subsequent rows.
void writeWholeTable(std::ostream &out, const std::string &tableTitle, const Array< std::string > &columnNames, const Array< TableColumn > &columns) const
void setColumnSpacing(int columnSpacing_in)
Set the number of characters to be left as blank spaces in each column.
int computeRequiredColumnWidth(const std::string &name, const TableColumn &column) const
Computes the column width required to write all values to the required precision. ...
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
int pageWidth() const
Get the maximum number of characters per line. Default is 80.
A column of TableEntry objects.
void setPrecision(int p)
Set the precision for writing doubles.
int precision() const
Get the precision for writing doubles. Default is 4.
std::string blanks(int size) const
Return a std::string full of blanks up to the requested size.
void setPageWidth(int pw) const
Set the number of characters on a line. This quantity can be updated within the const method writeWho...
TableFormat()
Construct with a header and default format settings.
int columnSpacing() const
Get the number of characters to be left as blank spaces in each column. Default is 4...
std::string thickline() const
Return a thick horizontal line in equal signs &quot;====&quot; the width of the page.
void setRowsBetweenLines(int lineInterval)
Set the interval at which a horizontal line will be written between rows.
std::string thinline() const
Return a horizontal line in dashes &quot;----&quot; the width of the page.
Smart reference counting pointer class for automatic garbage collection.
void writeRow(std::ostream &out, const Array< RCP< TableEntry > > &entries) const
Write the row of entries.
Encapsulation of formatting specifications for writing data in a clean tabular form.