Main Page   Modules   Class Hierarchy   Compound List   Compound Members  

GAUGE3D::GFileSystem Class Reference

Low-level filesystem access. More...

#include <gauge3d/osabstraction/filesystem.h>

List of all members.

Public Types

enum  tOpenFlags {
  READ = 1 << 0, WRITE = 1 << 1, CREATE = 1 << 2, NOREPLACE = 1 << 3,
  TRUNCATE = 1 << 4, APPEND = 1 << 5
}
 Flags used in the Open() function. More...

enum  tSeekType { BEGINNING, CURRENT, END }
 Flags for the Seek() function. More...


Static Public Methods

Initialization
void Init (GString progName)
 Initialize the filesystem. More...

void ShutDown ()
 Shuts down and cleans up the filesystem. More...

Directory Structure
GString WorkingDir ()
 Get the currend working directory.

GString ConfigDir ()
 Get the directory where config files should be placed.

GString ResourceDir ()
 Get the location of the program's resources.

GString PluginDir ()
 Get the location of GAUGE plugins.

Stream-based File Access
File* Open (GString filename,int flags)
 Open a file. More...

int Read (File *file,void *target,int size)
 Read from a file. More...

int Write (File *file,const void *source,int size)
 Write to a file. More...

void Seek (File *file,int offset,tSeekType relativeTo)
 Seek the position of the stream. More...

int TellPos (File *file)
 Get the position of the stream. More...

void Close (File *file)
 Close the file. More...

Memmory Mapped File Access
FileMapMap (GString filename,int offset,int size,int flags)
 Map a file to memory. More...

void UnMap (FileMap *map)
 Close a memory mapped file. More...

Other File Manipulation Functions
int FileSize (GString filename)
 Get the size of a file. More...

int FileSize (File *file)
 Get the size of an already open file. More...

bool Exists (GString filename)
 Check if a file or directory exists. More...

void DeleteFile (GString filename)
 Delete a file. More...

Directory Manipulation Functions
Directory* OpenDirectory (GString dirName)
 Open a directory for listing. More...

bool ReadDirectory (GString *filename,Directory *directory)
 Read the name of one object in the directory. More...

void RewindDirectory (Directory *directory)
 Restart reading from the beginning of a directory. More...

void CloseDirectory (Directory *directory)
 Close the directory. More...

void CreateDirectory (GString dirname)
 Create a directory. More...

void DeleteDirectory (GString dirname)
 Remove an empty directory. More...

void DeleteTree (GString dirname)
 Recursively delete a directory and all of its contents. More...

bool IsDirectory (GString dirname)
 Check if an object is a file or a directory. More...


Detailed Description

Low-level filesystem access.

Do not use this class directly. Use the classes in the File Manipulation module instead.

This is a static class. All members are static. You do not need to instantiate it. So, if you want to open a file, you would say something like GFileSystem::Open("myfile.txt", GFileSystem::READ).


Member Enumeration Documentation

enum GAUGE3D::GFileSystem::tOpenFlags
 

Flags used in the Open() function.

Enumeration values:
READ   Open for reading.
WRITE   Open for writing.
CREATE   Create the file if it doesn't exist.
NOREPLACE   Don't open if the file already exists.
TRUNCATE   Truncate the file to zero length if it exists.
APPEND   Place the stream at the end of the file.

enum GAUGE3D::GFileSystem::tSeekType
 

Flags for the Seek() function.

Enumeration values:
BEGINNING   Seek relative to the beginning of the stream.
CURRENT   Seek relative to the current stream position.
END   Seek relative to the end of the stream.


Member Function Documentation

void GAUGE3D::GFileSystem::Init ( GString progName ) [static]
 

Initialize the filesystem.

Parameters:
progName   A short name for the program, containing only numbers and lower-case letters with no spaces. For example, "gauge3d". This name will be used for directories and such that belong to this program. (i.e. on Unix, the config files are stored in "~/." + progName.)

Specifically, this function does the following things:
  • Creates the config directory if it isn't there yet.
  • Deletes the temporary directory if it is there, and creates a new one.
  • Sticks a text file in the temporary directory telling the user that they can delete it if it is there.

void GAUGE3D::GFileSystem::ShutDown ( ) [static]
 

Shuts down and cleans up the filesystem.

Specifically, this function deletes the temporary directory and all of its contents.

File * GAUGE3D::GFileSystem::Open ( GString filename,
int flags ) [static]
 

Open a file.

Parameters:
filename   The path and name of the file.
flags   One or more of the flags from tOpenFlags, bitwise or'd.
Returns:
A pointer to the open file, or NULL if an error occured.

int GAUGE3D::GFileSystem::Read ( File * file,
void * target,
int size ) [static]
 

Read from a file.

Parameters:
file   A pointer to a file, obtained by calling Open().
target   The location to fill with the data read from the file.
size   The number of bytes to read.
Returns:
The number of bytes read.

int GAUGE3D::GFileSystem::Write ( File * file,
const void * source,
int size ) [static]
 

Write to a file.

Parameters:
file   A pointer to a file, obtained by calling Open().
source   The location of the data to write to the file.
size   The number of bytes to write.
Returns:
The number of bytes written.

void GAUGE3D::GFileSystem::Seek ( File * file,
int offset,
tSeekType relativeTo ) [static]
 

Seek the position of the stream.

Parameters:
file   A pointer to a file, obtained by calling Open().
offset   The position to seek to.
relativeTo   The position that offset is relative to. One of the values of tSeekType.

int GAUGE3D::GFileSystem::TellPos ( File * file ) [static]
 

Get the position of the stream.

Parameters:
file   A pointer to a file, obtained by calling Open().
Returns:
The position of the stream relative to the beginning of the file.

void GAUGE3D::GFileSystem::Close ( File * file ) [static]
 

Close the file.

Parameters:
file   A pointer to a file, obtained by calling Open().

Call this when you are done with the file.

FileMap * GAUGE3D::GFileSystem::Map ( GString filename,
int offset,
int size,
int flags ) [static]
 

Map a file to memory.

Parameters:
filename   The path and name of the file to map.
offset   The offset in bytes from the beginning of the file at which the map should start.
size   The number of bytes of the file to map.
flags   One or more of the flags READ, WRITE, CREATE, and NOREPLACE, from tOpenFlags, bitwise or'd. These have the same effect here as they do for Open().
Returns:
A FileMap structure describing the map in memory, or NULL if an error occured.

This function allows you to access a file as if the entire file (or a segment of it) were in RAM. Where available, features of the operating system are used to accellerate this functionality.

void GAUGE3D::GFileSystem::UnMap ( FileMap * map ) [static]
 

Close a memory mapped file.

Parameters:
map   A pointer to a FileMap, obtained by calling Map()

Call this when you are done with the file map.

int GAUGE3D::GFileSystem::FileSize ( GString filename ) [static]
 

Get the size of a file.

Parameters:
filename   The path and name of the file to get the size of.
Returns:
The size of the file in bytes.

int GAUGE3D::GFileSystem::FileSize ( File * file ) [static]
 

Get the size of an already open file.

Parameters:
file   A pointer to a file, obtained by calling Open().
Returns:
The size of the file in bytes.

bool GAUGE3D::GFileSystem::Exists ( GString filename ) [static]
 

Check if a file or directory exists.

Parameters:
filename   The path and name of the file to check.
Returns:
True if the file exists, or false if it does not.
Remarks:
This function will also return true if the file is actually a directory. Use IsDirectory() to find out if it is a file or a directory.

void GAUGE3D::GFileSystem::DeleteFile ( GString filename ) [static]
 

Delete a file.

Parameters:
filename   The path and name of the file to delete.

Directory * GAUGE3D::GFileSystem::OpenDirectory ( GString dirName ) [static]
 

Open a directory for listing.

Parameters:
dirName   The path and name of the directory.
Returns:
A pointer to a directory, or NULL if an error occured.

bool GAUGE3D::GFileSystem::ReadDirectory ( GString * filename,
Directory * directory ) [static]
 

Read the name of one object in the directory.

Parameters:
filename   A pointer to a string which should be replaced with the name of the file or sub directory.
directory   A pointer to a directory, obtained by calling OpenDirectory().
Returns:
True if a name was read, or false if there were no more objects to read

void GAUGE3D::GFileSystem::RewindDirectory ( Directory * directory ) [static]
 

Restart reading from the beginning of a directory.

Parameters:
directory   A pointer to a directory, obtained by calling OpenDirectory().

void GAUGE3D::GFileSystem::CloseDirectory ( Directory * directory ) [static]
 

Close the directory.

Parameters:
directory   A pointer to a directory, obtained by calling OpenDirectory().

Call this when you are done reading the directory.

void GAUGE3D::GFileSystem::CreateDirectory ( GString dirname ) [static]
 

Create a directory.

Parameters:
dirname   The path and name of the directory to create.

void GAUGE3D::GFileSystem::DeleteDirectory ( GString dirname ) [static]
 

Remove an empty directory.

Parameters:
dirname   The path and name of the directory to remove. This directory must be empty.

void GAUGE3D::GFileSystem::DeleteTree ( GString dirname ) [static]
 

Recursively delete a directory and all of its contents.

Parameters:
dirname   The path and name of the directory to remove. This directory does not have to be empty.

bool GAUGE3D::GFileSystem::IsDirectory ( GString dirname ) [static]
 

Check if an object is a file or a directory.

Parameters:
dirname   The path and name of the filesystem object to check.
Returns:
True if the object was a directory, or false if it was not.


The documentation for this class was generated from the following file:
Generated at Tue Jan 30 17:07:34 2001 for gauge3d by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000