Unicorn XML Toolkit
Version 1.50.00

Namespace Unicode
Class CTextFile

class CTextFile: public CInterface {
public:
    enum {
        standardInput,
        standardOutput,
        standardError
        };
    enum {
        fromBegin,
        fromCurrent,
        fromEnd
        };
    enum {
        errOk = 0,
        errFileNotOpen = 10001,
        errFileAlreadyOpen = 10002,
        errInvalidPath = 10003,
        errInvalidMode = 10004,
        errFunctionNotSupported = 10005
        };
public:
    CTextFile();
    CTextFile(int nStandard);
    ~CTextFile();
public:
    static bool Exists(const WCHAR *pszPath);
    static bool Remove(const WCHAR *pszPath);
    static bool Rename(
        const WCHAR *pszOldPath, 
        const WCHAR *pszNewPath);
public:
    void ClearError();
    bool Close();
    bool Eof();
    int Error();
    bool Flush();
    int GetLength();
    int GetPosition();
    bool Open(
        const WCHAR *pszPath, 
        const WCHAR *pszMode, 
        CEncoding *pEncoding=NULL);
    CString Read();
    CString Read(int nCount);
    bool SetPosition(int nPosition, int nFrom=fromBegin);
    bool Write(const WCHAR *pszData);
    bool Write(const WCHAR *pchData, int nCount);
    };
typedef XInterface<CTextFile> XTextFile;

The Unicode-based text file.

The Unicode-based text file contains a Unicode text encoded as a sequence of bytes according to the certain encoding algorithm.

Since:
1.00.00
Version:
1.50.00
Author:
Alexey Gokhberg
See Also:
CEncoding
Constructor/Destructor Summary
CTextFile ();
����������Constructs the text file.
CTextFile (int nStandard);
����������Constructs the text file, mapping one of three standard file streams (standard input, standard output, or standard error output).
~CTextFile ();
����������Destroys the text file.

Function Summary
bool Exists (const WCHAR *pszPath);
����������Tests whether a file with the specified path exists.
bool Remove (const WCHAR *pszPath);
����������Removes (deletes) a file with the specified path.
bool Rename (const WCHAR *pszOldPath, const WCHAR *pszNewPath);
����������Renames a file with the specified path.
void ClearError ();
����������Clears the last error code associated with this file.
bool Close ();
����������Closes this file.
bool Eof ();
����������Tests whether the last read operation on this file attempted to read past the end of file.
int Error ();
����������Returns an error code associated with the last operation performed on this file.
bool Flush ();
����������Flushes a stream associated with this file.
int GetLength ();
����������Returns a length, in bytes, of this file.
int GetPosition ();
����������Returns a current position of the file pointer for this file.
bool Open (const WCHAR *pszPath, const WCHAR *pszMode, CEncoding *pEncoding=NULL);
����������Opens this file, using the specified file path, the specified access mode, and the optional encoding.
CString Read ();
����������Reads a line from this file.
CString Read (int nCount);
����������Reads a specified number of characters from this file.
bool SetPosition (int nPosition, int nFrom=fromBegin);
����������Moves the file pointer to a specified position.
bool Write (const WCHAR *pszData);
����������Writes the specified string to this file.
bool Write (const WCHAR *pchData, int nCount);
����������Writes the array of characters to this file.

Constructor/Destructor Detail

CTextFile

CTextFile();

Constructs the text file.

CTextFile

CTextFile(int nStandard);

Constructs the text file, mapping one of three standard file streams (standard input, standard output, or standard error output).

The parameter nStandard is used to specify the standard stream. Allowed values are: standardInput , standardOutput , and standardError .

Parameters:
nStandard - the code of the standard stream

~CTextFile

~CTextFile();

Destroys the text file.

Function Detail

Exists

static bool Exists(const WCHAR *pszPath);

Tests whether a file with the specified path exists.

The syntax of the file path is platform-dependent.

Parameters:
pszPath - the file path
Returns:
true if a file with the specified path exists; false otherwise

Remove

static bool Remove(const WCHAR *pszPath);

Removes (deletes) a file with the specified path.

The syntax of the file path is platform-dependent.

Parameters:
pszPath - the file path
Returns:
true if the file was successfully removed; false otherwise

Rename

static bool Rename(
    const WCHAR *pszOldPath, 
    const WCHAR *pszNewPath);

Renames a file with the specified path.

The syntax of the file path is platform-dependent.

Parameters:
pszOldPath - the original file path
pszNewPath - the new file path
Returns:
true if the file was successfully renamed; false otherwise

ClearError

void ClearError();

Clears the last error code associated with this file.

Close

bool Close();

Closes this file.

Operation failes if this file is not open.

Returns:
true if this file was successfully closed; false otherwise

Eof

bool Eof();

Tests whether the last read operation on this file attempted to read past the end of file.

Operation failes if this file is not open.

Returns:
true if the last read operation on this file attempted to read past the end of file; false otherwise

Error

int Error();

Returns an error code associated with the last operation performed on this file.

Allowed values are those returned by the standard ferror function of the C run-time library, and the extended error codes errOk , errFileNotOpen , errFileAlreadyOpen , errInvalidPath , errInvalidMode , and errFunctionNotSupported . If the last operation was completed successfully, the code errOk is returned.

Returns:
the error code associated with the last operation performed on this file

Flush

bool Flush();

Flushes a stream associated with this file.

This operation has the same effect as the standard fflush function of the C run-time library.

Returns:
true if this file was successfully flushed; false otherwise

GetLength

int GetLength();

Returns a length, in bytes, of this file.

Operation failes if this file is not open.

Returns:
the length, in bytes, of this file; -1 if operation failed

GetPosition

int GetPosition();

Returns a current position of the file pointer for this file.

Operation failes if this file is not open or if it is open with the explicitly specified encoding.

Returns:
the current position of the file pointer for this file; -1 if operation failed

Open

bool Open(
    const WCHAR *pszPath, 
    const WCHAR *pszMode, 
    CEncoding *pEncoding=NULL);

Opens this file, using the specified file path, the specified access mode, and the optional encoding.

The access mode string has the same syntax and meaning as the second argument of the standard fopen function of the C run-time library.

The encoding, if specified, describes the character encoding used to interpret the byte content of this file. If the encoding is not specified explicitly (the corresponding parameter is set to NULL ), the ISO-8859-1 encoding is implicitly used.

If the encoding is explicitly specified, the access mode string is not allowed to contain characters '+' (read/write access) and 'b' (binary access). Furthermore, GetPosition and SetPosition functions are not permitted and will fail in this case.

Operation failes if this file is already open.

Parameters:
pszPath - the file path
pszMode - the access mode
pEncoding - the encoding; NULL if no explicit encoding specified
Returns:
true if this file was open successfully; false otherwise

Read

CString Read();

Reads a line from this file.

Operation failes if this file is not open.

Returns:
the string containing the line read

Read

CString Read(int nCount);

Reads a specified number of characters from this file.

Operation failes if this file is not open.

Parameters:
nCount - the number of characters to read
Returns:
the string containing characters read

SetPosition

bool SetPosition(int nPosition, int nFrom=fromBegin);

Moves the file pointer to a specified position.

The file pointer is positioned relatively to the origin. The origin is specified using the origin code; allowed values are: fromBegin for beginning of file, fromCurrent for current position of file pointer, and fromEnd for end of file.

Operation failes if this file is not open or if it is open with the explicitly specified encoding.

Parameters:
nPosition - the position relative to the origin
nFrom - the indicator of the origin
Returns:
true if the file pointer was successfully positioned; false otherwise

Write

bool Write(const WCHAR *pszData);

Writes the specified string to this file.

Operation failes if this file is not open.

Parameters:
pszData - the string to write
Returns:
true if the string was successfully written; false otherwise

Write

bool Write(const WCHAR *pchData, int nCount);

Writes the array of characters to this file.

Operation failes if this file is not open.

Parameters:
pchData - the array of characters to write
nCount - the number of characters to write
Returns:
true if the string was successfully written; false otherwise

Unicorn XML Toolkit
Version 1.50.00


This document was created using Unicorn DOC++.

Copyright 1999-2001 Unicorn Enterprises SA.
All Rights Reserved.