LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Private Member Functions | Private Attributes
LogCabin::Storage::FilesystemUtil::FileContents Class Reference

Provides random access to a file. More...

#include <FilesystemUtil.h>

List of all members.

Public Member Functions

 FileContents (const File &file)
 Constructor.
 ~FileContents ()
 Destructor.
uint64_t getFileLength ()
 Return the length of the file.
void copy (uint64_t offset, void *buf, uint64_t length)
 Copy some number of bytes of the file into a user-supplied buffer.
uint64_t copyPartial (uint64_t offset, void *buf, uint64_t maxLength)
 Copy up to some number of bytes of the file into a user-supplied buffer.
template<typename T = void>
const T * get (uint64_t offset, uint64_t length)
 Get a pointer to a region of the file.

Private Member Functions

const void * getHelper (uint64_t offset, uint64_t length)
 Used internally by get().
 FileContents (const FileContents &)
FileContentsoperator= (const FileContents &)

Private Attributes

File file
 An open file descriptor for the file to read.
uint64_t fileLen
 The number of bytes in the file.
const void * map
 The value returned by mmap(), or NULL for empty files.

Detailed Description

Provides random access to a file.

This implementation currently works by mmaping the file and working from the in-memory copy.

Definition at line 284 of file FilesystemUtil.h.


Constructor & Destructor Documentation

Constructor.

Parameters:
fileAn open file descriptor for the file to read.

Definition at line 445 of file FilesystemUtil.cc.

Destructor.

Definition at line 460 of file FilesystemUtil.cc.


Member Function Documentation

Return the length of the file.

Definition at line 297 of file FilesystemUtil.h.

void LogCabin::Storage::FilesystemUtil::FileContents::copy ( uint64_t  offset,
void *  buf,
uint64_t  length 
)

Copy some number of bytes of the file into a user-supplied buffer.

If there are not enough bytes in the file, this will PANIC. See copyPartial if that's not what you want.

Parameters:
offsetThe number of bytes into the file at which to start copying.
[out]bufThe destination buffer to copy into.
lengthThe number of bytes to copy.

Definition at line 471 of file FilesystemUtil.cc.

uint64_t LogCabin::Storage::FilesystemUtil::FileContents::copyPartial ( uint64_t  offset,
void *  buf,
uint64_t  maxLength 
)

Copy up to some number of bytes of the file into a user-supplied buffer.

Parameters:
offsetThe number of bytes into the file at which to start copying.
[out]bufThe destination buffer to copy into.
maxLengthThe maximum number of bytes to copy.
Returns:
The number of bytes copied. This can be fewer than maxLength if the file ended first.

Definition at line 480 of file FilesystemUtil.cc.

template<typename T = void>
const T* LogCabin::Storage::FilesystemUtil::FileContents::get ( uint64_t  offset,
uint64_t  length 
) [inline]

Get a pointer to a region of the file.

If there are not enough bytes in the file, this will PANIC.

Template Parameters:
TThe return type is casted to a pointer of T.
Parameters:
offsetThe number of bytes into the file at which to return the pointer.
lengthThe number of bytes that must be valid after the offset.
Returns:
A pointer to a buffer containing the 'length' bytes starting at 'offset' in the file. The caller may not modify this buffer. The returned buffer will remain valid until this object is destroyed.

Definition at line 347 of file FilesystemUtil.h.

const void * LogCabin::Storage::FilesystemUtil::FileContents::getHelper ( uint64_t  offset,
uint64_t  length 
) [private]

Used internally by get().

Definition at line 490 of file FilesystemUtil.cc.

FileContents& LogCabin::Storage::FilesystemUtil::FileContents::operator= ( const FileContents ) [private]

Member Data Documentation

An open file descriptor for the file to read.

Definition at line 355 of file FilesystemUtil.h.

The number of bytes in the file.

Definition at line 357 of file FilesystemUtil.h.

The value returned by mmap(), or NULL for empty files.

Definition at line 359 of file FilesystemUtil.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines