Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Teuchos_VerboseObject.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_VERBOSE_OBJECT_HPP
43#define TEUCHOS_VERBOSE_OBJECT_HPP
44
45#include "Teuchos_RCP.hpp"
48
49
50namespace Teuchos {
51
52
67public:
68
70
71
77 static void setDefaultOStream( const RCP<FancyOStream> &defaultOStream );
78
80 static RCP<FancyOStream> getDefaultOStream();
81
83
85
86
88 virtual ~VerboseObjectBase();
89
92 explicit
95 );
96
102 virtual const VerboseObjectBase& setOStream(
103 const RCP<FancyOStream> &oStream) const;
104
111 virtual const VerboseObjectBase& setOverridingOStream(
112 const RCP<FancyOStream> &oStream) const;
113
115 virtual VerboseObjectBase& setLinePrefix(const std::string &linePrefix);
116
118
120
121
125 virtual RCP<FancyOStream> getOStream() const;
126
133 virtual RCP<FancyOStream> getOverridingOStream() const;
134
136 virtual std::string getLinePrefix() const;
137
139
141
142
156 virtual OSTab getOSTab(const int tabs = 1, const std::string &linePrefix = "") const;
157
159
160protected:
161
164 void initializeVerboseObjectBase(
166 );
167
176 virtual void informUpdatedVerbosityState() const;
177
178private:
179
180 std::string thisLinePrefix_;
181
182//use pragmas to disable some false-positive warnings for windows sharedlibs export
183#ifdef _MSC_VER
184#pragma warning(push)
185#pragma warning(disable:4251)
186#endif
189#ifdef _MSC_VER
190#pragma warning(pop)
191#endif
192
193 static RCP<FancyOStream>& privateDefaultOStream();
194
195};
196
197
233template<class ObjectType>
234class VerboseObject : virtual public VerboseObjectBase {
235public:
237
238
244
247
249
251
253 explicit
255 const EVerbosityLevel verbLevel = VERB_DEFAULT, // Note, this must be the same as the default value for defaultVerbLevel_
257 );
258
265 const EVerbosityLevel verbLevel) const;
266
274 const EVerbosityLevel verbLevel) const;
275
277
279
282
284
285protected:
286
295 const EVerbosityLevel verbLevel = VERB_DEFAULT,
297 );
298
299private:
300
303
305
306};
307
308
312template<class ObjectType>
348
349
350// //////////////////////////////////
351// Template defintions
352
353
354//
355// VerboseObject
356//
357
358
359// Public static member functions
360
361
362template<class ObjectType>
367
368
369template<class ObjectType>
371{
372 return privateDefaultVerbLevel();
373}
374
375
376// Constructors/Initializers
377
378
379template<class ObjectType>
381 const EVerbosityLevel verbLevel,
383 )
384 : thisOverridingVerbLevel_(VERB_DEFAULT)
385{
386 this->initializeVerboseObject(verbLevel,oStream);
387}
388
389
390template<class ObjectType>
392 const EVerbosityLevel verbLevel,
394 )
395{
396 thisVerbLevel_ = verbLevel;
397 this->initializeVerboseObjectBase(oStream);
398}
399
400
401template<class ObjectType>
404{
405 thisVerbLevel_ = verbLevel;
406 informUpdatedVerbosityState();
407 return *this;
408}
409
410
411template<class ObjectType>
414 const EVerbosityLevel verbLevel
415 ) const
416{
417 thisOverridingVerbLevel_ = verbLevel;
418 informUpdatedVerbosityState();
419 return *this;
420}
421
422
423// Query functions
424
425
426template<class ObjectType>
428{
429 if (VERB_DEFAULT != thisOverridingVerbLevel_)
430 return thisOverridingVerbLevel_;
431 if (VERB_DEFAULT == thisVerbLevel_)
432 return getDefaultVerbLevel();
433 return thisVerbLevel_;
434}
435
436
437// Private static members
438
439
440template<class ObjectType>
446
447
448} // namespace Teuchos
449
450
451#endif // TEUCHOS_VERBOSE_OBJECT_HPP
#define TEUCHOSCORE_LIB_DLL_EXPORT
Reference-counted pointer class and non-member templated function implementations.
Smart reference counting pointer class for automatic garbage collection.
Concrete serial communicator subclass.
Non-templated base class for objects that can print their activities to a stream.
RCP< FancyOStream > thisOverridingOStream_
Set and release a stream and verbosity level.
VerboseObjectTempState & operator=(const VerboseObjectTempState &)
VerboseObjectTempState(const VerboseObjectTempState &)
VerboseObjectTempState(const RCP< const VerboseObject< ObjectType > > &verboseObject, const RCP< FancyOStream > &newOStream, const EVerbosityLevel newVerbLevel)
RCP< const VerboseObject< ObjectType > > verboseObject_
Templated base class for objects that can print their activities to a stream and have a verbosity lev...
static void setDefaultVerbLevel(const EVerbosityLevel defaultVerbLevel)
Set the default verbosity level.
virtual const VerboseObject & setVerbLevel(const EVerbosityLevel verbLevel) const
Set this object's verbosity level.
static EVerbosityLevel & privateDefaultVerbLevel()
virtual EVerbosityLevel getVerbLevel() const
Get the verbosity level.
VerboseObject(const EVerbosityLevel verbLevel=VERB_DEFAULT, const RCP< FancyOStream > &oStream=Teuchos::null)
Constructor: calls initializeVerboseObject().
void initializeVerboseObject(const EVerbosityLevel verbLevel=VERB_DEFAULT, const RCP< FancyOStream > &oStream=Teuchos::null)
Initialize the VerboseObject.
static EVerbosityLevel getDefaultVerbLevel()
Get the default verbosity level.
virtual const VerboseObject & setOverridingVerbLevel(const EVerbosityLevel verbLevel) const
Set the overriding verbosity level for *this object.
EVerbosityLevel
Verbosity level.
@ VERB_DEFAULT
Generate output as defined by the object.