On-memory hash database with LRU deletion. More...
#include <kccachedb.h>
Classes | |
class | Cursor |
Cursor to indicate a record. More... | |
struct | Record |
Record data. | |
class | Remover |
Removing visitor. | |
class | Repeater |
Repeating visitor. | |
class | Setter |
Setting visitor. | |
struct | Slot |
Slot table. | |
struct | TranLog |
Transaction log. | |
Public Types | |
enum | Option { TSMALL = 1 << 0, TLINEAR = 1 << 1, TCOMPRESS = 1 << 2 } |
Tuning Options. More... | |
enum | Flag { FOPEN = 1 << 0, FFATAL = 1 << 1 } |
Status flags. More... | |
Public Member Functions | |
CacheDB () | |
Default constructor. | |
virtual | ~CacheDB () |
Destructor. | |
bool | accept (const char *kbuf, size_t ksiz, Visitor *visitor, bool writable=true) |
Accept a visitor to a record. | |
bool | iterate (Visitor *visitor, bool writable=true) |
Iterate to accept a visitor for each record. | |
Error | error () const |
Get the last happened error. | |
void | set_error (Error::Code code, const char *message) |
Set the error information. | |
bool | open (const std::string &path, uint32_t mode=OWRITER|OCREATE) |
Open a database file. | |
bool | close () |
Close the database file. | |
bool | synchronize (bool hard=false, FileProcessor *proc=NULL) |
Synchronize updated contents with the file and the device. | |
bool | begin_transaction (bool hard=false) |
Begin transaction. | |
bool | begin_transaction_try (bool hard=false) |
Try to begin transaction. | |
bool | end_transaction (bool commit=true) |
End transaction. | |
bool | clear () |
Remove all records. | |
int64_t | count () |
Get the number of records. | |
int64_t | size () |
Get the size of the database file. | |
std::string | path () |
Get the path of the database file. | |
bool | status (std::map< std::string, std::string > *strmap) |
Get the miscellaneous status information. | |
Cursor * | cursor () |
Create a cursor object. | |
bool | tune_error_reporter (std::ostream *erstrm, bool ervbs) |
Set the internal error reporter. | |
bool | tune_options (int8_t opts) |
Set the optional features. | |
bool | tune_buckets (int64_t bnum) |
Set the number of buckets of the hash table. | |
bool | tune_compressor (Compressor *comp) |
Set the data compressor. | |
bool | cap_count (int64_t count) |
Set the capacity by record number. | |
bool | cap_size (int64_t size) |
Set the capacity by memory usage. | |
char * | opaque () |
Get the opaque data. | |
bool | synchronize_opaque () |
Synchronize the opaque data. | |
Protected Member Functions | |
void | set_error (const char *file, int32_t line, Error::Code code, const char *message) |
Set the error information. | |
void | report (const char *file, int32_t line, const char *type, const char *format,...) |
Report a message for debugging. | |
bool | tune_type (int8_t type) |
Set the database type. | |
uint8_t | libver () |
Get the library version. | |
uint8_t | librev () |
Get the library revision. | |
uint8_t | fmtver () |
Get the format version. | |
uint8_t | chksum () |
Get the module checksum. | |
uint8_t | type () |
Get the database type. | |
uint8_t | opts () |
Get the options. | |
Compressor * | comp () |
Get the data compressor. | |
bool | recovered () |
Check whether the database was recovered or not. | |
bool | reorganized () |
Check whether the database was reorganized or not. | |
Friends | |
class | PlantDB< CacheDB, BasicDB::TYPEGRASS > |
On-memory hash database with LRU deletion.
kyotocabinet::CacheDB::CacheDB | ( | ) | [explicit] |
Default constructor.
virtual kyotocabinet::CacheDB::~CacheDB | ( | ) | [virtual] |
Destructor.
bool kyotocabinet::CacheDB::accept | ( | const char * | kbuf, | |
size_t | ksiz, | |||
Visitor * | visitor, | |||
bool | writable = true | |||
) | [virtual] |
Accept a visitor to a record.
kbuf | the pointer to the key region. | |
ksiz | the size of the key region. | |
visitor | a visitor object. | |
writable | true for writable operation, or false for read-only operation. |
Implements kyotocabinet::DB.
bool kyotocabinet::CacheDB::iterate | ( | Visitor * | visitor, | |
bool | writable = true | |||
) | [virtual] |
Iterate to accept a visitor for each record.
visitor | a visitor object. | |
writable | true for writable operation, or false for read-only operation. |
Implements kyotocabinet::DB.
Error kyotocabinet::CacheDB::error | ( | ) | const [virtual] |
void kyotocabinet::CacheDB::set_error | ( | Error::Code | code, | |
const char * | message | |||
) |
Set the error information.
code | an error code. | |
message | a supplement message. |
bool kyotocabinet::CacheDB::open | ( | const std::string & | path, | |
uint32_t | mode = OWRITER | OCREATE | |||
) | [virtual] |
Open a database file.
path | the path of a database file. | |
mode | the connection mode. CacheDB::OWRITER as a writer, CacheDB::OREADER as a reader. The following may be added to the writer mode by bitwise-or: CacheDB::OCREATE, which means it creates a new database if the file does not exist, CacheDB::OTRUNCATE, which means it creates a new database regardless if the file exists, CacheDB::OAUTOTRAN, which means each updating operation is performed in implicit transaction, CacheDB::OAUTOSYNC, which means each updating operation is followed by implicit synchronization with the file system. The following may be added to both of the reader mode and the writer mode by bitwise-or: CacheDB::ONOLOCK, which means it opens the database file without file locking, CacheDB::OTRYLOCK, which means locking is performed without blocking, CacheDB::ONOREPAIR, which means the database file is not repaired implicitly even if file destruction is detected. |
Implements kyotocabinet::BasicDB.
bool kyotocabinet::CacheDB::close | ( | ) | [virtual] |
Close the database file.
Implements kyotocabinet::BasicDB.
bool kyotocabinet::CacheDB::synchronize | ( | bool | hard = false , |
|
FileProcessor * | proc = NULL | |||
) | [virtual] |
Synchronize updated contents with the file and the device.
hard | true for physical synchronization with the device, or false for logical synchronization with the file system. | |
proc | a postprocessor object. If it is NULL, no postprocessing is performed. |
Implements kyotocabinet::BasicDB.
bool kyotocabinet::CacheDB::begin_transaction | ( | bool | hard = false |
) | [virtual] |
Begin transaction.
hard | true for physical synchronization with the device, or false for logical synchronization with the file system. |
Implements kyotocabinet::BasicDB.
bool kyotocabinet::CacheDB::begin_transaction_try | ( | bool | hard = false |
) | [virtual] |
Try to begin transaction.
hard | true for physical synchronization with the device, or false for logical synchronization with the file system. |
Implements kyotocabinet::BasicDB.
bool kyotocabinet::CacheDB::end_transaction | ( | bool | commit = true |
) | [virtual] |
End transaction.
commit | true to commit the transaction, or false to abort the transaction. |
Implements kyotocabinet::BasicDB.
bool kyotocabinet::CacheDB::clear | ( | ) | [virtual] |
int64_t kyotocabinet::CacheDB::count | ( | ) | [virtual] |
Get the number of records.
Implements kyotocabinet::DB.
int64_t kyotocabinet::CacheDB::size | ( | ) | [virtual] |
Get the size of the database file.
Implements kyotocabinet::BasicDB.
std::string kyotocabinet::CacheDB::path | ( | ) | [virtual] |
Get the path of the database file.
Implements kyotocabinet::BasicDB.
bool kyotocabinet::CacheDB::status | ( | std::map< std::string, std::string > * | strmap | ) | [virtual] |
Get the miscellaneous status information.
strmap | a string map to contain the result. |
Implements kyotocabinet::BasicDB.
Cursor* kyotocabinet::CacheDB::cursor | ( | ) | [virtual] |
Create a cursor object.
Implements kyotocabinet::BasicDB.
bool kyotocabinet::CacheDB::tune_error_reporter | ( | std::ostream * | erstrm, | |
bool | ervbs | |||
) |
Set the internal error reporter.
erstrm | a stream object into which internal error messages are stored. | |
ervbs | true to report all errors, or false to report fatal errors only. |
bool kyotocabinet::CacheDB::tune_options | ( | int8_t | opts | ) |
Set the optional features.
opts | the optional features by bitwise-or: DirDB::TCOMPRESS to compress each record. |
bool kyotocabinet::CacheDB::tune_buckets | ( | int64_t | bnum | ) |
Set the number of buckets of the hash table.
bnum | the number of buckets of the hash table. |
bool kyotocabinet::CacheDB::tune_compressor | ( | Compressor * | comp | ) |
Set the data compressor.
comp | the data compressor object. |
bool kyotocabinet::CacheDB::cap_count | ( | int64_t | count | ) |
Set the capacity by record number.
count | the maximum number of records. |
bool kyotocabinet::CacheDB::cap_size | ( | int64_t | size | ) |
Set the capacity by memory usage.
size | the maximum size of memory usage. |
char* kyotocabinet::CacheDB::opaque | ( | ) |
Get the opaque data.
bool kyotocabinet::CacheDB::synchronize_opaque | ( | ) |
Synchronize the opaque data.
void kyotocabinet::CacheDB::set_error | ( | const char * | file, | |
int32_t | line, | |||
Error::Code | code, | |||
const char * | message | |||
) | [protected] |
Set the error information.
file | the file name of the epicenter. | |
line | the line number of the epicenter. | |
code | an error code. | |
message | a supplement message. |
void kyotocabinet::CacheDB::report | ( | const char * | file, | |
int32_t | line, | |||
const char * | type, | |||
const char * | format, | |||
... | ||||
) | [protected] |
Report a message for debugging.
file | the file name of the epicenter. | |
line | the line number of the epicenter. | |
type | the type string. | |
format | the printf-like format string. | |
... | used according to the format string. |
bool kyotocabinet::CacheDB::tune_type | ( | int8_t | type | ) | [protected] |
Set the database type.
type | the database type. |
uint8_t kyotocabinet::CacheDB::libver | ( | ) | [protected] |
Get the library version.
uint8_t kyotocabinet::CacheDB::librev | ( | ) | [protected] |
Get the library revision.
uint8_t kyotocabinet::CacheDB::fmtver | ( | ) | [protected] |
Get the format version.
uint8_t kyotocabinet::CacheDB::chksum | ( | ) | [protected] |
Get the module checksum.
uint8_t kyotocabinet::CacheDB::type | ( | ) | [protected] |
Get the database type.
uint8_t kyotocabinet::CacheDB::opts | ( | ) | [protected] |
Get the options.
Compressor* kyotocabinet::CacheDB::comp | ( | ) | [protected] |
Get the data compressor.
bool kyotocabinet::CacheDB::recovered | ( | ) | [protected] |
Check whether the database was recovered or not.
bool kyotocabinet::CacheDB::reorganized | ( | ) | [protected] |
Check whether the database was reorganized or not.