//============================================================================== // outtextstream.hpp // Generic output text stream. // // Notice // Copyright ©2008-2011 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_outtextstream_hpp #define drt_lib_outtextstream_hpp 102 // Identification #ifndef NO_H_IDENT static char drt_lib_outtextstream_hpp_REV[] = "@(#)drt/src/lib/outtextstream.hpp $Revision: 1.2 $$Date: 2011/04/30 00:35:31 $"; #endif // Includes #ifndef sys_stdio_h #include #define sys_stdio_h #endif #ifndef drt_lib_textstream_hpp #include "textstream.hpp" #endif //------------------------------------------------------------------------------ // class OutTextStream // Controls the writing of data for an output text file. // // 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 OutTextStream_VS 201 // Class version class OutTextStream: public TextStream { #if TextStream_VS/100 != 2 #error class TextStream has changed #endif // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // Constants private: static const unsigned char parity_even[128]; // 7-bit even parity // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // Static functions private: static int put_8bit(FILE *out, int ch); // Write an 8-bit char static int put_7none(FILE *out, int ch); // Write 7-bit none static int put_7mark(FILE *out, int ch); // Write 7-bit mark static int put_7even(FILE *out, int ch); // Write 7-bit even static int put_7odd(FILE *out, int ch); // Write 7-bit odd static int put_utf8(FILE *out, int ch); // Write a UTF-8 char static int put_utf16(FILE *out, int ch); // Write a UTF-16BE char static int put_utf16r(FILE *out, int ch); // Write a UTF-16LE char static int put_utf32(FILE *out, int ch); // Write a UTF-32BE char static int put_utf32r(FILE *out, int ch); // Write a UTF-32LE char static int put_24bit(FILE *out, int ch); // Write 24-bit BE char static int put_24bitr(FILE *out, int ch); // Write 24-bit LE char // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // Functions public: virtual /**/ ~OutTextStream(); // Destructor /**/ OutTextStream(); // Constructor virtual bool open(const char *fname, enum FileType ftype, enum EolnType eoln); // Open a file stream virtual bool open(FILE *fp, enum FileType ftype, enum EolnType eoln); // Open an I/O stream virtual bool close(); // Close the stream bool flush(); // Flush pending output bool write(int ch); // Write a Unicode char int write(const char *s); // Write a string int write(const int buf[], int len); // Write Unicode chars bool writeln(); // Write a newline private: /**/ OutTextStream(const OutTextStream &o); const OutTextStream & operator =(const OutTextStream &o); bool openPrep(enum FileType ftype, enum EolnType eoln); // Prepare to open a stream // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // Variables protected: int (*m_put)(FILE *out, int ch); // Write a char }; #endif // drt_lib_outtextstream_hpp // End outtextstream.hpp