Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
core
src
Teuchos_Describable.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_DESCRIBABLE_HPP
43
#define TEUCHOS_DESCRIBABLE_HPP
44
45
#include "
Teuchos_VerbosityLevel.hpp
"
46
#include "
Teuchos_FancyOStream.hpp
"
47
#include "
Teuchos_LabeledObject.hpp
"
48
49
50
namespace
Teuchos
{
51
52
76
class
TEUCHOSCORE_LIB_DLL_EXPORT
Describable
:
virtual
public
LabeledObject
{
77
public
:
79
static
const
EVerbosityLevel
verbLevel_default
;
80
82
83
95
virtual
std::string
description
()
const
;
96
148
virtual
void
149
describe
(
FancyOStream
&out,
150
const
EVerbosityLevel
verbLevel =
verbLevel_default
)
const
;
151
162
void
163
describe
(std::ostream &out,
164
const
EVerbosityLevel
verbLevel =
verbLevel_default
)
const
;
165
167
virtual
~Describable
();
168
};
169
170
171
// Describable stream manipulator state class
172
//
173
// This is not a class that a user needs to see and that is why it is not
174
// being given doxygen documentation!
175
struct
DescribableStreamManipulatorState
{
176
const
Describable
&
describable
;
177
const
EVerbosityLevel
verbLevel
;
178
DescribableStreamManipulatorState
(
179
const
Describable
&_describable,
180
const
EVerbosityLevel
_verbLevel =
VERB_MEDIUM
181
)
182
:
describable
(_describable)
183
,
verbLevel
(_verbLevel)
184
{}
185
};
186
187
209
inline
DescribableStreamManipulatorState
describe
(
210
const
Describable
&describable,
211
const
EVerbosityLevel
verbLevel =
Describable::verbLevel_default
212
)
213
{
214
return
DescribableStreamManipulatorState
(describable,verbLevel);
215
}
216
217
244
inline
245
std::ostream&
operator<<
(
246
std::ostream& os,
const
DescribableStreamManipulatorState
& d
247
)
248
{
249
d.
describable
.
describe
(*
getFancyOStream
(
Teuchos::rcp
(&os,
false
)),d.
verbLevel
);
250
return
os;
251
}
252
253
//
254
// RAB: Note: The above function works with an std::ostream object even
255
// through Describable::describe(...) requires a FancyOStream object. We must
256
// write the stream manipulator in terms of std::ostream, or compound output
257
// statements like:
258
//
259
// void foo( FancyOStream &out, Describable &d, EVerbLevel verbLevel )
260
// {
261
// out << "\nThis is the describable object d:" << describe(d,verbLevel);
262
// }
263
//
264
// will not work correctly. The problem is that the first output
265
//
266
// out << "\nThis is the describable object d:"
267
//
268
// must return a reference to an std::ostream object. This should mean that
269
// the next statement, which is basically:
270
//
271
// static_cast<std::ostream&>(out) << DescribableStreamManipulatorState
272
//
273
// should not even compile. However, under gcc 3.4.3, the code did compile
274
// but did not call the above function. Instead, it set up some type of
275
// infinite recursion that resulted in a segfault due to the presence of the
276
// Teuchos::any class!
277
//
278
279
280
}
// namespace Teuchos
281
282
#endif
// TEUCHOS_DESCRIBABLE_HPP
TEUCHOSCORE_LIB_DLL_EXPORT
#define TEUCHOSCORE_LIB_DLL_EXPORT
Definition
Teuchos_DLLExportMacro.h:9
Teuchos_FancyOStream.hpp
Teuchos_LabeledObject.hpp
Teuchos_VerbosityLevel.hpp
Teuchos::Describable
Base class for all objects that can describe themselves.
Definition
Teuchos_Describable.hpp:76
Teuchos::Describable::verbLevel_default
static const EVerbosityLevel verbLevel_default
Default value for the verbLevel argument of describe().
Definition
Teuchos_Describable.hpp:79
Teuchos::Describable::operator<<
std::ostream & operator<<(std::ostream &os, const DescribableStreamManipulatorState &d)
Output stream operator for Describable manipulator.
Definition
Teuchos_Describable.hpp:245
Teuchos::Describable::describe
DescribableStreamManipulatorState describe(const Describable &describable, const EVerbosityLevel verbLevel=Describable::verbLevel_default)
Describable output stream manipulator.
Definition
Teuchos_Describable.hpp:209
Teuchos::Describable::describe
virtual void describe(FancyOStream &out, const EVerbosityLevel verbLevel=verbLevel_default) const
Print the object with some verbosity level to a FancyOStream.
Definition
Teuchos_Describable.cpp:64
Teuchos::Describable::description
virtual std::string description() const
Return a simple one-line description of this object.
Definition
Teuchos_Describable.cpp:52
Teuchos::LabeledObject::LabeledObject
LabeledObject()
Construct with an empty label.
Definition
Teuchos_LabeledObject.cpp:48
Teuchos::basic_FancyOStream::getFancyOStream
RCP< basic_FancyOStream< char > > getFancyOStream(const RCP< std::basic_ostream< char > > &out)
Get a FancyOStream from an std::ostream object.
Definition
Teuchos_FancyOStream.hpp:629
Teuchos
Definition
Teuchos_AbstractFactory.hpp:47
Teuchos::FancyOStream
basic_FancyOStream< char > FancyOStream
Definition
Teuchos_FancyOStream.hpp:845
Teuchos::rcp
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Definition
Teuchos_RCPDecl.hpp:1266
Teuchos::EVerbosityLevel
EVerbosityLevel
Verbosity level.
Definition
Teuchos_VerbosityLevel.hpp:63
Teuchos::VERB_MEDIUM
@ VERB_MEDIUM
Generate more output.
Definition
Teuchos_VerbosityLevel.hpp:67
Teuchos::DescribableStreamManipulatorState
Definition
Teuchos_Describable.hpp:175
Teuchos::DescribableStreamManipulatorState::describable
const Describable & describable
Definition
Teuchos_Describable.hpp:176
Teuchos::DescribableStreamManipulatorState::DescribableStreamManipulatorState
DescribableStreamManipulatorState(const Describable &_describable, const EVerbosityLevel _verbLevel=VERB_MEDIUM)
Definition
Teuchos_Describable.hpp:178
Teuchos::DescribableStreamManipulatorState::verbLevel
const EVerbosityLevel verbLevel
Definition
Teuchos_Describable.hpp:177
Generated by
1.17.0