Oncaphillis::niftyLib

niftyLib::IO::time_log_filter Class Reference

#include <io/time_log_filter.h>

Inheritance diagram for niftyLib::IO::time_log_filter:
Collaboration diagram for niftyLib::IO::time_log_filter:

Detailed Description

A subclass of basic_log_filter which dumps a time-stamp of the current time whenever the streambuf hits a line-feed.

Still very crude:

Example

See also:
basic_log_filter, str_log_filter

Public Types

typedef super::char_type char_type
 We inherit the char_type from our associated output device.
typedef super::traits_type traits_type
 We also inherit the traits_type from our associated output device.
typedef super::device_ptr device_ptr
 Handy typedef for the device we're operating on.

Public Member Functions

 time_log_filter (device_ptr d, bool own=true)
virtual ~time_log_filter ()
virtual std::streamsize line_intro ()
 Method to generate the start of every new line.

Member Typedef Documentation

We inherit the char_type from our associated output device.

This definition has to be here in order to make us work properly with a device_streambuf

Reimplemented from niftyLib::IO::basic_log_filter< char >.

We also inherit the traits_type from our associated output device.

Reimplemented from niftyLib::IO::basic_log_filter< char >.

Handy typedef for the device we're operating on.

Reimplemented from niftyLib::IO::basic_log_filter< char >.


Constructor & Destructor Documentation

niftyLib::IO::time_log_filter::time_log_filter ( device_ptr  d,
bool  own = true 
) [inline]

virtual niftyLib::IO::time_log_filter::~time_log_filter (  )  [inline, virtual]


Member Function Documentation

virtual std::streamsize niftyLib::IO::time_log_filter::line_intro (  )  [inline, virtual]

Method to generate the start of every new line.

This one does nothing and is expected to get overwritten by subclasses doing more sophisticated stuff like dumping out the current date.

One might choose to build up a chane of methods by always calling the line_intro method of the super class. This way one can concatinate the output of various filters.

e.g:

          template<class D>
          class foo_log_filter : public log_filter<D> {
           ...
           ...
           std::streamsize line_intro() {
            std::streamsize n = super::line_intro();
            n+=this->raw_write("foo ");
            return n;
           }
          };

          template<class D>
          class bar_log_filter : public log_filter<D> {
           ...
           ...
           std::streamsize line_intro() {
            std::streamsize n = super::line_intro();
            n+=this->raw_write("bar ");
            return n;
           }
          };


          int main() {
           ...
           IO::device<char> * d = new bar_log_filter< foo_log_filter< IO::fd_device<char> > >( new foo_log_filter< IO::fd_device<char> >(new IO::fd_device<char>(1)));
           IO::device_streambuf< IO::device<char> > b(d);
    
           // Finally create a ostream 
           std::ostream os(&b);
    
           for(int i=0;i<3;i++) {
            os << " helloworld" << std::endl;
           }
           ...
           ...
          }

Which should dump out

	   foo bar hello world
	   foo bar hello world
	   foo bar hello world
	  

Of course this kind of cascading template orgy should be hidden nicely within some typedefs or container classes. It's just to tempting to be so ugly.

See also:
write

Reimplemented from niftyLib::IO::basic_log_filter< char >.

References niftyLib::IO::basic_log_filter< char >::line_intro(), and niftyLib::IO::basic_log_filter< char >::raw_write().


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

Generated by  doxygen
© 2008; Dr. Sebastian Kloska ( Oncaphillis )
Powered by: [?]