GNU CommonC++
Public Member Functions | Protected Member Functions | Protected Attributes | Related Functions | List of all members
ost::RandomFile Class Reference

The purpose of this class is to define a base class for low level random file access that is portable between Win32 and Posix systems. More...

#include <file.h>

Inheritance diagram for ost::RandomFile:
ost::Mutex ost::File ost::MappedFile ost::SharedFile ost::ThreadFile

Public Member Functions

virtual ~RandomFile ()
 Destroy a random access file or it's derived class. More...
 
bool initial (void)
 This method should be called right after a RandomFile derived object has been created. More...
 
off_t getCapacity (void)
 Get current file capacity. More...
 
virtual Error restart (void)
 This method is commonly used to close and re-open an existing database. More...
 
Error getErrorNumber (void)
 Return current error id. More...
 
char * getErrorString (void)
 Return current error string. More...
 
bool operator! (void)
 

Protected Member Functions

 RandomFile (const char *name=NULL)
 Create an unopened random access file. More...
 
 RandomFile (const RandomFile &rf)
 Default copy constructor. More...
 
Error error (Error errid, char *errstr=NULL)
 Post an error event. More...
 
Error error (char *err)
 Post an extended string error message. More...
 
void setError (bool enable)
 Used to enable or disable throwing of exceptions on errors. More...
 
Error setCompletion (Complete mode)
 Used to set file completion modes. More...
 
void setTemporary (bool enable)
 Used to set the temporary attribute for the file. More...
 
virtual Attr initialize (void)
 This method is used to initialize a newly created file as indicated by the "initial" flag. More...
 
void final (void)
 Close the file. More...
 
- Protected Member Functions inherited from ost::Mutex
 Mutex (const char *name=NULL)
 The mutex is always initialized as a recursive entity. More...
 
virtual ~Mutex ()
 Destroying the mutex removes any system resources associated with it. More...
 
void nameMutex (const char *name)
 Enable setting of mutex name for deadlock debug. More...
 
void enterMutex (void)
 Entering a Mutex locks the mutex for the current thread. More...
 
void enter (void)
 Future abi will use enter/leave/test members. More...
 
void leave (void)
 Future abi will use enter/leave/test members. More...
 
bool test (void)
 Future abi will use enter/leave/test members. More...
 
bool tryEnterMutex (void)
 Tries to lock the mutex for the current thread. More...
 
void leaveMutex (void)
 Leaving a mutex frees that mutex for use by another thread. More...
 

Protected Attributes

int fd
 
Access access
 
char * pathname
 
struct {
   unsigned   count: 16
 
   bool   thrown: 1
 
   bool   initial: 1
 
   bool   immediate: 1
 
   bool   temp: 1
 
flags
 

Related Functions

(Note that these are not member functions.)

bool __EXPORT isDir (const char *path)
 
bool __EXPORT isFile (const char *path)
 
bool __EXPORT isDevice (const char *path)
 
bool __EXPORT canAccess (const char *path)
 
bool __EXPORT canModify (const char *path)
 
time_t __EXPORT lastModified (const char *path)
 
time_t __EXPORT lastAccessed (const char *path)
 

Additional Inherited Members

- Public Types inherited from ost::File
enum  Error {
  errSuccess = 0, errNotOpened, errMapFailed, errInitFailed,
  errOpenDenied, errOpenFailed, errOpenInUse, errReadInterrupted,
  errReadIncomplete, errReadFailure, errWriteInterrupted, errWriteIncomplete,
  errWriteFailure, errLockFailure, errExtended
}
 
enum  Access { accessReadOnly = O_RDONLY, accessWriteOnly = O_WRONLY, accessReadWrite = O_RDWR }
 
enum  Open {
  openReadOnly = O_RDONLY, openWriteOnly = O_WRONLY, openReadWrite = O_RDWR, openAppend = O_WRONLY | O_APPEND,
  openSync = O_RDWR, openTruncate = O_RDWR | O_TRUNC
}
 
enum  Attr { attrInvalid = 0, attrPrivate = 0400 | 0200, attrGroup = attrPrivate | 0040 | 0020, attrPublic = attrGroup | 0004 | 0002 }
 
enum  Mapping { mappedRead = accessReadOnly, mappedWrite = accessWriteOnly, mappedReadWrite = accessReadWrite }
 
enum  Complete { completionImmediate, completionDelayed, completionDeferred }
 
typedef enum Error Error
 
typedef enum Access Access
 
typedef enum Open Open
 
typedef enum Attr Attr
 
typedef enum Complete Complete
 
typedef enum Mapping Mapping
 
- Static Public Member Functions inherited from ost::File
static const char * getExtension (const char *path)
 
static const char * getFilename (const char *path)
 
static char * getFilename (const char *path, char *buffer, size_t size=64)
 
static char * getDirname (const char *path, char *buffer, size_t size=256)
 
static char * getRealpath (const char *path, char *buffer, size_t size=256)
 
- Protected Types inherited from ost::File
typedef struct ost::File::_fcb fcb_t
 
enum  Error {
  errSuccess = 0, errNotOpened, errMapFailed, errInitFailed,
  errOpenDenied, errOpenFailed, errOpenInUse, errReadInterrupted,
  errReadIncomplete, errReadFailure, errWriteInterrupted, errWriteIncomplete,
  errWriteFailure, errLockFailure, errExtended
}
 
enum  Access { accessReadOnly = O_RDONLY, accessWriteOnly = O_WRONLY, accessReadWrite = O_RDWR }
 
enum  Open {
  openReadOnly = O_RDONLY, openWriteOnly = O_WRONLY, openReadWrite = O_RDWR, openAppend = O_WRONLY | O_APPEND,
  openSync = O_RDWR, openTruncate = O_RDWR | O_TRUNC
}
 
enum  Attr { attrInvalid = 0, attrPrivate = 0400 | 0200, attrGroup = attrPrivate | 0040 | 0020, attrPublic = attrGroup | 0004 | 0002 }
 
enum  Mapping { mappedRead = accessReadOnly, mappedWrite = accessWriteOnly, mappedReadWrite = accessReadWrite }
 
enum  Complete { completionImmediate, completionDelayed, completionDeferred }
 
typedef enum Error Error
 
typedef enum Access Access
 
typedef enum Open Open
 
typedef enum Attr Attr
 
typedef enum Complete Complete
 
typedef enum Mapping Mapping
 
- Static Protected Member Functions inherited from ost::Mutex
static void setDebug (bool mode)
 Enable or disable deadlock debugging. More...
 
- Static Protected Member Functions inherited from ost::File
static const char * getExtension (const char *path)
 
static const char * getFilename (const char *path)
 
static char * getFilename (const char *path, char *buffer, size_t size=64)
 
static char * getDirname (const char *path, char *buffer, size_t size=256)
 
static char * getRealpath (const char *path, char *buffer, size_t size=256)
 

Detailed Description

The purpose of this class is to define a base class for low level random file access that is portable between Win32 and Posix systems.

This class is a foundation both for optimized thread shared and traditional locked file access that is commonly used to build database services, rather than the standard C++ streaming file classes.

Author
David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m Portable random disk file access.

Constructor & Destructor Documentation

ost::RandomFile::RandomFile ( const char *  name = NULL)
protected

Create an unopened random access file.

ost::RandomFile::RandomFile ( const RandomFile rf)
protected

Default copy constructor.

virtual ost::RandomFile::~RandomFile ( )
virtual

Destroy a random access file or it's derived class.

Member Function Documentation

Error ost::RandomFile::error ( Error  errid,
char *  errstr = NULL 
)
protected

Post an error event.

Returns
error code.
Parameters
erriderror code.
errstrerror message string.
Error ost::RandomFile::error ( char *  err)
inlineprotected

Post an extended string error message.

Returns
errExtended.
Parameters
errerror string.

References ost::error().

void ost::RandomFile::final ( void  )
protected

Close the file.

off_t ost::RandomFile::getCapacity ( void  )

Get current file capacity.

Returns
total file size.
Error ost::RandomFile::getErrorNumber ( void  )
inline

Return current error id.

Returns
last error identifier set.
char* ost::RandomFile::getErrorString ( void  )
inline

Return current error string.

Returns
last error string set.
bool ost::RandomFile::initial ( void  )

This method should be called right after a RandomFile derived object has been created.

This method will invoke initialize if the object is newly created, and set file access permissions appropriately.

Returns
true if file had to be initialized.
virtual Attr ost::RandomFile::initialize ( void  )
protectedvirtual

This method is used to initialize a newly created file as indicated by the "initial" flag.

This method also returns the file access permissions that should be associated with the file. This method should never be called directly, but is instead used to impliment the "Initial" method. Typically one would use this to build an empty database shell when a previously empty database file is created.

Returns
access, or attrInvalid if should be removed.
bool ost::RandomFile::operator! ( void  )
virtual Error ost::RandomFile::restart ( void  )
virtual

This method is commonly used to close and re-open an existing database.

This may be used when the database has been unlinked and an external process provides a new one to use.

Reimplemented in ost::SharedFile, and ost::ThreadFile.

Error ost::RandomFile::setCompletion ( Complete  mode)
protected

Used to set file completion modes.

Returns
errSuccess if okay.
Parameters
modecompletion mode.
void ost::RandomFile::setError ( bool  enable)
inlineprotected

Used to enable or disable throwing of exceptions on errors.

Parameters
enabletrue if errors will be thrown.
void ost::RandomFile::setTemporary ( bool  enable)
inlineprotected

Used to set the temporary attribute for the file.

Temporary files are automatically deleted when closed.

Parameters
enabletrue for marking as temporary.

Friends And Related Function Documentation

bool __EXPORT canAccess ( const char *  path)
related
bool __EXPORT canModify ( const char *  path)
related
bool __EXPORT isDevice ( const char *  path)
related
bool __EXPORT isDir ( const char *  path)
related
bool __EXPORT isFile ( const char *  path)
related
time_t __EXPORT lastAccessed ( const char *  path)
related
time_t __EXPORT lastModified ( const char *  path)
related

Member Data Documentation

Access ost::RandomFile::access
protected
unsigned ost::RandomFile::count
int ost::RandomFile::fd
protected
struct { ... } ost::RandomFile::flags
bool ost::RandomFile::immediate
bool ost::RandomFile::initial
char* ost::RandomFile::pathname
protected
bool ost::RandomFile::temp
bool ost::RandomFile::thrown

The documentation for this class was generated from the following file: