Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
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
11
12using namespace Teuchos;
13
14
15/* --------- base class methods ---------------------------------------------- */
16
18{
19 return toString().substr(0, maxWidth);
20}
21
22
23
24/* --------- DoubleEntry methods -------------------------------------------- */
25
26DoubleEntry::DoubleEntry(const double& value, int precision, const std::ios_base::fmtflags& flags)
27 : TableEntry(), data_(value), precision_(precision), fmtflags_(flags)
28{}
29
30std::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
42IntEntry::IntEntry(int value, const std::ios_base::fmtflags& flags)
43 : TableEntry(), data_(value), fmtflags_(flags)
44{}
45
46std::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
58StringEntry::StringEntry(std::string value)
59 : TableEntry(), data_(value)
60{}
61
62std::string StringEntry::toString() const
63{
64 return data_;
65}
66
67
68
69
70
71/* --------- CompoundEntryWithParentheses methods ------------------------- */
72
73CompoundEntryWithParentheses
74::CompoundEntryWithParentheses(const RCP<TableEntry>& first,
75 const RCP<TableEntry>& second,
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
Base class for representing compound entries in a printed table of data. "Compound" means that each e...
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.
DoubleEntry(const double &value, int precision, const std::ios_base::fmtflags &flags)
Construct with a value and a precision.
virtual std::string toString() const
Write the specified entry to a std::string.
IntEntry(int value, const std::ios_base::fmtflags &flags)
Construct with a value.
Smart reference counting pointer class for automatic garbage collection.
StringEntry(std::string value)
Construct with a value.
virtual std::string toString() const
Write the specified entry to a std::string.
An entry, perhaps compound, to be written into a table.
virtual std::string toString() const =0
Return a std::string representation of this entry.
virtual std::string toChoppedString(int maxWidth) const
Return a std::string representation of this entry, truncated if necessary to fit within the given col...
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...