#include <store.h>
Inheritance diagram for Store:
Public Member Functions | |
Store () | |
~Store () | |
int | open (const char *name) |
portable_off_t | alloc () |
int | write (const char *buf, uint size) |
void | end () |
void | release (portable_off_t handle) |
void | close () |
void | seek (portable_off_t handle) |
int | read (char *buf, uint size) |
void | printStats () |
Classes | |
struct | Node |
You can open the store using open(). Then obtain a handle via alloc() followed by a sequence of write() commands to store information, and finalize it using end().
Later on you locate the information with seek() using the handle obtained with alloc(), and then use a sequence of read() calls to read the information back.
If no longer needed the storage space can be freed using release().
The store will dynamically grow the file on disk if needed.
Definition at line 52 of file store.h.
Store::~Store | ( | ) |
int Store::open | ( | const char * | name | ) |
Opens the file underlying the store using name as the file name. Returns 0 upon success, or -1 otherwise.
Definition at line 66 of file store.cpp.
References BLOCK_SIZE, and STORE_ASSERT.
portable_off_t Store::alloc | ( | ) |
Allocates a handle to write to and read from.
Definition at line 99 of file store.cpp.
References BLOCK_SIZE, portable_fseek(), portable_ftell(), and STORE_ASSERT.
Referenced by MemberDef::flushToDisk().
int Store::write | ( | const char * | buf, | |
uint | size | |||
) | [virtual] |
Writes size bytes in array buf to the store. First alloc() has to be called.
Implements StorageIntf.
Definition at line 137 of file store.cpp.
References BLOCK_POINTER_SIZE, BLOCK_SIZE, portable_fseek(), portable_ftell(), and STORE_ASSERT.
void Store::end | ( | ) |
Ends the sequence of writes.
Definition at line 213 of file store.cpp.
References BLOCK_SIZE, portable_ftell(), and STORE_ASSERT.
void Store::release | ( | portable_off_t | handle | ) |
Releases the memory corresponding to the handle returned with alloc()
Definition at line 229 of file store.cpp.
References BLOCK_POINTER_SIZE, BLOCK_SIZE, portable_fseek(), and STORE_ASSERT.
void Store::close | ( | ) |
void Store::seek | ( | portable_off_t | handle | ) |
Goes to the start of information corresponding to handle pos
Definition at line 264 of file store.cpp.
References BLOCK_SIZE, portable_fseek(), and STORE_ASSERT.
Referenced by MemberDef::loadFromDisk().
int Store::read | ( | char * | buf, | |
uint | size | |||
) | [virtual] |
Reads size bytes from the store into the array pointed to be buf.
Implements StorageIntf.
Definition at line 277 of file store.cpp.
References BLOCK_POINTER_SIZE, BLOCK_SIZE, portable_fseek(), portable_ftell(), and STORE_ASSERT.
void Store::printStats | ( | ) |