Dv::ostream_ptr Class Reference

The following functions support writing to a std::ostream* If the pointer is 0 (null), nothing is written. More...

#include <debug.h>

List of all members.

Public Member Functions

 ostream_ptr (std::ostream *ostrm=0)
 Constructor.
 ~ostream_ptr ()
 Destructor.
bool null () const
std::ostream * set_os (std::ostream *ostrm)
 Update the underlying std::ostream pointer.
std::ostream * ostrm () const
ostream_ptroperator= (std::ostream *ostrm)
 Update the underlying std::ostream pointer using assignment.

Private Attributes

std::ostream * os

Friends

template<typename T >
ostream_ptroperator<< (ostream_ptr &osp, const T &t)
 Generic writing to an ostream_ptr.
template<typename T >
ostream_ptroperator<< (ostream_ptr &osp, const T *t)
 Specialization for writing a pointer to an ostream_ptr.
ostream_ptroperator<< (ostream_ptr &osp, std::ostream &(*pf)(std::ostream &))
 This function supports writing some io manipulators such as std::endl or std::setw to an ostream_ptr.

Detailed Description

The following functions support writing to a std::ostream* If the pointer is 0 (null), nothing is written.

Otherwise, operator<< behaves as on std::ostream.

This is useful e.g. when one has a

 std::ostream* log;

variable which may be 0 (if logging is turned off). One may then write

 ostream_ptr(log) << "blabla" << std::endl;

instead of cluttering with

 if (log)
   *log << "blabla" << std::endl;

Note that in order to support

  operator<<(ostream_ptr& osp, const T& t) {

we need to package std::ostream* into its own class since overloaded operators need at least one user defined operand type.

See also:
Dv::Debugable
Dv::DebuSlave
Dv::Debug

Definition at line 41 of file debug.h.


Constructor & Destructor Documentation

Dv::ostream_ptr::ostream_ptr ( std::ostream *  ostrm = 0  )  [inline]

Constructor.

Parameters:
ostrm underlying std::ostream pointer or 0

Definition at line 46 of file debug.h.

Dv::ostream_ptr::~ostream_ptr (  )  [inline]

Destructor.

Definition at line 50 of file debug.h.


Member Function Documentation

bool Dv::ostream_ptr::null (  )  const [inline]
Returns:
true if this is a null Dv::ostream_ptr, i.e. the underlying std::ostream pointer is 0

Definition at line 56 of file debug.h.

References os.

std::ostream* Dv::ostream_ptr::set_os ( std::ostream *  ostrm  )  [inline]

Update the underlying std::ostream pointer.

Parameters:
ostrm new underlying std::ostream pointer or 0
Returns:
old underlying std::ostream pointer

Definition at line 63 of file debug.h.

References os.

Referenced by operator=(), and Dv::Debug::set_log().

std::ostream* Dv::ostream_ptr::ostrm (  )  const [inline]

Definition at line 71 of file debug.h.

References os.

ostream_ptr& Dv::ostream_ptr::operator= ( std::ostream *  ostrm  )  [inline]

Update the underlying std::ostream pointer using assignment.

Parameters:
ostrm new underlying std::ostream pointer or 0
Returns:
*this
See also:
Dv::ostream_ptr::set_os

Definition at line 81 of file debug.h.

References set_os().


Friends And Related Function Documentation

template<typename T >
ostream_ptr& operator<< ( ostream_ptr osp,
const T &  t 
) [friend]

Generic writing to an ostream_ptr.

If the underlying stream is 0, nothing will be written, obviously.

Parameters:
osp ostream_ptr with underlying stream (or 0) to write to
t object to write
Returns:
osp, which may have been zeroed if the write operation failed

Definition at line 95 of file debug.h.

template<typename T >
ostream_ptr& operator<< ( ostream_ptr osp,
const T *  t 
) [friend]

Specialization for writing a pointer to an ostream_ptr.

If the underlying stream is 0, nothing will be written, obviously.

Parameters:
osp ostream_ptr with underlying stream (or 0) to write to
t object to write
Returns:
osp, which may have been zeroed if the write operation failed

Definition at line 112 of file debug.h.

ostream_ptr& operator<< ( ostream_ptr osp,
std::ostream &(*)(std::ostream &)  pf 
) [friend]

This function supports writing some io manipulators such as std::endl or std::setw to an ostream_ptr.

Parameters:
osp stream to write to
pf io manipulator to write
Returns:
osp, which may have been zeroed if the write operation failed

Definition at line 128 of file debug.h.


Member Data Documentation

std::ostream* Dv::ostream_ptr::os [private]

Definition at line 137 of file debug.h.

Referenced by null(), ostrm(), and set_os().


The documentation for this class was generated from the following file:

dvutil-1.0.10 [ 5 December, 2009]