Block File. More...
#include <rblockfile.h>
Public Types | |
enum | CacheType { WriteThrough, WriteBack } |
Public Member Functions | |
RBlockFile (const RURI &uri, size_t nbcaches) | |
RBlockFile (const RURI &uri, size_t blocksize, size_t nbcaches) | |
void | Open (void) |
virtual void | Close (void) |
void | Clear (void) |
size_t | GetNbBlocks (void) const |
CacheType | GetCacheType (void) const |
void | SetCacheType (CacheType type) |
void | Flush (void) |
void | Read (char *buffer, size_t nb) |
void | Write (const char *buffer, size_t nb) |
void | MoveBlock (size_t blockid, size_t start, size_t end, size_t size) |
const char * | GetPtr (size_t size) |
void | Seek (size_t blockid, size_t pos) |
void | SeekRel (long pos) |
virtual | ~RBlockFile (void) |
Protected Member Functions | |
virtual void | Open (RIO::ModeType mode) |
Protected Member Functions inherited from RIOFile | |
RIOFile (void) | |
RIOFile (const RURI &uri) | |
RIOFile (RIOFile &file) | |
RURI | GetRealName (void) const |
void | Open (const RURI &uri, RIO::ModeType mode) |
bool | IsOpen (void) const |
size_t | Read (char *buffer, size_t nb, bool move=true) |
void | Write (const char *buffer, size_t nb) |
virtual void | Seek (off_t pos) |
virtual void | SeekRel (off_t pos) |
virtual void | SeekToEnd (void) |
void | Truncate (off_t newsize) |
bool | End (void) const |
off_t | GetSize (void) const |
off_t | GetPos (void) const |
virtual | ~RIOFile (void) |
Protected Member Functions inherited from RFile | |
RFile (void) | |
RFile (const RURI &uri) | |
RFile (const RFile &file) | |
void | Open (const RURI &uri, RIO::ModeType mode) |
int | Compare (const RFile &file) const |
int | Compare (const RFile *file) const |
int | Compare (const RString &uri) const |
const RURI & | GetURI (void) const |
void | SetURI (const RURI &uri) |
const RString | GetFileName (void) const |
virtual | ~RFile (void) |
Protected Attributes | |
CacheType | Type |
size_t | BlockSize |
RContainer< RBlockFileData, true, true > | Cache |
RBlockFileData * | Current |
size_t | CurrentPos |
char * | CurrentData |
size_t | NbBlocks |
Protected Attributes inherited from RIOFile | |
bool | CanWrite |
bool | CanRead |
Protected Attributes inherited from RFile | |
RIO::ModeType | Mode |
RURI | URI |
Private Member Functions | |
RBlockFileData * | LoadBlock (size_t id) |
Static Private Member Functions | |
static int | sortOrderAccess (const void *a, const void *b) |
Detailed Description
Block File.
The RBlockFile class represents a file composed from several blocks of a given size. It maintains a cache in memory with a given number of blocks. The class supposes that the first block has an identifier of 1 (0 points to a null block).
Each block have a fixed size and defines an upper limit of the amount of data continuously stored.
The file has a header of 2 Kb. The first byte indicates the number of bytes to store a size_t type. Then, the next bytes represent a size_t that store the block size. The rest of the bytes are actually unused.
- Warning
- When a file created with a given block size on a given architecture, it cannot be opened on another architecture and/or another block size.
Member Enumeration Documentation
enum CacheType |
Constructor & Destructor Documentation
RBlockFile | ( | const RURI & | uri, |
size_t | nbcaches | ||
) |
Construct a file. It is suppose that the block size is either already defined (file exists) or that it is set to 1 Mb.
- Parameters
-
uri URI of the file. nbcaches Number of blocks managed in memory.
RBlockFile | ( | const RURI & | uri, |
size_t | blocksize, | ||
size_t | nbcaches | ||
) |
Construct a file. If the block size differs from the one defined in an existing file, the file cannot be opened.
- Parameters
-
uri URI of the file. blocksize Size of a block (in KBytes). nbcaches Number of blocks managed in memory.
|
virtual |
Destruct the file.
Member Function Documentation
|
protectedvirtual |
Open the file.
- Parameters
-
mode The open mode for the file.
Reimplemented from RIOFile.
Reimplemented in RKeyValueFile< K >.
void Open | ( | void | ) |
Open the file in RIO::ReadWrite mode (the only one acceptable).
|
virtual |
void Clear | ( | void | ) |
Clear the file.
size_t GetNbBlocks | ( | void | ) | const |
Get the number of blocks.
CacheType GetCacheType | ( | void | ) | const |
Get the type of the cache.
void SetCacheType | ( | CacheType | type | ) |
Set the type of the cache. If the type is set to WriteThrough, all the changed caches are saved.
- Parameters
-
type Type.
void Flush | ( | void | ) |
Flush the caches : All the blocks in memory that are dirtied are save on disk.
|
staticprivate |
Method used to ordered the blocks by descending order of accesses.
- Parameters
-
a Pointer to a block. b Pointer to the second block.
|
private |
Load a given block in to memory.
- Parameters
-
id Identifier.
- Returns
- Pointer to the block.
void Read | ( | char * | buffer, |
size_t | nb | ||
) |
Read a given number of bytes at the current position of the file.
- Parameters
-
buffer Buffer (must be allocated). nb Number of bytes to read.
void Write | ( | const char * | buffer, |
size_t | nb | ||
) |
Write a number of bytes of a buffer in the current position of the file.
- Parameters
-
buffer Buffer. nb Number of bytes to read.
void MoveBlock | ( | size_t | blockid, |
size_t | start, | ||
size_t | end, | ||
size_t | size | ||
) |
Move a given number of bytes of a given block. The existing data are overwritten. After the call, the file is positioned at the last byte moved.
- Parameters
-
blockid Identifier of the block. start Initial position. end Final position. size Size of the data to move.
const char* GetPtr | ( | size_t | size | ) |
Get a pointer to the memory at the current position of the file. The internal cursor is moved.
- Parameters
-
size Number of bytes to manipulate from that position.
void Seek | ( | size_t | blockid, |
size_t | pos | ||
) |
Go to a specific position of the file.
- Parameters
-
blockid Identifier of the block. pos Position to reach in the block.
void SeekRel | ( | long | pos | ) |
Go to a specific position in the current block.
- Parameters
-
pos Relative position to reach in the block.
Field Documentation
|
protected |
Type of the cache.
|
protected |
Size of the blocks.
|
protected |
Cache managed.
|
protected |
Current block.
|
protected |
Current position.
|
protected |
Pointer to the current data.
|
protected |
Number of blocks contained in the file.