[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

 

LFile



Description:

LFile is a PowerPlant class that is used as a wrapper class for a Macintosh file with a data and/or a resource fork.

A FSSpec (File System Specification) record identifies a Mac file. When open, the data fork has a file refNum. Likewise, when open, the resource fork has a file refNum. The LFile class stores an FSSpec and the refNums for the data and resource forks.

This class does not provide many functions for manipulating files. You should get the FSSpec or refNum of the fork you want to manipulate and make direct calls to the Mac File Manager. However, use the member functions for opening and closing data and resource forks.

The only file accessing functions provided are ones for reading and writing the entire data fork.

Methods :

The methods in this class are:

 

LFile()  
~LFile()  
CloseDataFork()  
CloseResourceFork()  
CreateNewDataFile()  
CreateNewFile()  
EqualFileSpec()  
GetSpecifier()  
MakeAlias()  
OpenDataFork()  
OpenResourceFork()  
ReadDataFork()  
SetSpecifier()  
UsesSpecifier()  
WriteDataFork()  
 

Data Members:

The data members in this class are:

 

mMacFileSpec  
mDataForkRefNum  
mResourceForkRefNum  
 

Source files:

(File & Stream Classes)

LFile.h

LFile.cp

See also:

 

LFile()

Purpose:

There are three constructor methods.

The default constructor sets the items in mMacFileSpec to 0, mDataForkRefNum and mResourceForkRefNum to refNum_Undefined.

The second constructor is a parameter constructor which sets mMacFileSpec to inFileSpec, mDataForkRefNum and mResourceForkRefNum to refNum_Undefined.

The third constructor is also a parameter constructor that creates a File from an AliasHandle. outWasChanged indicates if the AliasHandle was changed during resolution. inFromFile is a File Specifiier for the starting point for a relative search. If nil, an absolute search should be performed. Also sets mDataForkRefNum and mResourceForkRefNum to refNum_Undefined. Calls an exception if the OS returns an error.

Access :

Public

Prototypes:

LFile(); // Default Constructor

LFile (const FSSpec &inFileSpec);

LFile ( AliasHandle inAlias,
  Boolean& outWasChanged,
  FSSpec* inFromFile);
Return:

No return value for a constructor.

~LFile()

Purpose:

The destructor closes the data and resource forks before deletion.

Access :

Public

Prototype:

virtual ~LFile();
Parameters:

None

Return:

No return value for a destructor

CloseDataFork()

Purpose:

Close the data fork of a File (if any). It's a good idea to close files just after reading or writing, to avoid damage if something crashes.

Access :

Public, Virtual

Prototype:

void CloseDataFork();
Parameters:

None

Return:

None

Remarks:

Throws anexception if it fails.

CloseResourceFork()

Purpose:

Close the resource fork of a File (if any). It's a good idea to close files just after reading or writing, to avoid damage if something crashes.

Access :

Public, Virtual

Prototype:

void CloseResourceFork();
Parameters:

None

Return:

None

Remarks:

Throws an exception if it fails.

CreateNewDataFile()

Purpose:

Create a new disk File, with an empty data fork and no resource map. You must call OpenDataFork (with write permission) before you can store data in the File. The resource fork is uninitialized (no resource map), so you can't call OpenResourceFork for the File. You can initialize the resource fork by calling CreateNewFile.

Access :

Virtual, Public

Prototype:

void CreateNewDataFile( 
  OSType inCreator,
  OSType inFileType,
  ScriptCode inScriptCode);
Parameters:

 

OSType  
inCreator  
Creator type of file  
OSType  
inFileType  
File type (`TEXT', etc.)  
ScriptCode  
inScriptCode  
Script code (e.g.: smSystemScript)  

Return:

None

Remarks:

The resource fork is uninitialized (no resource map), so you can't call OpenResourceFork() for the file. You can initialize the resource fork by calling CreateNewFile().

CreateNewFile()

Purpose:

Create a new disk File, with an empty data fork and a resoure map. You must call OpenDataFork or OpenResourceFork (with write permission) before you can store information in the File. If the file already exists, but doesn't have a resource map, this function will create a resource map.

Access :

Virtual, Public

Prototype:

void CreateNewFile( 
  OSType inCreator,
  OSType inFileType,
  ScriptCode inScriptCode);
Parameters:

 

OSType  
inCreator  
Creator type of file  
OSType  
inFileType  
File type (`TEXT', etc.)  
ScriptCode  
inScriptCode  
Script code (e.g.: smSystemScript)  

Return:

None

Remarks:

If the file already exists, but doesn't have a resource map, this function will create a resource map.

EqualFileSpec()

Purpose:

Compare two FSSpec structs for equality. Compares each field in the FSSpec struct.

Access :

Static, Public

Prototype:

Boolean EqualFileSpec(
  const FSSpec& inFileSpecA,
  const FSSpec& inFileSpecB);
Parameters:

 

const FSSpec  
inFileSpecA  
First FSSpec struct  
const FSSpec  
inFileSpecB  
Second FSSpec struct  

Return:

True if both FSSpec structs are equal.

GetSpecifier()

Purpose:

Return the current Mac File System Specification record (mMacFileSpec) for a File.

Access :

Public

Prototype:

void GetSpecifier(
  FSSpec& outFileSpec) const;
Parameters:

 

FSSpec  
outFileSpec  
File System Specification record  

Return:

None

MakeAlias()

Purpose:

Return a newly created AliasHandle for a File.

Access :

Virtual, Public

Prototype:

virtual AliasHandle MakeAlias( FSSpec* 
inFromFile);
Parameters:

 

FSSpec  
inFromFile  
File Specifier for the starting point for a relative search. Pass nil if you don't need relative path information.  

Return:

None

OpenDataFork()

Purpose:

Open the data fork of a File with the specified permissions and return the reference number for the opened fork A data fork must be Open before you can read or write data

Access :

 

Prototype:

virtual SInt16 OpenDataFork( SInt16 inPrivileges);
Parameters:

 

SInt16  
inPrivileges  
Read/Write permissions.  

Return:

Reference number for the open data fork.

Remarks:

A data fork must be open before you can read or write data.

OpenResourceFork()

Purpose:

Open the resource fork of a File with the specified permissions andreturn the reference number for the opened fork A resource fork must be Open before you can read or write resources

Access :

Virtual, Public

Prototype:

virtual SInt16 OpenResourceFork( 
  SInt16 inPrivileges)
Parameters:

 

SInt16  
inPrivileges  
Read/Write permissions.  

Return:

Referencenumber for the open resource fork.

Remarks:

A resource fork must be open before you can read or write resources.

ReadDataFork()

Purpose:

Read the entire contents of a File's data fork into a newly created Handle. The caller is responsible for disposing of the Handle.

Access :

Virtual, Public

Prototype:

virtual Handle ReadDataFork();
Parameters:

None

Return:

Handle to the data fork.

Remarks:

Throws an exception if it fails.

SetSpecifier()

Purpose:

Set a new Toolbox File System Specification for a File. This has the side effect of closing any open forks of the file identified by the old Specifier.

Access :

Virtual, Public

Prototype:

virtual void SetSpecifier(

	const FSSpec& inFileSpec);
Parameters:

 

const FSSpec  
inFileSpec  
new File Specification  

Return:

None

UsesSpecifier()

Purpose:

Returns whether the File's FSSpec is the same as the input FSSpec.

Access :

Public

Prototype:

Boolean UsesSpecifier(
  const FSSpec& inFileSpec) const;
Parameters:

 

const FSSpec  
inFileSpec  
File specification to compare  

Return:

True if FSSpec's are the same.

Remarks:

Calls EqualFileSpec().

WriteDataFork()

Purpose:

Write to the data fork of a File from a buffer. The buffer contents completely replace any existing data.

Access :

Virtual, Public

Prototype:

SInt32 WriteDataFork(
  const void* inBuffer,
  SInt32 inByteCount);
Parameters:

 

const void*  
inBuffer  
Pointer to data buffer  
SInt32  
inByteCount  
Size of data buffer to write  

Return:

Number of bytes actually written.

Remarks:

Throws an exception if it fails.

mMacFileSpec

Purpose:

Stores the FSSpec of the file.

Access :

Protected

Prototype:

FSSpec mMacFileSpec;

mDataForkRefNum

Purpose:

refNum for the File's data fork.

Access :

Protected

Prototype:

SInt16 mDataForkRefNum;

mResourceForkRefNum

Purpose:

refNum for the File's resource fork.

Access :

Protected

Prototype:

SInt16 mResourceForkRefNum;

 


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: July 21, 2000