Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_Describable.hpp
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#ifndef TEUCHOS_DESCRIBABLE_HPP
11#define TEUCHOS_DESCRIBABLE_HPP
12
14#include "Teuchos_FancyOStream.hpp"
15#include "Teuchos_LabeledObject.hpp"
16
17
18namespace Teuchos {
19
20
44class TEUCHOSCORE_LIB_DLL_EXPORT Describable : virtual public LabeledObject {
45public:
48
50
51
63 virtual std::string description() const;
64
116 virtual void
117 describe (FancyOStream &out,
118 const EVerbosityLevel verbLevel = verbLevel_default) const;
119
130 void
131 describe (std::ostream &out,
132 const EVerbosityLevel verbLevel = verbLevel_default) const;
133
135 virtual ~Describable ();
136};
137
138
139// Describable stream manipulator state class
140//
141// This is not a class that a user needs to see and that is why it is not
142// being given doxygen documentation!
143struct DescribableStreamManipulatorState {
144 const Describable &describable;
145 const EVerbosityLevel verbLevel;
146 DescribableStreamManipulatorState(
149 )
150 :describable(_describable)
151 ,verbLevel(_verbLevel)
152 {}
153};
154
155
177inline DescribableStreamManipulatorState describe(
178 const Describable &describable,
180 )
181{
182 return DescribableStreamManipulatorState(describable,verbLevel);
183}
184
185
212inline
213std::ostream& operator<<(
214 std::ostream& os, const DescribableStreamManipulatorState& d
215 )
216{
217 d.describable.describe(*getFancyOStream(Teuchos::rcp(&os,false)),d.verbLevel);
218 return os;
219}
220
221//
222// RAB: Note: The above function works with an std::ostream object even
223// through Describable::describe(...) requires a FancyOStream object. We must
224// write the stream manipulator in terms of std::ostream, or compound output
225// statements like:
226//
227// void foo( FancyOStream &out, Describable &d, EVerbLevel verbLevel )
228// {
229// out << "\nThis is the describable object d:" << describe(d,verbLevel);
230// }
231//
232// will not work correctly. The problem is that the first output
233//
234// out << "\nThis is the describable object d:"
235//
236// must return a reference to an std::ostream object. This should mean that
237// the next statement, which is basically:
238//
239// static_cast<std::ostream&>(out) << DescribableStreamManipulatorState
240//
241// should not even compile. However, under gcc 3.4.3, the code did compile
242// but did not call the above function. Instead, it set up some type of
243// infinite recursion that resulted in a segfault due to the presence of the
244// Teuchos::any class!
245//
246
247
248} // namespace Teuchos
249
250#endif // TEUCHOS_DESCRIBABLE_HPP
Base class for all objects that can describe themselves.
static const EVerbosityLevel verbLevel_default
Default value for the verbLevel argument of describe().
std::ostream & operator<<(std::ostream &os, const DescribableStreamManipulatorState &d)
Output stream operator for Describable manipulator.
DescribableStreamManipulatorState describe(const Describable &describable, const EVerbosityLevel verbLevel=Describable::verbLevel_default)
Describable output stream manipulator.
Base class for objects that contain a std::string label.
Smart reference counting pointer class for automatic garbage collection.
std::ostream subclass that performs the magic of indenting data sent to an std::ostream object among ...
EVerbosityLevel
Verbosity level.
@ VERB_MEDIUM
Generate more output.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.