BLOCXX_NAMESPACE::File Class Reference

The purpose of the File class is to provide an abstraction layer over the platform dependant functionality related to a file. More...

#include <File.hpp>

List of all members.

Public Types

typedef FileHandle File::* safe_bool
enum  ELockType { E_READ_LOCK, E_WRITE_LOCK }

Public Member Functions

 File ()
 Create a NULL File object.
 File (const File &x)
 Copy constructor.
 ~File ()
Fileoperator= (const File &x)
 Assignment operator.
void swap (File &x)
size_t read (void *bfr, size_t numberOfBytes, off_t offset=-1L) const
 Read from the underlying file.
size_t write (const void *bfr, size_t numberOfBytes, off_t offset=-1L)
 Write to the underlying file.
int seek (off_t offset, int whence) const
 Seek to a given offset within the file.
off_t tell () const
void rewind () const
 Position the file pointer to the beginning of the file.
int close ()
 Close the underlying file object.
int flush ()
 Flush any buffered data to the file.
int getLock (ELockType type=E_WRITE_LOCK)
 Acquire a kernel lock on the file.
int tryLock (ELockType type=E_WRITE_LOCK)
 Acquire a kernel lock on the file.
int unlock ()
 Release a lock on the file.
 operator safe_bool () const
bool operator! () const
bool operator== (const File &rhs)
 Equality operator.
 File (FileHandle hdl)

Private Attributes

FileHandle m_hdl


Detailed Description

The purpose of the File class is to provide an abstraction layer over the platform dependant functionality related to a file.

Definition at line 52 of file File.hpp.


Member Typedef Documentation

typedef FileHandle File::* BLOCXX_NAMESPACE::File::safe_bool
 

Definition at line 201 of file File.hpp.


Member Enumeration Documentation

enum BLOCXX_NAMESPACE::File::ELockType
 

Enumerator:
E_READ_LOCK  Place a read / shared lock. More than one process may hold a shared lock for a given file at a given time.
E_WRITE_LOCK  Place an write / exclusive lock. Only one process may hold an exclusive lock for a given file at a given time.

Definition at line 55 of file File.hpp.


Constructor & Destructor Documentation

BLOCXX_NAMESPACE::File::File  )  [inline]
 

Create a NULL File object.

Definition at line 64 of file File.hpp.

BLOCXX_NAMESPACE::File::File const File x  ) 
 

Copy constructor.

Parameters:
x The File object to copy.

Definition at line 133 of file PosixFile.cpp.

BLOCXX_NAMESPACE::File::~File  )  [inline]
 

Definition at line 72 of file File.hpp.

References BLOCXX_NAMESPACE::FileSystem::close().

BLOCXX_NAMESPACE::File::File FileHandle  hdl  )  [inline]
 

Definition at line 219 of file File.hpp.


Member Function Documentation

int BLOCXX_NAMESPACE::File::close  )  [inline]
 

Close the underlying file object.

Returns:
0 on success. Otherwise -1.

Definition at line 150 of file File.hpp.

References BLOCXX_INVALID_FILEHANDLE, and BLOCXX_NAMESPACE::FileSystem::close().

Referenced by BLOCXX_NAMESPACE::ServerSocketImpl::close(), and BLOCXX_NAMESPACE::TempFileEnumerationImplBase::readSize().

int BLOCXX_NAMESPACE::File::flush  )  [inline]
 

Flush any buffered data to the file.

Returns:
0 on success. Otherwise -1.

Definition at line 164 of file File.hpp.

References BLOCXX_NAMESPACE::FileSystem::flush().

int BLOCXX_NAMESPACE::File::getLock ELockType  type = E_WRITE_LOCK  ) 
 

Acquire a kernel lock on the file.

This call may block. The lock may be released by calling unlock(). The lock will also be released when the the file is closed or when locking application exits. This is only an advisory lock and will not prevent non-coordinated access to the file.

Parameters:
type Whether to acquire a read (shared) or a write (exclusive) lock. Default is a write lock.
Returns:
0 on sucess. On error, -1 is returned, and errno is set appropriately. errno may be one of: EBADF, EDEADLK, EINVAL, ENOLCK

Definition at line 154 of file PosixFile.cpp.

References BLOCXX_NAMESPACE::doLock(), E_WRITE_LOCK, and m_hdl.

BLOCXX_NAMESPACE::File::operator safe_bool  )  const [inline]
 

Returns:
true if this is a valid File object.

Definition at line 205 of file File.hpp.

References BLOCXX_INVALID_FILEHANDLE, and m_hdl.

bool BLOCXX_NAMESPACE::File::operator!  )  const [inline]
 

Definition at line 207 of file File.hpp.

References BLOCXX_INVALID_FILEHANDLE.

File& BLOCXX_NAMESPACE::File::operator= const File x  )  [inline]
 

Assignment operator.

Parameters:
x The File object to copy.
Returns:
A reference to this File object.

Definition at line 81 of file File.hpp.

bool BLOCXX_NAMESPACE::File::operator== const File rhs  )  [inline]
 

Equality operator.

Parameters:
rhs The File object to compare this object to.
Returns:
true if this File represents the same file as rhs.

Definition at line 214 of file File.hpp.

References m_hdl.

size_t BLOCXX_NAMESPACE::File::read void *  bfr,
size_t  numberOfBytes,
off_t  offset = -1L
const [inline]
 

Read from the underlying file.

Parameters:
bfr The location where the read operation will place what is read.
numberOfBytes The number of bytes to read.
offset The offset to seek to in the file before the read operation is done. -1 will use the current offset.
Returns:
The number of bytes read. If EOF or an error occurs, a short count or zero is returned.

Definition at line 100 of file File.hpp.

References BLOCXX_NAMESPACE::BinarySerialization::read().

Referenced by BLOCXX_NAMESPACE::dlSharedLibrary::isFakeLibrary(), and BLOCXX_NAMESPACE::TempFileEnumerationImplBase::readSize().

void BLOCXX_NAMESPACE::File::rewind  )  const [inline]
 

Position the file pointer to the beginning of the file.

Definition at line 142 of file File.hpp.

References BLOCXX_NAMESPACE::FileSystem::rewind().

int BLOCXX_NAMESPACE::File::seek off_t  offset,
int  whence
const [inline]
 

Seek to a given offset within the file.

Parameters:
offset The offset to seek to relative to the whence parm.
whence Can be one of the follwing values: SEEK_SET - Seek relative to the beginning of the file. SEEK_CUR - Seek relative to the current position. SEEK_END - Seek relative to the end of the file (bwd).
Returns:
The the current location in the file relative to the beginning of the file on success. Other -1.

Definition at line 127 of file File.hpp.

References BLOCXX_NAMESPACE::FileSystem::seek().

Referenced by BLOCXX_NAMESPACE::TempFileEnumerationImplBase::readSize().

void BLOCXX_NAMESPACE::File::swap File x  )  [inline]
 

Definition at line 86 of file File.hpp.

References m_hdl, and BLOCXX_NAMESPACE::swap().

off_t BLOCXX_NAMESPACE::File::tell  )  const [inline]
 

Returns:
The current position in the file relative to the beginning of the file on success. Otherwise -1.

Definition at line 135 of file File.hpp.

References BLOCXX_NAMESPACE::FileSystem::tell().

int BLOCXX_NAMESPACE::File::tryLock ELockType  type = E_WRITE_LOCK  ) 
 

Acquire a kernel lock on the file.

This call won't block. The lock may be released by calling unlock() The lock will also be released when the locking application exits. This is only an advisory lock and will not prevent non-coordinated access to the file. lt is a exclusive lock.

Parameters:
type Whether to acquire a read (shared) or a write (exclusive) lock. Default is a write lock.
Returns:
0 on sucess. On error, -1 is returned, and errno is set appropriately. errno may be one of: EACCES, EAGAIN, EBADF, EDEADLK, EINVAL, ENOLCK. EACCES or EAGAIN signifies the file is already locked.

Definition at line 161 of file PosixFile.cpp.

References BLOCXX_NAMESPACE::doLock(), E_WRITE_LOCK, and m_hdl.

Referenced by BLOCXX_NAMESPACE::ServerSocketImpl::doListen().

int BLOCXX_NAMESPACE::File::unlock  ) 
 

Release a lock on the file.

This call will not block.

Returns:
0 on sucess. On error, -1 is returned, and errno is set appropriately. errno may be one of: EAGAIN, EBADF, EDEADLK, EINVAL, ENOLCK

Definition at line 168 of file PosixFile.cpp.

References BLOCXX_NAMESPACE::doLock(), and m_hdl.

Referenced by BLOCXX_NAMESPACE::ServerSocketImpl::close().

size_t BLOCXX_NAMESPACE::File::write const void *  bfr,
size_t  numberOfBytes,
off_t  offset = -1L
[inline]
 

Write to the underlying file.

Parameters:
bfr The locaction to get the contents to write.
numberOfBytes The number of bytes to write.
offset The offset to seek to in the file before the write operation is done. -1 will use the current offset.
Returns:
The number of bytes written. If an error occurs, a short count or zero is returned.

Definition at line 113 of file File.hpp.

References BLOCXX_NAMESPACE::BinarySerialization::write().


Member Data Documentation

FileHandle BLOCXX_NAMESPACE::File::m_hdl [private]
 

Definition at line 225 of file File.hpp.

Referenced by getLock(), operator safe_bool(), operator==(), swap(), tryLock(), and unlock().


The documentation for this class was generated from the following files:
Generated on Fri Jun 16 15:39:10 2006 for blocxx by  doxygen 1.4.6