# kyotocabinet::DirDB Class Reference

Directory hash database. More...

`#include <kcdirdb.h>`

List of all members.

## Classes

class | Cursor
| Cursor to indicate a record. More...
struct | Record
| Record data.

## 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

| DirDB ()
| Default constructor.
virtual | ~DirDB ()
| 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_compressor (Compressor *comp)
| Set the data compressor.
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.
void | report_binary (const char *file, int32_t line, const char *type, const char *name, const char *buf, size_t size)
| Report the content of a binary buffer 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< DirDB, BasicDB::TYPEFOREST >

## Detailed Description

Directory hash database.

Note:
  This class is a concrete class to operate a hash database in a directory. This class can be inherited but overwriting methods is forbidden. Before every database operation, it is necessary to call the TreeDB::open method in order to open a database file and connect the database object to it. To avoid data missing or corruption, it is important to close every database file by the TreeDB::close method when the database is no longer in use. It is forbidden for multible database objects in a process to open the same database at the same time.

## Member Enumeration Documentation

enum kyotocabinet::DirDB::Option

Tuning Options.

Enumerator:

  TSMALL | dummy for compatibility
  TLINEAR | dummy for compatibility
  TCOMPRESS | compress each record

enum kyotocabinet::DirDB::Flag

Status flags.

Enumerator:

  FOPEN | dummy for compatibility
  FFATAL | dummy for compatibility

## Constructor & Destructor Documentation

kyotocabinet::DirDB::DirDB | ( |  | ) | `[explicit]`

Default constructor.

virtual kyotocabinet::DirDB::~DirDB | ( |  | ) | `[virtual]`

Destructor.

Note:
  If the database is not closed, it is closed implicitly.

## Member Function Documentation

bool kyotocabinet::DirDB::accept | ( | const char * | kbuf,
|  | size_t | ksiz,
|  | Visitor * | visitor,
|  | bool | writable = `true` |
| ) |  |  | `[virtual]`

Accept a visitor to a record.

Parameters:

  | 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.

Returns:
  true on success, or false on failure.

Note:
  the operation for each record is performed atomically and other threads accessing the same record are blocked.

Implements kyotocabinet::DB.

bool kyotocabinet::DirDB::iterate | ( | Visitor * | visitor,
|  | bool | writable = `true` |
| ) |  |  | `[virtual]`

Iterate to accept a visitor for each record.

Parameters:

  | visitor | a visitor object.
  | writable | true for writable operation, or false for read-only operation.

Returns:
  true on success, or false on failure.

Note:
  the whole iteration is performed atomically and other threads are blocked.

Implements kyotocabinet::DB.

Error kyotocabinet::DirDB::error | ( |  | ) | const`[virtual]`

Get the last happened error.

Returns:
  the last happened error.

Implements kyotocabinet::BasicDB.

void kyotocabinet::DirDB::set_error | ( | Error::Code | code,
|  | const char * | message |
| ) |  |  |

Set the error information.

Parameters:

  | code | an error code.
  | message | a supplement message.

bool kyotocabinet::DirDB::open | ( | const std::string & | path,
|  | uint32_t | mode = `OWRITER | OCREATE` |
| ) |  |  | `[virtual]`

Open a database file.

Parameters:

  | path | the path of a database file.

  mode

  the connection mode. DirDB::OWRITER as a writer, DirDB::OREADER as a reader. The following may be added to the writer mode by bitwise-or: DirDB::OCREATE, which means it creates a new database if the file does not exist, DirDB::OTRUNCATE, which means it creates a new database regardless if the file exists, DirDB::OAUTOTRAN, which means each updating operation is performed in implicit transaction, DirDB::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: DirDB::ONOLOCK, which means it opens the database file without file locking, DirDB::OTRYLOCK, which means locking is performed without blocking, DirDB::ONOREPAIR, which means the database file is not repaired implicitly even if file destruction is detected.

Returns:
  true on success, or false on failure.

Note:
  Every opened database must be closed by the DirDB::close method when it is no longer in use. It is not allowed for two or more database objects in the same process to keep their connections to the same database file at the same time.

Implements kyotocabinet::BasicDB.

bool kyotocabinet::DirDB::close | ( |  | ) | `[virtual]`

Close the database file.

Returns:
  true on success, or false on failure.

Implements kyotocabinet::BasicDB.

bool kyotocabinet::DirDB::synchronize | ( | bool | hard = `false`,
|  | FileProcessor * | proc = `NULL` |
| ) |  |  | `[virtual]`

Synchronize updated contents with the file and the device.

Parameters:

  | 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.

Returns:
  true on success, or false on failure.

Implements kyotocabinet::BasicDB.

bool kyotocabinet::DirDB::begin_transaction | ( | bool | hard = `false` | ) | `[virtual]`

Begin transaction.

Parameters:

  | hard | true for physical synchronization with the device, or false for logical synchronization with the file system.

Returns:
  true on success, or false on failure.

Implements kyotocabinet::BasicDB.

bool kyotocabinet::DirDB::begin_transaction_try | ( | bool | hard = `false` | ) | `[virtual]`

Try to begin transaction.

Parameters:

  | hard | true for physical synchronization with the device, or false for logical synchronization with the file system.

Returns:
  true on success, or false on failure.

Implements kyotocabinet::BasicDB.

bool kyotocabinet::DirDB::end_transaction | ( | bool | commit = `true` | ) | `[virtual]`

End transaction.

Parameters:

  | commit | true to commit the transaction, or false to abort the transaction.

Returns:
  true on success, or false on failure.

Implements kyotocabinet::BasicDB.

bool kyotocabinet::DirDB::clear | ( |  | ) | `[virtual]`

Remove all records.

Returns:
  true on success, or false on failure.

Implements kyotocabinet::DB.

int64_t kyotocabinet::DirDB::count | ( |  | ) | `[virtual]`

Get the number of records.

Returns:
  the number of records, or -1 on failure.

Implements kyotocabinet::DB.

int64_t kyotocabinet::DirDB::size | ( |  | ) | `[virtual]`

Get the size of the database file.

Returns:
  the size of the database file in bytes, or -1 on failure.

Implements kyotocabinet::BasicDB.

std::string kyotocabinet::DirDB::path | ( |  | ) | `[virtual]`

Get the path of the database file.

Returns:
  the path of the database file, or an empty string on failure.

Implements kyotocabinet::BasicDB.

bool kyotocabinet::DirDB::status | ( | std::map< std::string, std::string > * | strmap | ) | `[virtual]`

Get the miscellaneous status information.

Parameters:

  | strmap | a string map to contain the result.

Returns:
  true on success, or false on failure.

Implements kyotocabinet::BasicDB.

Cursor* kyotocabinet::DirDB::cursor | ( |  | ) | `[virtual]`

Create a cursor object.

Returns:
  the return value is the created cursor object.

Note:
  Because the object of the return value is allocated by the constructor, it should be released with the delete operator when it is no longer in use.

Implements kyotocabinet::BasicDB.

bool kyotocabinet::DirDB::tune_error_reporter | ( | std::ostream * | erstrm,
|  | bool | ervbs |
| ) |  |  |

Set the internal error reporter.

Parameters:

  | erstrm | a stream object into which internal error messages are stored.
  | ervbs | true to report all errors, or false to report fatal errors only.

Returns:
  true on success, or false on failure.

bool kyotocabinet::DirDB::tune_options | ( | int8_t | opts | ) |

Set the optional features.

Parameters:

  | opts | the optional features by bitwise-or: DirDB::TCOMPRESS to compress each record.

Returns:
  true on success, or false on failure.

bool kyotocabinet::DirDB::tune_compressor | ( | Compressor * | comp | ) |

Set the data compressor.

Parameters:

  | comp | the data compressor object.

Returns:
  true on success, or false on failure.

char* kyotocabinet::DirDB::opaque | ( |  | ) |

Get the opaque data.

Returns:
  the pointer to the opaque data region, whose size is 16 bytes.

bool kyotocabinet::DirDB::synchronize_opaque | ( |  | ) |

Synchronize the opaque data.

Returns:
  true on success, or false on failure.

void kyotocabinet::DirDB::set_error | ( | const char * | file,
|  | int32_t | line,
|  | Error::Code | code,
|  | const char * | message |
| ) |  |  | `[protected]`

Set the error information.

Parameters:

  | file | the file name of the epicenter.
  | line | the line number of the epicenter.
  | code | an error code.
  | message | a supplement message.

void kyotocabinet::DirDB::report | ( | const char * | file,
|  | int32_t | line,
|  | const char * | type,
|  | const char * | format,
|  |  | ... |
| ) |  |  | `[protected]`

Report a message for debugging.

Parameters:

  | 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.

void kyotocabinet::DirDB::report_binary | ( | const char * | file,
|  | int32_t | line,
|  | const char * | type,
|  | const char * | name,
|  | const char * | buf,
|  | size_t | size |
| ) |  |  | `[protected]`

Report the content of a binary buffer for debugging.

Parameters:

  | file | the file name of the epicenter.
  | line | the line number of the epicenter.
  | type | the type string.
  | name | the name of the information.
  | buf | the binary buffer.
  | size | the size of the binary buffer

bool kyotocabinet::DirDB::tune_type | ( | int8_t | type | ) | `[protected]`

Set the database type.

Parameters:

  | type | the database type.

Returns:
  true on success, or false on failure.

uint8_t kyotocabinet::DirDB::libver | ( |  | ) | `[protected]`

Get the library version.

Returns:
  the library version, or 0 on failure.

uint8_t kyotocabinet::DirDB::librev | ( |  | ) | `[protected]`

Get the library revision.

Returns:
  the library revision, or 0 on failure.

uint8_t kyotocabinet::DirDB::fmtver | ( |  | ) | `[protected]`

Get the format version.

Returns:
  the format version, or 0 on failure.

uint8_t kyotocabinet::DirDB::chksum | ( |  | ) | `[protected]`

Get the module checksum.

Returns:
  the module checksum, or 0 on failure.

uint8_t kyotocabinet::DirDB::type | ( |  | ) | `[protected]`

Get the database type.

Returns:
  the database type, or 0 on failure.

uint8_t kyotocabinet::DirDB::opts | ( |  | ) | `[protected]`

Get the options.

Returns:
  the options, or 0 on failure.

Compressor* kyotocabinet::DirDB::comp | ( |  | ) | `[protected]`

Get the data compressor.

Returns:
  the data compressor, or NULL on failure.

bool kyotocabinet::DirDB::recovered | ( |  | ) | `[protected]`

Check whether the database was recovered or not.

Returns:
  true if recovered, or false if not.

bool kyotocabinet::DirDB::reorganized | ( |  | ) | `[protected]`

Check whether the database was reorganized or not.

Returns:
  true if recovered, or false if not.