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),
71  precision_ (4),
72  columnSpacing_ (4),
73  lineInterval_ (10),
74  columnWidths_ ()
75  {}
76 
79  int pageWidth() const {return pageWidth_;}
80 
83  int precision() const {return precision_;}
84 
87  int columnSpacing() const {return columnSpacing_;}
88 
92  void setPageWidth(int pw) const {pageWidth_ = pw;}
93 
95  void setPrecision(int p) {precision_ = p;}
96 
98  void setColumnSpacing(int columnSpacing_in) {columnSpacing_ = columnSpacing_in;}
99 
105  void setRowsBetweenLines(int lineInterval) {lineInterval_=lineInterval;}
106 
113  std::string thinline() const ;
114 
117  std::string thickline() const ;
118 
120  std::string blanks(int size) const ;
121 
130  int computeRequiredColumnWidth(const std::string& name,
131  const TableColumn& column) const ;
132 
134  void setColumnWidths(const Array<int>& colWidths)
135  {columnWidths_ = colWidths;}
136 
143  void writeRow(
144  std::ostream& out,
145  const Array<RCP<TableEntry> >& entries
146  ) const;
147 
155  void writeRow(
156  std::ostream& out,
157  int rowIndex,
158  const Array<TableColumn>& columns
159  ) const;
160 
162  void writeWholeTable(
163  std::ostream& out,
164  const std::string& tableTitle,
165  const Array<std::string>& columnNames,
166  const Array<TableColumn>& columns
167  ) const ;
168 
169 protected:
170 
171  int defaultColumnWidth() const {return 20;}
172 
173 private:
174 
175  mutable int pageWidth_;
176  int precision_;
177  int columnSpacing_;
178  //int maxNameSize_; // UNUSED
179  int lineInterval_;
180  Array<int> columnWidths_;
181 };
182 
183 
184 } // namespace Teuchos
185 
186 
187 #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.