strusBase  0.17
Public Types | Public Member Functions | List of all members
strus::DataRecordFile Class Reference

Basic portable file type for collections of equal sized records with random access. More...

#include <dataRecordFile.hpp>

Public Types

enum  Mode { NoAccess =0x0, SharedRead =0x1, ExclusiveAppendWrite =0x4 }
 Implemented modes to access a data record file. More...
 

Public Member Functions

 DataRecordFile ()
 Constructor. More...
 
 ~DataRecordFile ()
 Destructor. More...
 
bool open (const std::string &filename, const Mode &mode_, unsigned int recordsize_, unsigned int headersize_=0, const void *headerstruct=0)
 Open a file. More...
 
const void * read (std::size_t fpos)
 Read one record of the file. More...
 
const void * read ()
 Read the record at the current file position of the file. More...
 
const void * header ()
 Get a pointer to the header of of the file. More...
 
bool append (const void *recbuf)
 Append a record at the end of the file. More...
 
bool close ()
 Close the file. More...
 
int error () const
 Get the error of the last operation to this file. More...
 
std::size_t recordsize () const
 Get the size of one record of this file. More...
 
std::size_t size ()
 Get the number of records stored in the file. More...
 

Detailed Description

Basic portable file type for collections of equal sized records with random access.

Remarks
Access of the same file with the same DataRecordFile class is not thread safe

Member Enumeration Documentation

Implemented modes to access a data record file.

Enumerator
NoAccess 
SharedRead 
ExclusiveAppendWrite 

Constructor & Destructor Documentation

strus::DataRecordFile::DataRecordFile ( )

Constructor.

strus::DataRecordFile::~DataRecordFile ( )

Destructor.

Member Function Documentation

bool strus::DataRecordFile::append ( const void *  recbuf)

Append a record at the end of the file.

Parameters
[in]recbufbuffer containing the record to write
Returns
true, if success, false on failure (see error() for the system error code ~ errno)
bool strus::DataRecordFile::close ( )

Close the file.

Returns
true, if success, false on failure (see error() for the system error code ~ errno)
int strus::DataRecordFile::error ( ) const

Get the error of the last operation to this file.

Returns
the error code (system errno)
const void* strus::DataRecordFile::header ( )

Get a pointer to the header of of the file.

Returns
pointer to the header, a structure of a size specified as last argument of DataRecordFile::open(..)
bool strus::DataRecordFile::open ( const std::string &  filename,
const Mode mode_,
unsigned int  recordsize_,
unsigned int  headersize_ = 0,
const void *  headerstruct = 0 
)

Open a file.

Parameters
[in]filenamename of the file o open
[in]mode_file mode describing the access to the file
[in]recordsize_size of one record in bytes
[in]headersize_size of the file header in bytes (0 for no header is default)
[in]headerstructheader structure in case of open for write
Returns
true, if success, false on failure (see error() for the system error code ~ errno)
const void* strus::DataRecordFile::read ( std::size_t  fpos)

Read one record of the file.

Parameters
[in]fposindex of the record to read (file position is the index multiplied with the record size)
Returns
pointer to buffer read if success, (0) NULL on failure (see error() for the system error code ~ errno)
const void* strus::DataRecordFile::read ( )

Read the record at the current file position of the file.

Returns
pointer to buffer read if success, (0) NULL on failure (see error() for the system error code ~ errno)
std::size_t strus::DataRecordFile::recordsize ( ) const
inline

Get the size of one record of this file.

std::size_t strus::DataRecordFile::size ( )

Get the number of records stored in the file.


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