Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"
46 #include "Teuchos_FancyOStream.hpp"
48 
49 
50 namespace Teuchos {
51 
52 
67 public:
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
94  const RCP<FancyOStream> &oStream = Teuchos::null
95  );
96 
99  virtual void initializeVerboseObjectBase(
100  const RCP<FancyOStream> &oStream = Teuchos::null
101  );
102 
108  virtual const VerboseObjectBase& setOStream(
109  const RCP<FancyOStream> &oStream) const;
110 
117  virtual const VerboseObjectBase& setOverridingOStream(
118  const RCP<FancyOStream> &oStream) const;
119 
121  virtual VerboseObjectBase& setLinePrefix(const std::string &linePrefix);
122 
124 
126 
127 
131  virtual RCP<FancyOStream> getOStream() const;
132 
139  virtual RCP<FancyOStream> getOverridingOStream() const;
140 
142  virtual std::string getLinePrefix() const;
143 
145 
147 
148 
162  virtual OSTab getOSTab(const int tabs = 1, const std::string &linePrefix = "") const;
163 
165 
166 protected:
167 
176  virtual void informUpdatedVerbosityState() const;
177 
178 private:
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 
233 template<class ObjectType>
234 class VerboseObject : virtual public VerboseObjectBase {
235 public:
237 
238 
243  static void setDefaultVerbLevel( const EVerbosityLevel defaultVerbLevel);
244 
247 
249 
251 
253  explicit
255  const EVerbosityLevel verbLevel = VERB_DEFAULT, // Note, this must be the same as the default value for defaultVerbLevel_
256  const RCP<FancyOStream> &oStream = Teuchos::null
257  );
258 
266  virtual void initializeVerboseObject(
267  const EVerbosityLevel verbLevel = VERB_DEFAULT,
268  const RCP<FancyOStream> &oStream = Teuchos::null
269  );
270 
276  virtual const VerboseObject& setVerbLevel(
277  const EVerbosityLevel verbLevel) const;
278 
285  virtual const VerboseObject& setOverridingVerbLevel(
286  const EVerbosityLevel verbLevel) const;
287 
289 
291 
293  virtual EVerbosityLevel getVerbLevel() const;
294 
296 
297 private:
298 
301 
303 
304 };
305 
306 
310 template<class ObjectType>
312 public:
315  const RCP<const VerboseObject<ObjectType> > &verboseObject,
316  const RCP<FancyOStream> &newOStream,
317  const EVerbosityLevel newVerbLevel
318  )
319  :verboseObject_(verboseObject)
320  {
321  if(verboseObject_.get()) {
322  oldOStream_ = verboseObject_->getOStream();
323  oldVerbLevel_ = verboseObject_->getVerbLevel();
324  verboseObject_->setOStream(newOStream);
325  verboseObject_->setVerbLevel(newVerbLevel);
326  }
327  }
330  {
331  if(verboseObject_.get()) {
332  verboseObject_->setOStream(oldOStream_);
333  verboseObject_->setVerbLevel(oldVerbLevel_);
334  }
335  }
336 private:
340  // Not defined and not to be called
344 };
345 
346 
347 // //////////////////////////////////
348 // Template defintions
349 
350 
351 //
352 // VerboseObject
353 //
354 
355 
356 // Public static member functions
357 
358 
359 template<class ObjectType>
361 {
362  privateDefaultVerbLevel() = defaultVerbLevel;
363 }
364 
365 
366 template<class ObjectType>
368 {
369  return privateDefaultVerbLevel();
370 }
371 
372 
373 // Constructors/Initializers
374 
375 
376 template<class ObjectType>
378  const EVerbosityLevel verbLevel,
379  const RCP<FancyOStream> &oStream
380  )
381  : thisOverridingVerbLevel_(VERB_DEFAULT)
382 {
383  this->initializeVerboseObject(verbLevel,oStream);
384 }
385 
386 
387 template<class ObjectType>
389  const EVerbosityLevel verbLevel,
390  const RCP<FancyOStream> &oStream
391  )
392 {
393  thisVerbLevel_ = verbLevel;
394  this->initializeVerboseObjectBase(oStream);
395 }
396 
397 
398 template<class ObjectType>
401 {
402  thisVerbLevel_ = verbLevel;
403  informUpdatedVerbosityState();
404  return *this;
405 }
406 
407 
408 template<class ObjectType>
411  const EVerbosityLevel verbLevel
412  ) const
413 {
414  thisOverridingVerbLevel_ = verbLevel;
415  informUpdatedVerbosityState();
416  return *this;
417 }
418 
419 
420 // Query functions
421 
422 
423 template<class ObjectType>
425 {
426  if (VERB_DEFAULT != thisOverridingVerbLevel_)
427  return thisOverridingVerbLevel_;
428  if (VERB_DEFAULT == thisVerbLevel_)
429  return getDefaultVerbLevel();
430  return thisVerbLevel_;
431 }
432 
433 
434 // Private static members
435 
436 
437 template<class ObjectType>
439 {
440  static EVerbosityLevel defaultVerbLevel = VERB_DEFAULT;
441  return defaultVerbLevel;
442 }
443 
444 
445 } // namespace Teuchos
446 
447 
448 #endif // TEUCHOS_VERBOSE_OBJECT_HPP
EVerbosityLevel
Verbosity level.
RCP< const VerboseObject< ObjectType > > verboseObject_
static void setDefaultVerbLevel(const EVerbosityLevel defaultVerbLevel)
Set the default verbosity level.
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object...
virtual void initializeVerboseObject(const EVerbosityLevel verbLevel=VERB_DEFAULT, const RCP< FancyOStream > &oStream=Teuchos::null)
Initialize the VerboseObject.
Set and release a stream and verbosity level.
static EVerbosityLevel & privateDefaultVerbLevel()
VerboseObjectTempState(const RCP< const VerboseObject< ObjectType > > &verboseObject, const RCP< FancyOStream > &newOStream, const EVerbosityLevel newVerbLevel)
Templated base class for objects that can print their activities to a stream and have a verbosity lev...
static EVerbosityLevel getDefaultVerbLevel()
Get the default verbosity level.
#define TEUCHOSCORE_LIB_DLL_EXPORT
Non-templated base class for objects that can print their activities to a stream. ...
VerboseObjectTempState & operator=(const VerboseObjectTempState &)
RCP< FancyOStream > thisOverridingOStream_
virtual const VerboseObject & setVerbLevel(const EVerbosityLevel verbLevel) const
Set this object&#39;s verbosity level.
EVerbosityLevel thisOverridingVerbLevel_
VerboseObject(const EVerbosityLevel verbLevel=VERB_DEFAULT, const RCP< FancyOStream > &oStream=Teuchos::null)
Constructor: calls initializeVerboseObject().
Smart reference counting pointer class for automatic garbage collection.
virtual EVerbosityLevel getVerbLevel() const
Get the verbosity level.
Reference-counted pointer class and non-member templated function implementations.
Generate output as defined by the object.
virtual const VerboseObject & setOverridingVerbLevel(const EVerbosityLevel verbLevel) const
Set the overriding verbosity level for *this object.