This reference page is linked to from the following overview topics: Unicode.
#include <maxtextfile.h>
Write Text files.
This class was intended to be used to write text file. It differ from the ANSI fopen, fprintf, et al, because it's smarter when it's to modify existing files. It detect the underlying file format and match it intelligently.
It was designed to resolve the following problems: * Avoid mixing different text format in the same file. * Convert intelligently strings into binary data.
Public Types |
|
enum | TextFileWriterEncoding { FAVOR_UTF8 = 0x10000000, WRITE_BOM = 0x20000000, FLIPPED = 0x80000000 } |
Public Member Functions |
|
bool | Open (FILE *file, bool append=false, unsigned int encoding=0, LineEndMode mode=Text) |
Bind on a FILE pointer. |
|
bool | Open (HANDLE fileHandle, bool append=false, unsigned int encoding=0, LineEndMode mode=Text) |
Bind on a file File handle This service is
used to allow a developer to access a file open with fopen but with
the advantage to use the SDK API. |
|
Writer () | |
Default Constructor. |
|
virtual | ~Writer () |
Destructor. |
|
bool | Open (const MCHAR *fileName, bool append=false, unsigned int encoding=0, LineEndMode mode=Text) |
Open a file. |
|
bool | Open (const MaxString &fileName, bool append=false, unsigned int encoding=0, LineEndMode mode=Text) |
Open a file. |
|
void | Close () |
Close the file. |
|
MaxString | LastError () const |
Returns the last error return by the
BinaryStream.
|
|
unsigned int | Encoding () const |
Returns the actual encoding used. |
|
size_t | Write (const char *string, size_t nbchars=(size_t)-1) |
Write string to file. |
|
size_t | Write (const wchar_t *string, size_t nbchars=(size_t)-1) |
Write string to file. |
|
size_t | Write (const MaxString &string) |
Write string to file. |
|
size_t | WriteChar (char character) |
Write an ASCII char. |
|
size_t | WriteChar (wchar_t character) |
Write an ASCII char. |
|
bool | CanWrite () const |
Returns true if we can write to file.
|
|
virtual bool | IsFileOpen () const |
Returns true if file is open. |
|
virtual bool | IsEndOfFile () const |
Returns true if file pointer is at end if
file. |
|
virtual size_t | Position () const |
Get the current position in the file.
|
|
virtual size_t | Seek (long offset, int origin) |
Seek inside the stream. |
|
void | Flush () |
Make sure that all the buffer are synced
with the OS native objects. |
|
Protected Types |
|
enum |
TextFileWriterError { ALL_OK, STREAM_INVALID_ARGUMENT, STREAM_ALREADY_OPEN, STREAM_NOT_OPEN, ERROR_PRINTING_BUFFER, ERROR_ALLOCATING_MEMORY, STREAM_ERROR } |
Internal processing error code.
More... |
|
Protected Member Functions |
|
bool | Open (BinaryStream *stream, bool append=false, unsigned int encoding=0, LineEndMode mode=Text, bool closeOnDelete=false) |
Open an abstract BinaryStream.
|
|
Protected Attributes |
|
BinaryStream * | _stream |
bool | _streamDelete |
bool | _append |
unsigned int | _encoding |
LineEndMode | _endOfLineMode |
TextFileWriterError | _error |
Friends |
|
class | ReaderWriter |
class | CharBinaryStream |
class | TextFileWriterTest |
enum
TextFileWriterError [protected] |
Internal processing error code.
Used by LastError to determine the proper message to generate.
{ /* If the file's encoding cannot be detected, favor UTF-8. By default, we favor ACP encoding. */ FAVOR_UTF8 = 0x10000000, /* Write a BOM at the beginning of the file. */ WRITE_BOM = 0x20000000, /* Write flipped UTF-16 data. */ FLIPPED = 0x80000000 };
Writer | ( | ) |
Default Constructor.
virtual ~Writer | ( | ) | [virtual] |
Destructor.
bool Open | ( | BinaryStream * | stream, |
bool | append = false , |
||
unsigned int | encoding = 0 , |
||
LineEndMode | mode = Text , |
||
bool | closeOnDelete =
false |
||
) | [protected] |
Open an abstract BinaryStream.
stream | Stream that the TextFile::Writer must use |
append | Append to file or truncate file |
encoding | If the stream actually contains any data and append is true, it will detect it's format and match it. You can hint the detection algorithm by using FAVOR_UTF8. If the stream is empty, it will use the code page specified here. You can mix it with "WRITE_BOM" and/or "FLIPPED" bits. |
mode |
closeOnDelete | Delete the "stream" at the same time of this object. Default false |
bool Open | ( | FILE * | file, |
bool | append = false , |
||
unsigned int | encoding = 0 , |
||
LineEndMode | mode = Text |
||
) |
Bind on a FILE pointer.
file | File pointer to use User is responsible for closing the file. |
append | Append to file or truncate file |
encoding | If the stream actually contains any data and append is true, it will detect it's format and match it. You can hint the detection algorithm by using FAVOR_UTF8. If the stream is empty, it will use the code page specified here. You can mix it with "WRITE_BOM" and/or "FLIPPED" bits. |
mode |
bool Open | ( | HANDLE | fileHandle, |
bool | append = false , |
||
unsigned int | encoding = 0 , |
||
LineEndMode | mode = Text |
||
) |
Bind on a file File handle This service is used to allow a developer to access a file open with fopen but with the advantage to use the SDK API.
Using this service allows the developer to now worry about character encoding The developer is responsible to close the file once he is done.
file | File handle to use User is responsible for closing the file. |
append | Append to file or truncate file |
encoding | If the stream actually contains any data and append is true, it will detect it's format and match it. You can hint the detection algorithm by using FAVOR_UTF8. If the stream is empty, it will use the code page specified here. You can mix it with "WRITE_BOM" and/or "FLIPPED" bits. |
mode |
bool Open | ( | const MCHAR * | fileName, |
bool | append = false , |
||
unsigned int | encoding = 0 , |
||
LineEndMode | mode = Text |
||
) |
Open a file.
fileName | File name to open |
append | Append to file or truncate file |
encoding | If the stream actually contains any data and append is true, it will detect it's format and match it. You can hint the detection algorithm by using FAVOR_UTF8. If the stream is empty, it will use the code page specified here. You can mix it with "WRITE_BOM" and/or "FLIPPED" bits. |
mode |
bool Open | ( | const MaxString & | fileName, |
bool | append = false , |
||
unsigned int | encoding = 0 , |
||
LineEndMode | mode = Text |
||
) |
Open a file.
fileName | File name to open |
append | Append to file or truncate file |
encoding | If the stream actually contains any data and append is true, it will detect it's format and match it. You can hint the detection algorithm by using FAVOR_UTF8. If the stream is empty, it will use the code page specified here. You can mix it with "WRITE_BOM" and/or "FLIPPED" bits. |
mode |
void Close | ( | ) |
Close the file.
MaxString LastError | ( | ) | const |
Returns the last error return by the BinaryStream.
unsigned int Encoding | ( | ) | const |
Returns the actual encoding used.
size_t Write | ( | const char * | string, |
size_t | nbchars =
(size_t)-1 |
||
) | [virtual] |
Write string to file.
string | The string to write |
nbchars | The size of the string in characters. -1 will write all chars up to '\0' |
Implements BaseTextWriter.
size_t Write | ( | const wchar_t * | string, |
size_t | nbchars =
(size_t)-1 |
||
) | [virtual] |
Write string to file.
string | The string to write. |
nbchars | The size of the string in characters. -1 will write all chars up to '\0' |
Implements BaseTextWriter.
size_t Write | ( | const MaxString & | string | ) | [virtual] |
Write string to file.
string | The string to write |
Implements BaseTextWriter.
size_t WriteChar | ( | char | character | ) |
Write an ASCII char.
character | The character to write |
size_t WriteChar | ( | wchar_t | character | ) |
Write an ASCII char.
character | The character to write |
bool CanWrite | ( | ) | const [virtual] |
virtual bool IsFileOpen | ( | ) | const [virtual] |
virtual bool IsEndOfFile | ( | ) | const [virtual] |
Returns true if file pointer is at end if file.
Implements BaseTextWriter.
virtual size_t Position | ( | ) | const [virtual] |
virtual size_t Seek | ( | long | offset, |
int | origin | ||
) | [virtual] |
Seek inside the stream.
offset | The seeks operations are done in number of characters (not bytes). |
origin | The direction to move. Origin can be one of the following * SEEK_CUR Current position of file pointer. * SEEK_END End of file. * SEEK_SET Beginning of file. |
Implements BaseTextWriter.
void Flush | ( | ) | [virtual] |
Make sure that all the buffer are synced with the OS native objects.
Implements BaseTextWriter.
friend class ReaderWriter
[friend] |
friend class CharBinaryStream
[friend] |
friend class TextFileWriterTest
[friend] |
BinaryStream*
_stream [protected] |
bool
_streamDelete [protected] |
bool
_append [protected] |
unsigned int
_encoding [protected] |
LineEndMode
_endOfLineMode [protected] |
TextFileWriterError
_error [mutable, protected] |