ucommon
Public Member Functions | Protected Member Functions | Protected Attributes | Related Functions
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:
Inheritance graph
[legend]

Public Member Functions

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

Protected Member Functions

Error error (Error errid, char *errstr=((void *) 0))
 Post an error event. More...
 
Error error (char *err)
 Post an extended string error message. More...
 
void final (void)
 Close the file.
 
virtual Attr initialize (void)
 This method is used to initialize a newly created file as indicated by the "initial" flag. More...
 
 RandomFile (const char *name=((void *) 0))
 Create an unopened random access file.
 
 RandomFile (const RandomFile &rf)
 Default copy constructor.
 
Error setCompletion (Complete mode)
 Used to set file completion modes. More...
 
void setError (bool enable)
 Used to enable or disable throwing of exceptions on errors. More...
 
void setTemporary (bool enable)
 Used to set the temporary attribute for the file. More...
 
- Protected Member Functions inherited from ost::Mutex
void enter (void)
 
void enterMutex (void)
 
void leave (void)
 
void leaveMutex (void)
 
bool test (void)
 
bool tryEnterMutex (void)
 
- Protected Member Functions inherited from ucommon::RecursiveMutex
virtual void _lock (void)
 
virtual void _unlock (void)
 
void lock (void)
 Acquire or increase locking.
 
bool lock (timeout_t timeout)
 Timed lock request.
 
 RecursiveMutex ()
 Create rexlock.
 
void release (void)
 Release or decrease locking.
 
void exclusive_lock (void)
 Access interface to exclusive lock the object.
 
void release_exclusive (void)
 Access interface to release a lock.
 

Protected Attributes

Access access
 
int fd
 
struct {
   unsigned   count: 16
 
   bool   immediate: 1
 
   bool   initial: 1
 
   bool   temp: 1
 
   bool   thrown: 1
 
flags
 
char * pathname
 
- Protected Attributes inherited from ucommon::RecursiveMutex
pthread_t locker
 
unsigned lockers
 
unsigned waiting
 

Related Functions

(Note that these are not member functions.)

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

Additional Inherited Members

- Public Types inherited from ost::File
enum  Access { accessReadOnly = 00, accessWriteOnly = 01, accessReadWrite = 02 }
 
typedef enum Access Access
 
enum  Attr { attrInvalid = 0, attrPrivate = 0400 | 0200, attrGroup = attrPrivate | ( 0400 >> 3) | ( 0200 >> 3), attrPublic = attrGroup | ( ( 0400 >> 3) >> 3) | ( ( 0200 >> 3) >> 3) }
 
typedef enum Attr Attr
 
enum  Complete { completionImmediate, completionDelayed, completionDeferred }
 
typedef enum Complete Complete
 
enum  Error {
  errSuccess = 0, errNotOpened, errMapFailed, errInitFailed,
  errOpenDenied, errOpenFailed, errOpenInUse, errReadInterrupted,
  errReadIncomplete, errReadFailure, errWriteInterrupted, errWriteIncomplete,
  errWriteFailure, errLockFailure, errExtended
}
 
typedef enum Error Error
 
enum  Mapping { mappedRead = accessReadOnly, mappedWrite = accessWriteOnly, mappedReadWrite = accessReadWrite }
 
typedef enum Mapping Mapping
 
enum  Open {
  openReadOnly = 00, openWriteOnly = 01, openReadWrite = 02, openAppend = 01 | 02000,
  openSync = 02 | 04010000, openTruncate = 02 | 01000
}
 
typedef enum Open Open
 
- Static Public Member Functions inherited from ost::File
static char * getDirname (const char *path, char *buffer, size_t size=4096)
 
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=255)
 
static char * getRealpath (const char *path, char *buffer, size_t size=4096)
 
- Protected Types inherited from ost::File
typedef struct ost::File::_fcb fcb_t
 
enum  Access { accessReadOnly = 00, accessWriteOnly = 01, accessReadWrite = 02 }
 
typedef enum Access Access
 
enum  Attr { attrInvalid = 0, attrPrivate = 0400 | 0200, attrGroup = attrPrivate | ( 0400 >> 3) | ( 0200 >> 3), attrPublic = attrGroup | ( ( 0400 >> 3) >> 3) | ( ( 0200 >> 3) >> 3) }
 
typedef enum Attr Attr
 
enum  Complete { completionImmediate, completionDelayed, completionDeferred }
 
typedef enum Complete Complete
 
enum  Error {
  errSuccess = 0, errNotOpened, errMapFailed, errInitFailed,
  errOpenDenied, errOpenFailed, errOpenInUse, errReadInterrupted,
  errReadIncomplete, errReadFailure, errWriteInterrupted, errWriteIncomplete,
  errWriteFailure, errLockFailure, errExtended
}
 
typedef enum Error Error
 
enum  Mapping { mappedRead = accessReadOnly, mappedWrite = accessWriteOnly, mappedReadWrite = accessReadWrite }
 
typedef enum Mapping Mapping
 
enum  Open {
  openReadOnly = 00, openWriteOnly = 01, openReadWrite = 02, openAppend = 01 | 02000,
  openSync = 02 | 04010000, openTruncate = 02 | 01000
}
 
typedef enum Open Open
 
- Static Protected Member Functions inherited from ost::File
static char * getDirname (const char *path, char *buffer, size_t size=4096)
 
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=255)
 
static char * getRealpath (const char *path, char *buffer, size_t size=4096)
 

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.

Definition at line 377 of file file.h.

Member Function Documentation

Error ost::RandomFile::error ( Error  errid,
char *  errstr = ((void *) 0) 
)
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.

Definition at line 428 of file file.h.

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.

Definition at line 513 of file file.h.

char* ost::RandomFile::getErrorString ( void  )
inline

Return current error string.

Returns
last error string set.

Definition at line 521 of file file.h.

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.
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.

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

Used to set file completion modes.

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

Used to enable or disable throwing of exceptions on errors.

Parameters
enabletrue if errors will be thrown.

Definition at line 437 of file file.h.

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.

Definition at line 457 of file file.h.

Friends And Related Function Documentation

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

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