The following functions support writing to a std::ostream* If the pointer is 0 (null), nothing is written. More...
#include <debug.h>
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_ptr & | operator= (std::ostream *ostrm) |
| Update the underlying std::ostream pointer using assignment. | |
Private Attributes | |
| std::ostream * | os |
Friends | |
| template<typename T > | |
| ostream_ptr & | operator<< (ostream_ptr &osp, const T &t) |
| Generic writing to an ostream_ptr. | |
| template<typename T > | |
| ostream_ptr & | operator<< (ostream_ptr &osp, const T *t) |
| Specialization for writing a pointer to an ostream_ptr. | |
| ostream_ptr & | operator<< (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. | |
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.
Definition at line 41 of file debug.h.
| Dv::ostream_ptr::ostream_ptr | ( | std::ostream * | ostrm = 0 |
) | [inline] |
| bool Dv::ostream_ptr::null | ( | ) | const [inline] |
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.
| ostrm | new underlying std::ostream pointer or 0 |
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] |
| ostream_ptr& Dv::ostream_ptr::operator= | ( | std::ostream * | ostrm | ) | [inline] |
Update the underlying std::ostream pointer using assignment.
| ostrm | new underlying std::ostream pointer or 0 |
Definition at line 81 of file debug.h.
References set_os().
| 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.
| osp | ostream_ptr with underlying stream (or 0) to write to | |
| t | object to write |
| 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.
| osp | ostream_ptr with underlying stream (or 0) to write to | |
| t | object to write |
| 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.
| osp | stream to write to | |
| pf | io manipulator to write |
std::ostream* Dv::ostream_ptr::os [private] |
| dvutil-1.0.10 | [ 5 December, 2009] |