Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_Describable.hpp
Go to the documentation of this file.
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"
16 
17 
18 namespace Teuchos {
19 
20 
45 public:
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!
147  const Describable &_describable,
148  const EVerbosityLevel _verbLevel = VERB_MEDIUM
149  )
150  :describable(_describable)
151  ,verbLevel(_verbLevel)
152  {}
153 };
154 
155 
178  const Describable &describable,
180  )
181 {
182  return DescribableStreamManipulatorState(describable,verbLevel);
183 }
184 
185 
212 inline
213 std::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
EVerbosityLevel
Verbosity level.
Base class for objects that contain a std::string label.
DescribableStreamManipulatorState(const Describable &_describable, const EVerbosityLevel _verbLevel=VERB_MEDIUM)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
#define TEUCHOSCORE_LIB_DLL_EXPORT
std::ostream subclass that performs the magic of indenting data sent to an std::ostream object among ...
std::ostream & operator<<(std::ostream &os, const DescribableStreamManipulatorState &d)
Output stream operator for Describable manipulator.
static const EVerbosityLevel verbLevel_default
Default value for the verbLevel argument of describe().
Base class for all objects that can describe themselves.
DescribableStreamManipulatorState describe(const Describable &describable, const EVerbosityLevel verbLevel=Describable::verbLevel_default)
Describable output stream manipulator.
Generate more output.
virtual void describe(FancyOStream &out, const EVerbosityLevel verbLevel=verbLevel_default) const
Print the object with some verbosity level to a FancyOStream.