Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_TableEntry.cpp
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "Teuchos_TableEntry.hpp"
11 
12 using namespace Teuchos;
13 
14 
15 /* --------- base class methods ---------------------------------------------- */
16 
17 std::string TableEntry::toChoppedString(int maxWidth) const
18 {
19  return toString().substr(0, maxWidth);
20 }
21 
22 
23 
24 /* --------- DoubleEntry methods -------------------------------------------- */
25 
26 DoubleEntry::DoubleEntry(const double& value, int precision, const std::ios_base::fmtflags& flags)
27  : TableEntry(), data_(value), precision_(precision), fmtflags_(flags)
28 {}
29 
30 std::string DoubleEntry::toString() const
31 {
32  std::ostringstream toss;
33  toss.setf(fmtflags_);
34  toss << std::setprecision(precision_) << data_;
35  return toss.str();
36 }
37 
38 
39 
40 /* --------- IntEntry methods -------------------------------------------- */
41 
42 IntEntry::IntEntry(int value, const std::ios_base::fmtflags& flags)
43  : TableEntry(), data_(value), fmtflags_(flags)
44 {}
45 
46 std::string IntEntry::toString() const
47 {
48  std::ostringstream toss;
49  toss.setf(fmtflags_);
50  toss << data_;
51  return toss.str();
52 }
53 
54 
55 
56 /* --------- StringEntry methods -------------------------------------------- */
57 
58 StringEntry::StringEntry(std::string value)
59  : TableEntry(), data_(value)
60 {}
61 
62 std::string StringEntry::toString() const
63 {
64  return data_;
65 }
66 
67 
68 
69 
70 
71 /* --------- CompoundEntryWithParentheses methods ------------------------- */
72 
73 CompoundEntryWithParentheses
74 ::CompoundEntryWithParentheses(const RCP<TableEntry>& first,
75  const RCP<TableEntry>& second,
76  bool spaceBeforeParens)
77  : TableEntry(),
78  first_(first),
79  second_(second),
80  spaceBeforeParens_(spaceBeforeParens)
81 {}
82 
84 {
85  std::ostringstream toss;
86 
87  toss << first_->toString();
88  if (spaceBeforeParens_) toss << " ";
89  toss << "(" << second_->toString() << ")";
90 
91  return toss.str();
92 }
93 
94 
95 
96 
97 
98 
virtual std::string toString() const =0
Return a std::string representation of this entry.
An entry, perhaps compound, to be written into a table.
virtual std::string toChoppedString(int maxWidth) const
Return a std::string representation of this entry, truncated if necessary to fit within the given col...
virtual std::string toString() const
Write the specified entry to a std::string.
Base class for representing compound entries in a printed table of data. &quot;Compound&quot; means that each e...
IntEntry(int value, const std::ios_base::fmtflags &flags)
Construct with a value.
virtual std::string toString() const
Write the specified entry to a std::string.
virtual std::string toString() const
Write the specified entry to a std::string.
virtual std::string toString() const
Write the specified entry to a std::string.
Smart reference counting pointer class for automatic garbage collection.
DoubleEntry(const double &value, int precision, const std::ios_base::fmtflags &flags)
Construct with a value and a precision.
StringEntry(std::string value)
Construct with a value.