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 // 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_VERBOSE_OBJECT_HPP
11 #define TEUCHOS_VERBOSE_OBJECT_HPP
12 
13 #include "Teuchos_RCP.hpp"
14 #include "Teuchos_FancyOStream.hpp"
16 
17 
18 namespace Teuchos {
19 
20 
35 public:
36 
38 
39 
45  static void setDefaultOStream( const RCP<FancyOStream> &defaultOStream );
46 
48  static RCP<FancyOStream> getDefaultOStream();
49 
51 
53 
54 
56  virtual ~VerboseObjectBase();
57 
60  explicit
62  const RCP<FancyOStream> &oStream = Teuchos::null
63  );
64 
70  virtual const VerboseObjectBase& setOStream(
71  const RCP<FancyOStream> &oStream) const;
72 
79  virtual const VerboseObjectBase& setOverridingOStream(
80  const RCP<FancyOStream> &oStream) const;
81 
83  virtual VerboseObjectBase& setLinePrefix(const std::string &linePrefix);
84 
86 
88 
89 
93  virtual RCP<FancyOStream> getOStream() const;
94 
101  virtual RCP<FancyOStream> getOverridingOStream() const;
102 
104  virtual std::string getLinePrefix() const;
105 
107 
109 
110 
124  virtual OSTab getOSTab(const int tabs = 1, const std::string &linePrefix = "") const;
125 
127 
128 protected:
129 
132  void initializeVerboseObjectBase(
133  const RCP<FancyOStream> &oStream = Teuchos::null
134  );
135 
144  virtual void informUpdatedVerbosityState() const;
145 
146 private:
147 
148  std::string thisLinePrefix_;
149 
150 //use pragmas to disable some false-positive warnings for windows sharedlibs export
151 #ifdef _MSC_VER
152 #pragma warning(push)
153 #pragma warning(disable:4251)
154 #endif
157 #ifdef _MSC_VER
158 #pragma warning(pop)
159 #endif
160 
161  static RCP<FancyOStream>& privateDefaultOStream();
162 
163 };
164 
165 
201 template<class ObjectType>
202 class VerboseObject : virtual public VerboseObjectBase {
203 public:
205 
206 
211  static void setDefaultVerbLevel( const EVerbosityLevel defaultVerbLevel);
212 
215 
217 
219 
221  explicit
223  const EVerbosityLevel verbLevel = VERB_DEFAULT, // Note, this must be the same as the default value for defaultVerbLevel_
224  const RCP<FancyOStream> &oStream = Teuchos::null
225  );
226 
232  virtual const VerboseObject& setVerbLevel(
233  const EVerbosityLevel verbLevel) const;
234 
241  virtual const VerboseObject& setOverridingVerbLevel(
242  const EVerbosityLevel verbLevel) const;
243 
245 
247 
249  virtual EVerbosityLevel getVerbLevel() const;
250 
252 
253 protected:
254 
263  const EVerbosityLevel verbLevel = VERB_DEFAULT,
264  const RCP<FancyOStream> &oStream = Teuchos::null
265  );
266 
267 private:
268 
271 
273 
274 };
275 
276 
280 template<class ObjectType>
282 public:
285  const RCP<const VerboseObject<ObjectType> > &verboseObject,
286  const RCP<FancyOStream> &newOStream,
287  const EVerbosityLevel newVerbLevel
288  ):
289  verboseObject_(verboseObject),
291  {
292  if(verboseObject_.get()) {
293  oldOStream_ = verboseObject_->getOStream();
294  oldVerbLevel_ = verboseObject_->getVerbLevel();
295  verboseObject_->setOStream(newOStream);
296  verboseObject_->setVerbLevel(newVerbLevel);
297  }
298  }
301  {
302  if(verboseObject_.get()) {
303  verboseObject_->setOStream(oldOStream_);
304  verboseObject_->setVerbLevel(oldVerbLevel_);
305  }
306  }
307 private:
311  // Not defined and not to be called
315 };
316 
317 
318 // //////////////////////////////////
319 // Template defintions
320 
321 
322 //
323 // VerboseObject
324 //
325 
326 
327 // Public static member functions
328 
329 
330 template<class ObjectType>
332 {
333  privateDefaultVerbLevel() = defaultVerbLevel;
334 }
335 
336 
337 template<class ObjectType>
339 {
340  return privateDefaultVerbLevel();
341 }
342 
343 
344 // Constructors/Initializers
345 
346 
347 template<class ObjectType>
349  const EVerbosityLevel verbLevel,
350  const RCP<FancyOStream> &oStream
351  )
352  : thisOverridingVerbLevel_(VERB_DEFAULT)
353 {
354  this->initializeVerboseObject(verbLevel,oStream);
355 }
356 
357 
358 template<class ObjectType>
360  const EVerbosityLevel verbLevel,
361  const RCP<FancyOStream> &oStream
362  )
363 {
364  thisVerbLevel_ = verbLevel;
365  this->initializeVerboseObjectBase(oStream);
366 }
367 
368 
369 template<class ObjectType>
372 {
373  thisVerbLevel_ = verbLevel;
374  informUpdatedVerbosityState();
375  return *this;
376 }
377 
378 
379 template<class ObjectType>
382  const EVerbosityLevel verbLevel
383  ) const
384 {
385  thisOverridingVerbLevel_ = verbLevel;
386  informUpdatedVerbosityState();
387  return *this;
388 }
389 
390 
391 // Query functions
392 
393 
394 template<class ObjectType>
396 {
397  if (VERB_DEFAULT != thisOverridingVerbLevel_)
398  return thisOverridingVerbLevel_;
399  if (VERB_DEFAULT == thisVerbLevel_)
400  return getDefaultVerbLevel();
401  return thisVerbLevel_;
402 }
403 
404 
405 // Private static members
406 
407 
408 template<class ObjectType>
410 {
411  static EVerbosityLevel defaultVerbLevel = VERB_DEFAULT;
412  return defaultVerbLevel;
413 }
414 
415 
416 } // namespace Teuchos
417 
418 
419 #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...
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.