Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CP_File Class Reference

A class for representing a platforms file object. More...

Inheritance diagram for CP_File:

CP_File_Imp CP_NoCopy List of all members.

Public Member Functions

void Create (FourCharCode inCreator, FourCharCode inType=kCP_Text_FileType)
void Open (SInt32 inPermissions=CP_E_FilePerm_ReadWrite, bool inOpenResourceFork=true)
SInt16 OpenFork (SInt32 inPermissions, const HFSUniStr255 &inForkName)
void Close ()
CP_FileSystemSpec GetFileSpec ()
OSFileRef GetRefNumber ()
SInt64 Length ()
SInt64 GetPosition () const
SInt64 SetPosition (UInt16 inMode, SInt64 inOffset)
void SetEOF (SInt32 inEOF)
UInt32 ReadData (void *inDataBuffer, UInt32 inDataSize, UInt16 inPositionMode=CP_E_FileSeek_FromCurrent, SInt64 inOffset=0)
UInt32 WriteData (const void *inDataBuffer, UInt32 inDataSize, UInt16 inPositionMode=CP_E_FileSeek_FromCurrent, SInt64 inOffset=0)
void UseResFile ()
bool IsOpen ()
void FlushFork (SInt16 inRefNum)
Constructor / Destructor
 CP_File ()
 Constructor.
 CP_File (const CP_FileSystemSpec &inFileSpec)
virtual ~CP_File ()
 Destructor.
Setters
void SetFileSpec (const CP_FileSystemSpec &inFileSpec)
Setters
void SetFileSpec (const CP_FileSystemSpec &inFileSpec)

Protected Member Functions

const HFSUniStr255 & GetDataForkName ()
const HFSUniStr255 & GetResourceForkName ()

Protected Attributes

CP_FileSystemSpec fFileSpec
OSFileRef fDataForkRefNum
OSFileRef fResourceForkRefNum

Detailed Description

This class is implemented for each of the supported platforms through a CP_File_Imp class.

The name and location of this file object is defined by its CP_FileSystemSpec.


Constructor & Destructor Documentation

CPLAT_Begin_Namespace_CPLAT CP_File::CP_File  ) 
 

Constructor.

You will need to call SetFileSpec on this object before you can work with this file object, as this default constructor does not represent a valid file system object.

Exceptions:
none 

CP_File::CP_File const CP_FileSystemSpec inFileSpec  ) 
 

Constructor. Constructs the file from the passed in CP_FileSystemSpec.

Parameters:
inFileSpec CP_FileSystemSpec object that specifies the name and location of the file. If the file has not yet been created, then this is the specification used to create the platforms file.
Exceptions:
none 

CP_File::~CP_File  )  [virtual]
 

Destructor.

Exceptions:
none 


Member Function Documentation

void CP_File_Imp::Create FourCharCode  inCreator,
FourCharCode  inType = kCP_Text_FileType
[inherited]
 

Creates the platforms file object in the platforms file system. Throws an OSError if there is a problem creating the file.

Parameters:
inCreator The creator code for this file.
inType The file type code for this file.
Exceptions:
OSStatus exceptions
Returns:
void

void CP_File_Imp::Open SInt32  inPermissions = CP_E_FilePerm_ReadWrite,
bool  inOpenResourceFork = true
[inherited]
 

Opens the file for reading and/or writing depending on the passed in inPermissions. Throws an OSError if there is a problem opening the data fork. Throws a std::logic_error if the file is already open.

Note: If the file is being opened for write access, and the file doesn't currently exist, it will be created, and then opened to match the behavior of Windows.

Parameters:
inPermissions Permissions for accessing the file. It should be one of the following values:
  • CP_E_FilePerm__ReadOnly
  • CP_E_FilePerm__WriteOnly
  • CP_E_FilePerm__ReadWrite
  • CP_E_FilePerm__ReadWriteShared
inOpenResourceFork Flag to indicate if we should also open the resource fork, default is true.
Exceptions:
Throws a std::logic_error if the file is already open, otherwise OSStatus exceptions on errors.
Returns:
void

SInt16 CP_File_Imp::OpenFork SInt32  inPermissions,
const HFSUniStr255 &  inForkName
[inherited]
 

void CP_File_Imp::Close  )  [inherited]
 

Closes the file in the platforms file system.

Exceptions:
OSErr exceptions.
Returns:
void

CP_FileSystemSpec CP_File_Imp::GetFileSpec  )  [inherited]
 

OSFileRef CP_File_Imp::GetRefNumber  )  [inherited]
 

SInt64 CP_File_Imp::Length  )  [inherited]
 

Returns the length of our file. The file needs to currently be open, otherwide an error occurs.

Exceptions:
OSStatus exceptions
Returns:
SInt64 Length of the file.

SInt64 CP_File_Imp::GetPosition  )  const [inherited]
 

Returns the current file marker position in the file.

Exceptions:
OSStatus exceptions
Returns:
SInt64 Returns the currennt position in the file.

SInt64 CP_File_Imp::SetPosition UInt16  inMode,
SInt64  inOffset
[inherited]
 

Sets the current position in the file based on the passed in parameters.

Parameters:
inPositionMode Specifier for where in the file to set the position. It should be one of the following: -CP_E_FileSeek__FromBegin -CP_E_FileSeek__FromEnd -CP_E_FileSeek__FromCurrent
inOffset Number of bytes offset from the position mode parameter to set the positionn.
Exceptions:
OSStatus exceptions
Returns:
SInt32 Returns the new position in the file.

void CP_File_Imp::SetEOF SInt32  inEOF  )  [inherited]
 

UInt32 CP_File_Imp::ReadData void *  inDataBuffer,
UInt32  inDataSize,
UInt16  inPositionMode = CP_E_FileSeek_FromCurrent,
SInt64  inOffset = 0
[inherited]
 

Reads data fromm the file. Throws an OSError if there was a problem.

Parameters:
inDataBuffer Pointer to the buffer that holds the data to be read into.
inDataSize Number of bytes to read into the passed in data buffer.
inPositionMode Specifier for where in the file to start reading. It should be one of the following: -CP_E_FileSeek__FromBegin -CP_E_FileSeek__FromEnd -CP_E_FileSeek__FromCurrent
inOffset Number of bytes offset from the position mode parameter to begin writing.
Exceptions:
OSStatus exceptions
Returns:
UInt32 Actual number of bytes read.

UInt32 CP_File_Imp::WriteData const void *  inDataBuffer,
UInt32  inDataSize,
UInt16  inPositionMode = CP_E_FileSeek_FromCurrent,
SInt64  inOffset = 0
[inherited]
 

Writes data to the file. Throws an OSError if there was a problem.

Parameters:
inDataBuffer Pointer to the buffer that holds the data to be written.
inDataSize Number of bytes to write from the passed in data buffer.
inPositionMode Specifier for where in the file to start writing. It should be one of the following: -CP_E_FileSeek__FromBegin -CP_E_FileSeek__FromEnd -CP_E_FileSeek__FromCurrent
inOffset Number of bytes offset from the position mode parameter to begin writing.
Exceptions:
OSStatus exceptions
Returns:
UInt32 Actual number of bytes written.

void CP_File_Imp::UseResFile  )  [inherited]
 

void CP_File_Imp::SetFileSpec const CP_FileSystemSpec inFileSpec  )  [inherited]
 

bool CP_File_Imp::IsOpen  )  [inherited]
 

void CP_File_Imp::FlushFork SInt16  inRefNum  )  [inherited]
 

const HFSUniStr255 & CP_File_Imp::GetDataForkName  )  [protected, inherited]
 

Returns the MacOS name of the data fork. Throws an OSError if there is a problem getting the forks name.

Exceptions:
OSStatus exceptions
Returns:
HFSUniStr255 MacOS name of the data fork.

const HFSUniStr255 & CP_File_Imp::GetResourceForkName  )  [protected, inherited]
 

Returns the MacOS name of the resource fork. Throws an OSError if there is a problem getting the forks name.

Exceptions:
OSStatus exceptions
Returns:
HFSUniStr255 MacOS name of the resource fork.


Member Data Documentation

CP_FileSystemSpec CP_File_Imp::fFileSpec [protected, inherited]
 

OSFileRef CP_File_Imp::fDataForkRefNum [protected, inherited]
 

CP_FileSystemSpec containing the name and location of this file.

OSFileRef CP_File_Imp::fResourceForkRefNum [protected, inherited]
 

MacOS file reference number for file when open, Data fork.


The documentation for this class was generated from the following files:
Generated on Tue Sep 20 20:21:45 2005 for CPLAT_MacOS by  doxygen 1.4.0