# kyotocabinet::PolyDB Class Reference

Polymorphic database. More...

`#include <kcpolydb.h>`

List of all members.

## Classes

class | Cursor
| Cursor to indicate a record. More...

## Public Member Functions

| PolyDB ()
| Default constructor.
| PolyDB (BasicDB *db)
| Constructor.
virtual | ~PolyDB ()
| 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.
BasicDB * | reveal_inner_db ()
| Reveal the inner database object.

## Detailed Description

Polymorphic database.

## Constructor & Destructor Documentation

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

Default constructor.

kyotocabinet::PolyDB::PolyDB | ( | BasicDB * | db | ) | `[explicit]`

Constructor.

Parameters:

  | db | the internal database object. Its possession is transferred inside and the object is deleted automatically.

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

Destructor.

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

## Member Function Documentation

bool kyotocabinet::PolyDB::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::PolyDB::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::PolyDB::error | ( |  | ) | const`[virtual]`

Get the last happened error.

Returns:
  the last happened error.

Implements kyotocabinet::BasicDB.

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

Set the error information.

Parameters:

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

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

Open a database file.

Parameters:

  path

  the path of a database file. If it is "-", the database will be a prototype hash database. If it is "+", the database will be a prototype tree database. If it is "*", the database will be a cache hash database. If it is "%", the database will be a cache tree database. If its suffix is ".kch", the database will be a file hash database. If its suffix is ".kct", the database will be a file tree database. If its suffix is ".kcd", the database will be a directory hash database. If its suffix is ".kcf", the database will be a directory tree database. Otherwise, this function fails. Tuning parameters can trail the name, separated by "#". Each parameter is composed of the name and the value, separated by "=". If the "type" parameter is specified, the database type is determined by the value in "-", "+", "*", "%", "kch", "kct", "kcd", and "kcf". The prototype hash database and the prototype tree database do not support any other tuning parameter. The cache hash database supports "opts", "bnum", "zcomp", "capcount", "capsize", "erstrm", "ervbs", and "zkey". The cache tree database supports all parameters of the cache hash database except for capacity limitation, and supports "psiz", "rcomp", "pccap" in addition. The file hash database supports "apow", "fpow", "opts", "bnum", "msiz", "dfunit", "zcomp", "erstrm", "ervbs", and "zkey". The file tree database supports all parameters of the file hash database and "psiz", "rcomp", "pccap" in addition. The directory hash database supports "opts", "zcomp", "erstrm", "ervbs", and "zkey". The directory tree database supports all parameters of the file hash database and "psiz", "rcomp", "pccap" in addition.

  mode

  the connection mode. PolyDB::OWRITER as a writer, PolyDB::OREADER as a reader. The following may be added to the writer mode by bitwise-or: PolyDB::OCREATE, which means it creates a new database if the file does not exist, PolyDB::OTRUNCATE, which means it creates a new database regardless if the file exists, PolyDB::OAUTOTRAN, which means each updating operation is performed in implicit transaction, PolyDB::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: PolyDB::ONOLOCK, which means it opens the database file without file locking, PolyDB::OTRYLOCK, which means locking is performed without blocking, PolyDB::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:
  The tuning parameter "opts" is for the original "tune_options" and the value can contain "s" for the small option, "l" for the linear option, and "c" for the compress option. "bnum" corresponds to "tune_bucket". "zcomp" is for "tune_compressor" and the value can be "zlib" for the ZLIB raw compressor, "def" for the ZLIB deflate compressor, "gz" for the ZLIB gzip compressor, "lzo" for the LZO compressor, "lzma" for the LZMA compressor, or "arc" for the Arcfour cipher. "erstrm" and "ervbs" are for "tune_error_reporter" and the formar value can be "stdout" or "stderr" and the latter value can be "true" or "false". "zkey" specifies the cipher key of the compressor. "capcount" is for "cap_count". "capsize" is for "cap_size". "psiz" is for "tune_page". "rcomp" is for "tune_comparator" and the value can be "lex" for the lexical comparator or "dec" for the decimal comparator. "pccap" is for "tune_page_cache". "apow" is for "tune_alignment". "fpow" is for "tune_fbp". "msiz" is for "tune_map". "dfunit" is for "tune_defrag". Every opened database must be closed by the PolyDB::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::PolyDB::close | ( |  | ) | `[virtual]`

Close the database file.

Returns:
  true on success, or false on failure.

Implements kyotocabinet::BasicDB.

bool kyotocabinet::PolyDB::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::PolyDB::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::PolyDB::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::PolyDB::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::PolyDB::clear | ( |  | ) | `[virtual]`

Remove all records.

Returns:
  true on success, or false on failure.

Implements kyotocabinet::DB.

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

Get the number of records.

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

Implements kyotocabinet::DB.

int64_t kyotocabinet::PolyDB::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::PolyDB::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::PolyDB::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::PolyDB::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.

BasicDB* kyotocabinet::PolyDB::reveal_inner_db | ( |  | ) |

Reveal the inner database object.

Returns:
  the inner database object, or NULL on failure.