PrevNextUpHome BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1
SFXFile
Class for operating a file.
#include <SFXFile.h.hpp>
class SFXFile : public SFXStorage;
SFMTYPEDEFCLASS(SFXFile)

Inheritance diagram

 Inheritance diagram of SFXFileClass

Collaboration diagram

 Collaboration diagram of SFXFileClass

Description

The SFXFile class is for creating a file, reading from file or writing to file, obtaining file information, and creating a temporary file.

Sample code for reading data from a file.

SFCError error;  // error value
SFXFile file;    // instance of SFXFile class
SFXAnsiStringStreamReader reader; // input stream for reading data from file
SFXAnsiString stringFromFile;     // string to be read from file
SFXAnsiString tempString;

// open file in ReadOnly mode
if ((error = file.OpenReadOnly(SFXPath("/dir1/data.txt"))) == SFERR_NO_ERROR) {

    // get input stream for reading data from file(buffer size = 1024)
    if ((error = file.GetStreamReader(1024, &reader)) == SFERR_NO_ERROR) {

        while (!reader.Ends()) { //  repeat until end of stream is reached

            // read data from file to input stream actually
            // up to 1024 bytes of data can be read since buffer size is specified
            if ((error = reader.Fetch()) != SFERR_NO_ERROR) {
                // if error occurs
                break; 
            }

            // read data from input stream to tempString
            if ((error = reader.ReadSFXAnsiString(&tempString))
                != SFERR_NO_ERROR) { 
                // if error occurs
                break;
            }

            // append tempString onto stringFromFile
            stringFromFile += tempString;
        }
        
        reader.Release();
    }
    file.Close();
}

Sample code for writing data to a file.

SFCError error;  // error value
SFXFile file;    // instance of SFXFile class 
SFXAnsiStringStreamWriter writer; // output stream for writing data to file
SFXAnsiString string("abcdefghijklmnopqrstuvwxyz");  // data to be written
ACharConstPtr p = string.GetBuffer();                // pointer to string
ACharConstPtr endOfString = p + string.GetLength();  // end of string

SInt32 bufferSize = 1024;

// open file in Read/Write mode
if ((error = file.OpenReadWrite(SFXPath("/dir1/data.txt")))
    == SFERR_NO_ERROR) {

    // get output stream for writing data to file
    if ((error = file.GetStreamWriter(bufferSize, &writer))
        == SFERR_NO_ERROR) {

        for (; p < endOfString; p += bufferSize) {

            // write size
            SInt32 size = (endOfString - p < bufferSize) ? endOfString - p : bufferSize;

            // write string to output stream
            if ((error = writer.Write(p, size)) != SFERR_NO_ERROR) {
                // if error occurs
                break; 
            }
            // write data from output stream to file actually 
            if ((error = writer.Flush()) != SFERR_NO_ERROR) { 
                // if error occurs
                break;
            }
        }
        writer.Release();
    }
    file.Close();
}

Reference

SFXDirectory | SFXPath | File Class

Member

Constructor/Destructor
SFXFile( Void )
Constructor of SFXFile class.
SFXFile( SInt32 cache )
Constructor of SFXFile class.
~SFXFile( Void )
Destructor of SFXFile class.
Public Functions
Void Cancel( Void )
Cancel the registered callback function.
Void Close( Void )
Close a file.
static
SFCError
Create( SFXPathConstRef path , Bool force = false )
Create a file.
static
SFCError
DeviceFreeSpace( UInt32Ptr result )
Get the free space of device.
static
SFCError
DeviceTotalSpace( UInt32Ptr result )
Get the device capacity.
static
SFCError
Exists( SFXPathConstRef path , BoolPtr result )
Check whether the file exists or not.
SInt32 GetCacheSize( Void )
Get the cache size when manipulating a file.
static
SFCError
GetCreateDate( SFXPathConstRef path , SFXDatePtr result )
Get the creation date of file.
SFBFileSmpConstRef GetSFBFile( Void )
Get the file interface used internally.
static
SFCError
GetSize( SFXPathConstRef path , UInt32Ptr result )
Get the file size.
SFCError GetStreamReader( UInt32 size , SFXStreamReaderPtr result )
GetStreamReader( SFXStreamReaderPtr result )
Get the input stream for reading data from file.
SFCError GetStreamWriter( UInt32 size , SFXStreamWriterPtr result )
GetStreamWriter( SFXStreamWriterPtr result )
Get the output stream for writing data to file.
static
SFCError
GetTemporaryPath( SFXPathConstRef path , SFXPathPtr result )
Get the temporary file path.
static
SFCError
GetUniquePath( SFXPathConstRef path , SFXAnsiStringConstRef prefix , SFXAnsiStringConstRef suffix , SFXPathPtr result )
Get the file path that does not duplicate existing ones.
static
SFCError
IsReadOnly( SFXPathConstRef path , BoolPtr result )
Check whether the file is read only or not.
static
SFCError
IsSystem( SFXPathConstRef path , BoolPtr result )
Check whether the file is system file or not.
SFCError OpenReadOnly( SFXPathConstRef path )
Open the file in read only mode.
SFCError OpenReadWrite( SFXPathConstRef path , Bool force = false )
Open the file in read/write mode.
SFCError Read( VoidPtr buffer , UInt32Ptr size )
Read data from file.
static
SFCError
Remove( SFXPathConstRef path )
Delete a file.
static
SFCError
Rename( SFXPathConstRef from , SFXPathConstRef to )
Move or rename a file.
SFCError ScheduleRead( CallbackSPP spp , VoidPtr reference )
Register the callback function and schedule to read data from file.
SFCError ScheduleWrite( CallbackSPP spp , VoidPtr reference )
[This function cannot be used now]
SFCError Seek( SInt32 distance )
Move the file pointer by the specified amount from the current position.
SFCError SeekEnd( SInt32 distance )
Move the file pointer by the specified amount from the end of file.
SFCError SeekStart( SInt32 distance )
Move the file pointer by the specified amount from the head of file.
Void SetCacheSize( SInt32 size )
Set the cache size when manipulating a file.
UInt32 Tell( Void )
Get the present position of file pointer.
SFCError Truncate( UInt32 position )
Truncate the file at the specified position.
SFCError Write( VoidConstPtr buffer , UInt32Ptr size )
Write data to file.
Types
CallbackSPP (inherits from SFXStorage)
The prototype of the callback function for the SFXStorage class.

SFXFile::SFXFile
Constructor of SFXFile class.
[ public, explicit ]
SFXFile(Void);
[ public, explicit ]
SFXFile(
    SInt32 cache   // cache size
);

Reference

SFXFile::SetCacheSize


SFXFile::~SFXFile
Destructor of SFXFile class.
[ public, virtual ]
~SFXFile(Void);

Description

Close an opened file.


SFXFile::Cancel
Cancel the registered callback function.
[ public, virtual ]
Void Cancel(Void);

Reference

SFXFile::ScheduleRead


SFXFile::Close
Close a file.
[ public ]
Void Close(Void);

Description

Cancel the callback function and close the open file.

Example

SFXFile file;

...

file.Close();  // close file

Reference

SFXFile::Create | SFXFile::OpenReadOnly | SFXFile::OpenReadWrite


SFXFile::Create
Create a file.
[ public, static ]
SFCError Create(
    SFXPathConstRef path   // file path
    Bool force = false     // recursively create directory or not?
);

Return value

  • Success : SFERR_NO_ERROR
  • If path is invalid : SFERR_INVALID_PARAM
  • If failed : SFERR_FAILED

Description

If the force argument is set to true, create the directories which do not exist in the specified path.

Example

// create file forcedly
// create parent directory if not exist
SFXFile::Create(SFXPath("/dir1/data.txt"), true);

Reference

SFXFile::OpenReadOnly | SFXFile::OpenReadWrite


SFXFile::DeviceFreeSpace
Get the free space of device.
[ public, static ]
SFCError DeviceFreeSpace(
    UInt32Ptr result   // pointer to the result
);

Return value

  • Success : SFERR_NO_ERROR
  • If argument is null : SFERR_INVALID_PARAM
  • If failed : SFERR_FAILED

Example

UInt32 space;

SFXFile::DeviceFreeSpace(&space); // get free space of device

Reference

SFXFile::DeviceTotalSpace


SFXFile::DeviceTotalSpace
Get the device capacity.
[ public, static ]
SFCError DeviceTotalSpace(
    UInt32Ptr result   // pointer to the result
);

Return value

  • Success : SFERR_NO_ERROR
  • If argument is null : SFERR_INVALID_PARAM
  • If failed : SFERR_FAILED

Example

UInt32 space;

SFXFile::DeviceTotalSpace(&space); // get device capacity

Reference

SFXFile::DeviceFreeSpace


SFXFile::Exists
Check whether the file exists or not.
[ public, static ]
SFCError Exists(
    SFXPathConstRef path   // file path to check
    BoolPtr result         // pointer to the result
);

Return value

  • Success : SFERR_NO_ERROR
  • If argument is null : SFERR_INVALID_PARAM
  • If path is directory : SFERR_INVALID_PARAM
  • If failed : SFERR_FAILED

Example

Bool b;

// return value of Exists function is of SFCError type
// b: set by Exists function whether specifiled file exists or not

SFXFile::Exists(SFXPath("/dir1/data.txt"), &b);

if (b) {
    // when file exist
    ...

}

Reference

SFXFile::IsReadOnly | SFXFile::IsSystem


SFXFile::GetCacheSize
Get the cache size when manipulating a file.
[ public, const ]
SInt32 GetCacheSize(Void);

Reference

SFXFile::SetCacheSize


SFXFile::GetCreateDate
Get the creation date of file.
[ public, static ]
SFCError GetCreateDate(
    SFXPathConstRef path   // file path
    SFXDatePtr result      // pointer to the result
);

Return value

  • Success : SFERR_NO_ERROR
  • If argument is null, or path is a directory : SFERR_INVALID_PARAM
  • If failed : SFERR_FAILED

Example

SFXDate date;

// get creation date of file
SFXFile::GetCreateDate(SFXPath("/dir1/data.txt"), &date);

SFXFile::GetSFBFile
Get the file interface used internally.
[ public, const ]
SFBFileSmpConstRef GetSFBFile(Void);

Description

Get the file interface (instance of SFBFile class) that is used internally.

Reference

SFBFile


SFXFile::GetSize
Get the file size.
[ public, static ]
SFCError GetSize(
    SFXPathConstRef path   // file path
    UInt32Ptr result       // pointer to the result
);

Return value

  • Success : SFERR_NO_ERROR
  • If argument is null, or the path is a directory : SFERR_INVALID_PARAM
  • If failed : SFERR_FAILED

Example

UInt32 size;

SFXFile::GetSize(SFXPath("/dir1/data.txt"), &size); // file size is stored in the size variable

SFXFile::GetStreamReader
Get the input stream for reading data from file.
[ public, virtual ]
SFCError GetStreamReader(
    UInt32 size                 // buffer size
    SFXStreamReaderPtr result   // pointer to the input stream
);
[ public, virtual ]
SFCError GetStreamReader(
    SFXStreamReaderPtr result   // pointer to the input stream
);

Return value

  • Success : SFERR_NO_ERROR
  • If argument is null : SFERR_INVALID_PARAM
  • If file is not open : SFERR_INVALID_STATE
  • If insufficient memory : SFERR_NO_MEMORY

Description

The buffer size of the input stream can be specified. Use the SFXBinaryStreamReader, SFXAnsiStringStreamReader, or SFXWideStringStreamReader class for the input stream properly according to the type of data to read.

Example

SFXFile file;
SFXAnsiStringStreamReader reader;
SFXAnsiString temp;
SFXAnsiString string;       // variable in which data read from file is stored
SFXPath path("/data.txt");  // file name

// open file in ReadOnly mode
if (file.OpenReadOnly(path) == SFERR_NO_ERROR) {
    // when success
    
    // get input stream for reading data from file
    file.GetStreamReader(1024, &reader);
    
    // repeat until end of file is reached
    while (!reader.Ends()) {
        if (reader.GetReadableSize() == 0) {
            // read data from file to input stream actually
            reader.Fetch();
        }
        // read data from input stream to temp
        reader >> temp;
        string += temp;
    }
    file.Close();  // close file
}

Reference

SFXFile::GetStreamWriter | SFXBinaryStreamReader | SFXAnsiStringStreamReader | SFXWideStringStreamReader


SFXFile::GetStreamWriter
Get the output stream for writing data to file.
[ public, virtual ]
SFCError GetStreamWriter(
    UInt32 size                 // size
    SFXStreamWriterPtr result   // pointer to the output stream
);
[ public, virtual ]
SFCError GetStreamWriter(
    SFXStreamWriterPtr result   // pointer to the output stream
);

Return value

  • Success : SFERR_NO_ERROR
  • If argument is null : SFERR_INVALID_PARAM
  • If file is not opened : SFERR_INVALID_STATE
  • If insufficient memory : SFERR_NO_MEMORY

Description

The buffer size of the output stream can be specified. Use the SFXBinaryStreamWriter, SFXAnsiStringStreamWriter, or SFXWideStringStreamWriter class for the output stream properly according to the written data type

Example

SFXFile file;
SFXAnsiStringStreamWriter writer;
SFXAnsiString string("abcdefg"); // string to write to file
SFXPath path("/data.txt");       // file name

// open file
if (file.OpenReadWrite(path) == SFERR_NO_ERROR) {
    // when success
    
    // get output stream for writing data to file
    file.GetStreamWriter(string.GetLength(), &writer);
    // write data from string to output stream
    writer << string;
    // write data from output stream to file actually
    writer.Flush();
    
    file.Close();  // close file
}

Reference

SFXFile::GetStreamReader | SFXBinaryStreamWriter | SFXAnsiStringStreamWriter | SFXWideStringStreamWriter


SFXFile::GetTemporaryPath
Get the temporary file path.
[ public, static ]
SFCError GetTemporaryPath(
    SFXPathConstRef path   // directory path in which the temporary file will be created
    SFXPathPtr result      // pointer to the temporary file path
);

Return value

  • Success : SFERR_NO_ERROR
  • If argument is null, or path is not a directory : SFERR_INVALID_PARAM
  • If failed : SFERR_FAILED

Description

The SFXFile::GetTemporaryPath function returns the temporary file path that does not duplicate existing ones.

[Note] Note
To get the permanent file which is not temporary one, use the SFXFile::GetUniquePath function.
[Note] Note
The SFXFile::GetTemporaryPath function internally calls the SFXFile::GetUniquePath function by specifying "sfx" as the prefix argument and "fle.tmp" as the suffix argument respectively.

Example

SFXPath dir("/");
SFXPath path;

if (SFXFile::GetTemporaryPath(path, &path) == SFERR_NO_ERROR) {
    // file path like "/sfx7182CBD4fle.tmp" will be created
    TRACE("%s", path.Get().GetCString());
}

Reference

SFXFile::GetUniquePath | SFXDirectory::GetTemporaryPath | SFXDirectory::GetUniquePath


SFXFile::GetUniquePath
Get the file path that does not duplicate existing ones.
[ public, static ]
SFCError GetUniquePath(
    SFXPathConstRef path           // directory path in which the file will be created
    SFXAnsiStringConstRef prefix   // prefix of file name
    SFXAnsiStringConstRef suffix   // suffix of file name
    SFXPathPtr result              // pointer to the file path
);

Return value

  • Success : SFERR_NO_ERROR
  • If argument is null, or the path is not a directory : SFERR_INVALID_PARAM
  • If failed : SFERR_FAILED

Description

Since the file name is generated using a random number, this function might fail in case many files have already existed.

[Note] Note
If the file name generated using a random number has already existed, repeat to retry this operation up to 64 times. Nevertheless, in case the file path that does not duplicate existing ones can not be generated, this function will fail.
[Note] Note
To get the temporary file path which will be deleted soon, use the SFXFile::GetTemporaryPath function.

Example

SFXPath dir("/");
SFXPath path;

if (SFXFile::GetUniquePath(dir, "sfx", ".dat", &path) == SFERR_NO_ERROR) {
    // file path like "/sfx7182CBD4.dat" will be obtained
    TRACE("%s", path.Get().GetCString());
}

Reference

SFXFile::GetTemporaryPath | SFXDirectory::GetUniquePath | SFXDirectory::GetTemporaryPath


SFXFile::IsReadOnly
Check whether the file is read only or not.
[ public, static ]
SFCError IsReadOnly(
    SFXPathConstRef path   // file path to check
    BoolPtr result         // pointer to the result
);

Return value

  • Success : SFERR_NO_ERROR
  • If argument is null : SFERR_INVALID_PARAM
  • If failed : SFERR_FAILED

Example

Bool b;

// return value of isReadOnly function is of SFCError type
// b: set by isReadOnly function whether specifiled file is read only or not

SFXFile::IsReadOnly(SFXPath("/dir1/data.txt"), &b);

if (b) {
    // when file is read only
    ...
}

Reference

SFXFile::Exists | SFXFile::IsSystem


SFXFile::IsSystem
Check whether the file is system file or not.
[ public, static ]
SFCError IsSystem(
    SFXPathConstRef path   // file path to check
    BoolPtr result         // pointer to the result
);

Return value

  • Success : SFERR_NO_ERROR
  • If argument is null : SFERR_INVALID_PARAM
  • If failed : SFERR_FAILED

Reference

SFXFile::Exists | SFXFile::IsReadOnly


SFXFile::OpenReadOnly
Open the file in read only mode.
[ public ]
SFCError OpenReadOnly(
    SFXPathConstRef path   // file path to open
);

Return value

  • Success : SFERR_NO_ERROR
  • If file is already opened : SFERR_INVALID_STATE
  • If path is not a directory : SFERR_INVALID_PARAM
  • If failed : SFERR_FAILED

Example

SFXFile file;

// open file in read only mode
if (file.OpenReadOnly(SFXPath("/dir1/data.txt")) == SFERR_NO_ERROR) {
    
    ...
    
    // close file
    file.Close();
}

Reference

SFXFile::Create | SFXFile::OpenReadWrite


SFXFile::OpenReadWrite
Open the file in read/write mode.
[ public ]
SFCError OpenReadWrite(
    SFXPathConstRef path   // file path
    Bool force = false     // whether or not to create the file when it does not exist
);

Return value

  • Success : SFERR_NO_ERROR
  • If file is already opened : SFERR_INVALID_STATE
  • If path is not a directory : SFERR_INVALID_PARAM
  • If failed : SFERR_FAILED

Example

SFXFile file;

// open file in read/write mode
if (file.OpenReadWrite(SFXPath("/dir1/data.txt")) == SFERR_NO_ERROR) {

    ...

    // close file
    file.Close();
}

Reference

SFXFile::Create | SFXFile::OpenReadOnly


SFXFile::Read
Read data from file.
[ public, virtual ]
SFCError Read(
    VoidPtr buffer   // buffer to store data read from file
    UInt32Ptr size   // size of data read from file(in bytes)
);

Return value

  • Success : SFERR_NO_ERROR
  • If file is not opened : SFERR_INVALID_STATE
  • If argument is null : SFERR_INVALID_PARAM
  • If failed : SFERR_FAILED
  • if retry is needed : AEE_STREAM_WOULDBLOCK
  • If end of file : EFILEEOF

Example

Copy a file (src.txt) to another file (dst.txt).

SFXFile fin;
SFXFile fout;
SFXBinaryStreamReader reader;
SFXBinaryStreamWriter writer;
SFXBuffer buffer;

// open input file in read only mode
if (fin.OpenReadOnly(SFXPath("/src.txt")) == SFERR_NO_ERROR) {
    // open output file in read/ write mode
    if (fout.OpenReadWrite(SFXPath("/dst.txt")) == SFERR_NO_ERROR) {
        
        fin.GetStreamReader(1024, &reader);    // get input stream for reading
        fout.GetStreamWriter(1024, &writer);   // get output stream for writing

        UInt08 c;
        
        // repeat until end of file is reached
        while (!reader.Ends()) { 
            buffer.SetSize(reader.GetReadableSize());
            reader.Fetch();       // read data from file to input stream
            reader.Read(&buffer); // read data from input stream to buffer
            writer.Write(buffer); // write data from buffer to output stream
            writer.Flush();       // write data from output stream to file
        }
        fout.Close();  // close output file
    }
    fin.Close();       // close input file
}

Reference

SFXFile::OpenReadOnly | SFXFile::OpenReadWrite | SFXFile::Seek | SFXFile::Write


SFXFile::Remove
Delete a file.
[ public, static ]
SFCError Remove(
    SFXPathConstRef path   // file path
);

Return value

  • Success : SFERR_NO_ERROR
  • If path is directory : SFERR_INVALID_PARAM
  • If failed : SFERR_FAILED

Example

if (SFXFile::Remove(SFXPath("/dir/data.txt")) == SFERR_NO_ERROR) {
   ...
}

SFXFile::Rename
Move or rename a file.
[ public, static ]
SFCError Rename(
    SFXPathConstRef from   // file path before changing
    SFXPathConstRef to     // file path after changing
);

Return value

  • Success : SFERR_NO_ERROR
  • If path is not a directory : SFERR_INVALID_PARAM
  • If failed : SFERR_FAILED

Example

Move data.txt from the dir1 directory to the dir2 directory.

if (SFXFile::Rename(SFXPath("/dir1/data.txt"), SFXPath("/dir2/data.txt"))
    == SFERR_NO_ERROR) {
    ...
}

Rename data.txt in dir1 directory to file.txt

if (SFXFile::Rename(SFXPath("/dir1/data.txt"), SFXPath("/dir1/file.txt"))
    == SFERR_NO_ERROR) {
    ...
}

SFXFile::ScheduleRead
Register the callback function and schedule to read data from file.
[ public, virtual ]
SFCError ScheduleRead(
    CallbackSPP spp     // callback function pointer
    VoidPtr reference   // user data passed to callback function
);

Return value

  • Success : SFERR_NO_ERROR
  • If file is not opened, or the callback function has already been registered : SFERR_INVALID_STATE

Description

The SFXFile::ScheduleRead function is used to register the callback function in which the SFXFile::Read function is used to read data from file.

[Note] Note
When the return value of SFXFile::Read function is AEE_STREAM_WOULDBLOCK or there is still remaining data to read, register the callback function using the SFXFile::ScheduleRead function, and then schedule the SFXFile::Read function in the callback function again.

Example

class MyClass {
    SFXFile _file;
    Void Function(Void);
    CALLBACK_DECLARE_SFXFILE(_SFXFile_OnRead)
};

Void MyClass::Function(Void)
{
    SFXPath  path("/dir1/data.txt");
    
    // read file in read only mode
    if (_file.OpenReadOnly(path) == SFERR_NO_ERROR) {
        // schedule to read data from file
        _file.ScheduleRead(CALLBACK_FUNCTION(_SFXFile_OnRead));// register the callback function  
    }
}

// callback function
CALLBACK_IMPLEMENT_SFXFILE(MyClass, _SFXFile_OnRead, error)
{
    SFXBuffer buffer;
    UInt32 size;

    buffer.SetSize(32);  // allocate buffer for reading data from file

     size = buffer.GetSize();  
     // read data from file to buffer
     switch (_file.Read(buffer.GetBuffer(), &size)) {
         case SFERR_NO_ERROR:
             // display the read data
             buffer.SetSize(size + 1);
             buffer[buffer.GetSize() + 1] = '\0';
             TRACE("%s", SFXAnsiString(buffer).GetCString());
             // schedule to read data from file
             _file.ScheduleRead(CALLBACK_FUNCTION(_SFXFile_OnRead));  // register the callback function
             break;
         case EFILEEOF:
             _file.Close();  // close file
             break;
         case AEE_STREAM_WOULDBLOCK:
             // schedule to read data from file
             _file.ScheduleRead(CALLBACK_FUNCTION(_SFXFile_OnRead));  // register the callback function
             break;
        }
    return;
}

Reference

SFXFile::Cancel


SFXFile::ScheduleWrite
[This function cannot be used now]
[ public, virtual ]
SFCError ScheduleWrite(
    CallbackSPP spp     // callback function pointer
    VoidPtr reference   // user data passed to callback function
);

Description

Return SFERR_UNSUPPORTED.


SFXFile::Seek
Move the file pointer by the specified amount from the current position.
[ public ]
SFCError Seek(
    SInt32 distance   // moving amount
);

Return value

  • Success : SFERR_NO_ERROR
  • If file is not open : SFERR_INVALID_STATE
  • If failed : SFERR_FAILED

Description

To move the file pointer backward, set a negative value as moving amount to the distance argument.

When the file is opened in read only mode, if the position of file pointer after moved by this function is under the head of file or over the end of file, this operation will fail.

When the file is opened in read/write mode, if the position of file pointer after moved is over the end of file, the file will be expanded to that position. And if the position of file pointer after moved is under the head of file, this operation will fail.

Reference

SFXFile::SeekStart | SFXFile::SeekEnd | SFXFile::Tell


SFXFile::SeekEnd
Move the file pointer by the specified amount from the end of file.
[ public ]
SFCError SeekEnd(
    SInt32 distance   // moving amount
);

Return value

  • Success : SFERR_NO_ERROR
  • If file is not open : SFERR_INVALID_STATE
  • If failed : SFERR_FAILED

Description

To move the file pointer backward, set a negative value as moving amount to the distance argument.

When the file is opened in read only mode, if the position of file pointer after moved by this function is under the head of file or over the end of file, this operation will fail.

When the file is opened in read/write mode, if the position of file pointer after moved is over the end of file, the file will be expanded to that position. And if the position of file pointer after moved is under the head of file, this operation will fail.

Reference

SFXFile::Seek | SFXFile::SeekStart | SFXFile::Tell


SFXFile::SeekStart
Move the file pointer by the specified amount from the head of file.
[ public ]
SFCError SeekStart(
    SInt32 distance   // moving amount
);

Return value

  • Success : SFERR_NO_ERROR
  • If file is not open : SFERR_INVALID_STATE
  • If failed : SFERR_FAILED

Description

To move the file pointer backward, set a negative value as moving amount to the distance argument.

When the file is opened in read only mode, if the position of file pointer after moved by this function is under the head of file or over the end of file, this operation will fail.

When the file is opened in read/write mode, if the position of file pointer after moved is over the end of file, the file will be expanded to that position. And if the position of file pointer after moved is under the head of file, this operation will fail.

Reference

SFXFile::Seek | SFXFile::SeekEnd | SFXFile::Tell


SFXFile::SetCacheSize
Set the cache size when manipulating a file.
[ public ]
Void SetCacheSize(
    SInt32 size   // cache size
);

Reference

SFXFile::GetCacheSize


SFXFile::Tell
Get the present position of file pointer.
[ public, const ]
UInt32 Tell(Void);

Example

// truncate file at present position of file pointer
file.Truncate(file.Tell());

Reference

SFXFile::Seek | SFXFile::SeekStart | SFXFile::SeekEnd


SFXFile::Truncate
Truncate the file at the specified position.
[ public ]
SFCError Truncate(
    UInt32 position   // position to truncate
);

Return value

  • Success : SFERR_NO_ERROR
  • If file is not open : SFERR_INVALID_STATE
  • If failed : SFERR_FAILED

Example

// truncate file at present position of file pointer
file.Truncate(file.Tell());

Reference

SFXFile::Seek | SFXFile::SeekStart | SFXFile::SeekEnd | SFXFile::Tell


SFXFile::Write
Write data to file.
[ public, virtual ]
SFCError Write(
    VoidConstPtr buffer   // buffer to write
    UInt32Ptr size        // writen data size in bytes
);

Return value

  • Success : SFERR_NO_ERROR
  • If file is not open : SFERR_INVALID_STATE
  • If argument is null : SFERR_INVALID_PARAM
  • If failed : SFERR_FAILED
  • If end of file : EFILEEOF

Description

Write data to file without using the output stream.

Reference

SFXFile::OpenReadOnly | SFXFile::OpenReadWrite | SFXFile::Read SFXFile::Seek |