core/vul/vul_redirector.h
Go to the documentation of this file.
00001 // This is core/vul/vul_redirector.h
00002 #ifndef vul_redirector_h_
00003 #define vul_redirector_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Contains class for simplified redirection of iostreams
00010 // \author awf@robots.ox.ac.uk
00011 //
00012 // \verbatim
00013 //  Modifications
00014 //   21-JUL-00  M.Bacic, Oxford RRG -- fixed 'pubsync' on gcc.
00015 //   PDA (Manchester) 21/03/2001: Tidied up the documentation
00016 //   Feb.2002 - Peter Vanroose - brief doxygen comment placed on single line
00017 // \endverbatim
00018 
00019 #include <vcl_iostream.h>
00020 
00021 struct vul_redirector_data;
00022 
00023 //: Simplified redirection of iostreams
00024 // To implement your own, derive a class from vul_redirector,
00025 // and implement `putchunk'.
00026 class vul_redirector
00027 {
00028  public:
00029   //: Attach redirector to vcl_ostream s, so that all future output to s goes through this->putchunk
00030   vul_redirector(vcl_ostream& s);
00031 
00032   //: Destroy redirector, restore stream to original.
00033   virtual ~vul_redirector();
00034 
00035   //: The filter function
00036   // Called with `n' characters in `buf', do with as you like.
00037   virtual vcl_streamsize putchunk(char const* buf, vcl_streamsize n);
00038 
00039  protected:
00040   //: Put characters to original stream.
00041   // Useful for derived classes which wish to filter a stream.
00042   vcl_streamsize put_passthru(char const* buf, vcl_streamsize n);
00043 
00044   //: Sync original stream.
00045   int sync_passthru();
00046 
00047  private:
00048   vul_redirector_data* p;
00049 };
00050 
00051 #endif // vul_redirector_h_