//============================================================================== // outcharfilter.cpp // Generic output character filter stream. // // Notice // Copyright ©2010 by David R. Tribble, all rights reserved. // Permission is granted to any person or entity except those designated // by the United States Department of State as a terrorist, or terrorist // government or agency, to use and distribute this source code provided // that the original copyright notice remains present and unaltered. //============================================================================== // Identification static char REV[] = "@(#)drt/src/lib/outcharfilter.cpp $Revision: 1.1 $$Date: 2010/05/08 17:08:07 $"; // Includes #include #define sys_ctype_h #include #define sys_errno_h #include #define sys_iso646_h #include #define sys_stdio_h #include #define sys_string_h #include "outcharfilter.hpp" //------------------------------------------------------------------------------ // OutCharFilter::~OutCharFilter() // Destructor. //------------------------------------------------------------------------------ /*virtual*/ OutCharFilter::~OutCharFilter() { #if OutCharFilter_VS != 100 #error class OutCharFilter has changed #endif // De-initialize close(); } //------------------------------------------------------------------------------ // OutCharFilter::OutCharFilter() // Constructor. //------------------------------------------------------------------------------ OutCharFilter::OutCharFilter(): OutCharStream(), m_out(NULL) { #if OutCharFilter_VS != 100 #error class OutCharFilter has changed #endif // Initialize } //------------------------------------------------------------------------------ // OutCharFilter::OutCharFilter() // Constructor. //------------------------------------------------------------------------------ OutCharFilter::OutCharFilter(OutCharStream *out): OutCharStream(), m_out(out) { #if OutCharFilter_VS != 100 #error class OutCharFilter has changed #endif // Initialize } //------------------------------------------------------------------------------ // OutCharFilter::open() // Open an existing stream as an output stream. //------------------------------------------------------------------------------ bool OutCharFilter::open(OutCharStream *out) { #if OutCharFilter_VS/100 != 1 #error class OutCharFilter has changed #endif // Sanity check if (out == NULL) return false; // Establish the underlying output stream m_out = out; return true; } //------------------------------------------------------------------------------ // OutCharFilter::getStream() // Retrieve the underlying output stream. //------------------------------------------------------------------------------ OutCharStream * OutCharFilter::getStream() const { #if OutCharFilter_VS/100 != 1 #error class OutCharFilter has changed #endif // Get the underlying output stream return m_out; } //------------------------------------------------------------------------------ // OutCharFilter::close() // Close the output stream. //------------------------------------------------------------------------------ /*virtual*/ bool OutCharFilter::close() { #if OutCharFilter_VS/100 != 1 #error class OutCharFilter has changed #endif // Close the underlying output stream if (m_out != NULL) return m_out->close(); return true; } //------------------------------------------------------------------------------ // OutCharFilter::flush() // Flush any pending output to the stream. //------------------------------------------------------------------------------ /*virtual*/ bool OutCharFilter::flush() { #if OutCharFilter_VS/100 != 1 #error class OutCharFilter has changed #endif // Flush the underlying output stream if (m_out != NULL) return m_out->flush(); return false; } //------------------------------------------------------------------------------ // OutCharFilter::write() // Write a character to the (output) stream. // // Notes // This function assumes that InCharFilter::write(int[],int) has been // implemented in an overridding subclass. //------------------------------------------------------------------------------ /*virtual*/ bool OutCharFilter::write(int ch) { #if OutCharFilter_VS/100 != 1 #error class OutCharFilter has changed #endif // Write a character to the underlying output stream if (m_out != NULL) return m_out->write(ch); return false; } //------------------------------------------------------------------------------ // OutCharFilter::write() // Write a character string to the (output) stream. // Newline ('\n') characters within 's' cause newlines to be written by // invoking writeln(). // All other control characters are written as is to the output stream. // // Notes // This function assumes that InCharFilter::write(int) has been // implemented in an overridding subclass. // // Return // Number of characters written to the output stream from 'buf'. //------------------------------------------------------------------------------ /*virtual*/ int OutCharFilter::write(const char *s) { #if OutCharFilter_VS/100 != 1 #error class OutCharFilter has changed #endif // Write characters to the underlying output stream if (m_out != NULL) return m_out->write(s); return -1; } //------------------------------------------------------------------------------ // OutCharFilter::write() // Write characters to the (output) stream. // CH_EOLN codes within 'buf' cause newlines to be written by invoking // writeln(). // All other character codes are written as is to the output stream. // // Notes // This function assumes that InCharFilter::write(int) has been // implemented in an overridding subclass. // // Return // Number of characters written to the output stream from 'buf'. //------------------------------------------------------------------------------ /*virtual*/ int OutCharFilter::write(const int buf[], int len) { #if OutCharFilter_VS/100 != 1 #error class OutCharFilter has changed #endif // Write characters to the underlying output stream if (m_out != NULL) return m_out->write(buf, len); return -1; } //------------------------------------------------------------------------------ // OutCharFilter::writeln() // Write a newline sequence to the (output) stream. //------------------------------------------------------------------------------ /*virtual*/ bool OutCharFilter::writeln() { #if OutCharFilter_VS/100 != 1 #error class OutCharFilter has changed #endif // Write a newline to the underlying output stream if (m_out != NULL) return m_out->writeln(); return false; } // End outcharfilter.cpp