This reference page is linked to from the following overview topics: Unicode.
#include <maxtextfile.h>
This class is used to access text file with both reader and writer functionality.
Public Member Functions |
|
ReaderWriter () | |
Default Constructor. |
|
virtual | ~ReaderWriter () |
Destructor. |
|
bool | Open (const MCHAR *fileName, unsigned int streamMode, unsigned int encoding=0, LineEndMode mode=Text) |
Open a file using a file name. |
|
bool | Open (const MaxSDK::Util::MaxString &fileName, unsigned int streamMode, unsigned int encoding=0, LineEndMode mode=Text) |
Open a file using a file name. |
|
void | Close () |
Close the opened file. |
|
void | Flush () |
Flush to file the cached data. |
|
virtual size_t | Seek (long offset, int origin) |
Seek inside the file. |
|
virtual Char | ReadChar (bool peek=false) const |
Read a character from the file. |
|
virtual unsigned int | ReadCharUTF32 (bool peek=false) const |
Read a char in UTF32 encoding. |
|
virtual MaxString | ReadChars (size_t nchars) const |
Reads characters from the file. |
|
virtual MaxString | ReadLine (size_t nchars=(size_t)-1, bool dontReturnEOL=false) const |
Read a line from the file. |
|
virtual bool | IsEndOfFile () const |
Used to determine if we read the end of
file. |
|
virtual size_t | Position () const |
used to determine the current position in
the file |
|
virtual size_t | LineNumber () const |
Used to obtain the current line number.
|
|
virtual size_t | UnreadChar (const Char &c) |
Unread the passed character. |
|
virtual size_t | Write (const char *string, size_t nchars=(size_t)-1) |
Write string to file. |
|
virtual size_t | Write (const wchar_t *string, size_t nchars=(size_t)-1) |
Write string to file. |
|
virtual size_t | Write (const MaxString &string) |
Write string to file. |
|
virtual bool | CanWrite () const |
Determine if we can write to the file.
|
|
virtual bool | IsFileOpen () const |
Returns true if file is open. |
|
void | EnsureAllocated (size_t s) |
Protected Member Functions |
|
bool | Open (BinaryStream *stream, unsigned int streamMode, unsigned int encoding, LineEndMode mode=Text, bool closeOnDelete=true) |
Open a file or stream for both read and
write actions. |
|
size_t | SeekToAbsolute (long offset) |
Used to seek to a position in the file.
|
|
size_t | SeekToEnd (long offset=0) |
Used to seek to end. |
|
size_t | SeekFromCurrent (long offset) |
Advance "offset" characters. |
|
virtual size_t | Unread (const MaxString &string) |
Unread the passed string. |
|
Protected Attributes |
|
BinaryStream * | _stream |
bool | _closeOnDelete |
unsigned int | _streamMode |
LineEndMode | _endOfLineMode |
unsigned int | _encoding |
unsigned int * | _chars |
size_t | _allocated |
size_t | _len |
size_t | _pos |
bool | _dirty |
Friends |
|
class | CharBinaryStream |
ReaderWriter | ( | ) |
Default Constructor.
virtual ~ReaderWriter | ( | ) | [virtual] |
Destructor.
bool Open | ( | BinaryStream * | stream, |
unsigned int | streamMode, | ||
unsigned int | encoding, | ||
LineEndMode | mode = Text , |
||
bool | closeOnDelete =
true |
||
) | [protected] |
Open a file or stream for both read and write actions.
[in,out] | stream | If non-null, the stream. |
encoding | The file encoding or preferred encoding | |
streamMode | Streaming mode |
LineEndMode | Text file end of line termination mode. Default Text |
closeOnDelete | true to close on delete. Default true |
size_t SeekToAbsolute | ( | long | offset | ) | [protected] |
Used to seek to a position in the file.
nchars | Position we which we want to position the cursor. |
size_t SeekToEnd | ( | long | offset = 0 |
) | [protected] |
Used to seek to end.
nchars | The nchars. |
size_t SeekFromCurrent | ( | long | offset | ) | [protected] |
Advance "offset" characters.
virtual size_t Unread | ( | const MaxString & | string | ) | [protected, virtual] |
Unread the passed string.
string | The string that will be put back into the buffer |
bool Open | ( | const MCHAR * | fileName, |
unsigned int | streamMode, | ||
unsigned int | encoding = 0 , |
||
LineEndMode | mode = Text |
||
) |
Open a file using a file name.
fileName | File name to open. If file does not exist, it will be created. |
streamMode | Streaming mode |
encoding | This parameter can contains hint to the detection algorithm. Acceptable values are all codepages numbers that are recognized by Windows. |
In addition to that, you can also specify FAVOR_UTF8. It can be used to cascade the detection of the codepage. For example, if you specify "CP_ACP | FAVOR_UTF8", the detection algorithm will treat any non-UTF8 data as ACP.
mode |
bool Open | ( | const MaxSDK::Util::MaxString & | fileName, |
unsigned int | streamMode, | ||
unsigned int | encoding = 0 , |
||
LineEndMode | mode = Text |
||
) |
Open a file using a file name.
fileName | File name to open. If file does not exist, it will be created. |
streamMode | Streaming mode |
encoding | This parameter can contains hint to the detection algorithm. Acceptable values are all codepages numbers that are recognized by Windows. |
In addition to that, you can also specify FAVOR_UTF8. It can be used to cascade the detection of the codepage. For example, if you specify "CP_ACP | FAVOR_UTF8", the detection algorithm will treat any non-UTF8 data as ACP.
mode |
void Close | ( | ) |
Close the opened file.
void Flush | ( | ) | [virtual] |
virtual size_t Seek | ( | long | offset, |
int | origin | ||
) | [virtual] |
Seek inside the file.
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 BaseTextReader.
virtual Char ReadChar | ( | bool | peek = false |
) | const [virtual] |
Read a character from the file.
peek | Read a char but does not move the internal pointer to next char. |
Implements BaseTextReader.
virtual unsigned int ReadCharUTF32 | ( | bool | peek = false |
) | const [virtual] |
Read a char in UTF32 encoding.
peek | Read a char but does not move the internal pointer to next char. |
Implements BaseTextReader.
virtual MaxString ReadChars | ( | size_t | nchars | ) | const [virtual] |
Reads characters from the file.
nchars | Stop reading after 'nchars' characters. |
Implements BaseTextReader.
virtual MaxString ReadLine | ( | size_t | nchars =
(size_t)-1 , |
bool | dontReturnEOL =
false |
||
) | const [virtual] |
Read a line from the file.
nchars | Max number of characters to read Default -1 - read until end of line character |
dontReturnEOL | Control if end of line character is in the returned string |
Implements BaseTextReader.
virtual bool IsEndOfFile | ( | ) | const [virtual] |
Used to determine if we read the end of file.
Implements BaseTextReader.
virtual size_t Position | ( | ) | const [virtual] |
used to determine the current position in the file
Implements BaseTextReader.
virtual size_t LineNumber | ( | ) | const [virtual] |
virtual size_t UnreadChar | ( | const Char & | c | ) | [virtual] |
Unread the passed character.
c | The character that will be put back into the buffer |
Implements BaseTextReader.
virtual size_t Write | ( | const char * | string, |
size_t | nchars =
(size_t)-1 |
||
) | [virtual] |
Write string to file.
string | The string to write |
nchars | The number of characters to write. Alternatively, this parameter can be set to -1 if the string is null-terminated. Note that, if string is NULL, the function fails. If this parameter is -1, the function processes the entire input string, up to the terminating NULL. If this parameter is set to a positive integer, the function processes exactly the specified number of characters up to the terminating NULL. |
Implements BaseTextWriter.
virtual size_t Write | ( | const wchar_t * | string, |
size_t | nchars =
(size_t)-1 |
||
) | [virtual] |
Write string to file.
string | The string to write |
nchars | The number of characters to write. Alternatively, this parameter can be set to -1 if the string is null-terminated. Note that, if string is NULL, the function fails. If this parameter is -1, the function processes the entire input string, up to the terminating NULL. If this parameter is set to a positive integer, the function processes exactly the specified number of characters up to the terminating NULL. |
Implements BaseTextWriter.
virtual size_t Write | ( | const MaxString & | string | ) | [virtual] |
Write string to file.
string | The string to write |
Implements BaseTextWriter.
virtual bool CanWrite | ( | ) | const [virtual] |
Determine if we can write to the file.
Implements BaseTextWriter.
virtual bool IsFileOpen | ( | ) | const [virtual] |
void EnsureAllocated | ( | size_t | s | ) |
friend class CharBinaryStream
[friend] |
BinaryStream*
_stream [protected] |
bool
_closeOnDelete [protected] |
unsigned int
_streamMode [protected] |
LineEndMode
_endOfLineMode [protected] |
unsigned int
_encoding [protected] |
unsigned int*
_chars [protected] |
size_t
_allocated [protected] |
size_t
_len [mutable, protected] |
size_t
_pos [mutable, protected] |
bool
_dirty [protected] |