//============================================================================== // incharfilter.cpp // Generic input 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/incharfilter.cpp $Revision: 1.1 $$Date: 2010/05/08 16:44:40 $"; // 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 "incharfilter.hpp" //------------------------------------------------------------------------------ // InCharFilter::~InCharFilter() // Destructor. //------------------------------------------------------------------------------ /*virtual*/ InCharFilter::~InCharFilter() { #if InCharFilter_VS != 100 #error class InCharFilter has changed #endif // De-initialize close(); } //------------------------------------------------------------------------------ // InCharFilter::InCharFilter() // Constructor. //------------------------------------------------------------------------------ InCharFilter::InCharFilter(): InCharStream(), m_in(NULL) { #if InCharFilter_VS != 100 #error class InCharFilter has changed #endif // Initialize } //------------------------------------------------------------------------------ // InCharFilter::InCharFilter() // Constructor. //------------------------------------------------------------------------------ InCharFilter::InCharFilter(InCharStream *in): InCharStream(), m_in(in) { #if InCharFilter_VS != 100 #error class InCharFilter has changed #endif // Initialize } //------------------------------------------------------------------------------ // InCharFilter::open() // Open an existing stream as an input stream. //------------------------------------------------------------------------------ bool InCharFilter::open(InCharStream *in) { #if InCharFilter_VS/100 != 1 #error class InCharFilter has changed #endif // Sanity check if (in == NULL) return false; // Establish the underlying input stream m_in = in; return true; } //------------------------------------------------------------------------------ // InCharFilter::getStream() // Retrieve the underlying input stream. //------------------------------------------------------------------------------ InCharStream * InCharFilter::getStream() const { #if InCharFilter_VS/100 != 1 #error class InCharFilter has changed #endif // Get the underlying input stream return m_in; } //------------------------------------------------------------------------------ // InCharFilter::close() // Close the input stream. //------------------------------------------------------------------------------ /*virtual*/ bool InCharFilter::close() { #if InCharFilter_VS/100 != 1 #error class InCharFilter has changed #endif // Close the underlying input stream if (m_in != NULL) return m_in->close(); return true; } //------------------------------------------------------------------------------ // InCharFilter::read() // Read a character from the input stream. // // Returns // A Unicode character code in the range [0x0000,0xFFFF], or // CH_EOLN if a newline sequence was read, or // CH_EOF if the end of the stream (end of file) was reached. //------------------------------------------------------------------------------ /*virtual*/ int InCharFilter::read() { #if InCharFilter_VS/100 != 1 #error class InCharFilter has changed #endif // Read a single char from the underlying input stream if (m_in != NULL) return m_in->read(); return CH_EOF; } //------------------------------------------------------------------------------ // InCharFilter::read() // Read characters from the input stream. // // Returns // Number of characters written into 'buf', or -1 if the end of the stream // (end of file) was reached. // Note that newline sequences are written into 'buf' as CH_EOLN codes. //------------------------------------------------------------------------------ /*virtual*/ int InCharFilter::read(int buf[], int len) { #if InCharFilter_VS/100 != 1 #error class InCharFilter has changed #endif // Read characters from the underlying input stream if (m_in != NULL) return m_in->read(buf, len); return -1; } // End incharfilter.cpp