//============================================================================== // outcharfilter.hpp // 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. //============================================================================== #ifndef drt_lib_outcharfilter_hpp #define drt_lib_outcharfilter_hpp 101 // Identification #ifndef NO_H_IDENT static char drt_lib_outcharfilter_hpp_REV[] = "@(#)drt/src/lib/outcharfilter.hpp $Revision: 1.1 $$Date: 2010/05/08 17:08:04 $"; #endif // Includes #ifndef sys_stdio_h #include #define sys_stdio_h #endif #ifndef drt_lib_chartream_hpp #include "charstream.hpp" #endif #ifndef drt_lib_outcharstream_hpp #include "outcharstream.hpp" #endif //------------------------------------------------------------------------------ // class OutCharFilter // Controls the writing of data for an output text file from another // underlying input character stream. // // Handles the following file encodings: // 8-bit (ASCII or ISO 8859-1) // 7-bit, with none(space)/mark/even/odd parity modes // UTF-8 // UTF-16 (big-endian) // UTF-16 reversed (little-endian) // UTF-32 (big-endian) // UTF-32 reversed (little-endian) // 24-bit (big-endian) (non-standard) // 24-bit reversed (little-endian) (non-standard) // // Handles the following newline sequences: // CR (0D) // LF (0A) // CR LF (0D 0A) // NEL (85) // None //------------------------------------------------------------------------------ #define OutCharFilter_VS 100 // Class version class OutCharFilter: public OutCharStream { #if CharStream_VS/100 != 1 #error class CharStream has changed #endif #if OutCharStream_VS/100 != 1 #error class OutCharStream has changed #endif // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // Functions public: virtual /**/ ~OutCharFilter(); // Destructor /**/ OutCharFilter(); // Constructor /**/ OutCharFilter(OutCharStream *out); // Constructor bool open(OutCharStream *out); // Open an output stream OutCharStream * getStream() const; // Get output stream virtual bool close(); // Close the stream virtual bool flush(); // Flush pending output virtual bool write(int ch); // Write a Unicode char virtual int write(const char *s); // Write a string virtual int write(const int buf[], int len); // Write Unicode chars virtual bool writeln(); // Write a newline private: /**/ OutCharFilter(const OutCharFilter &o); const OutCharFilter & operator =(const OutCharFilter &o); // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // Variables protected: OutCharStream * m_out; // Output stream }; #endif // drt_lib_outcharfilter_hpp // End outcharfilter.hpp