Kyoto Cabinet: kyotocabinet::DB Class Reference

Kyoto Cabinet

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Classes | Public Member Functions
kyotocabinet::DB Class Reference

Interface of database abstraction. More...

`#include <kcdb.h>`

List of all members.

## Classes
class | Cursor
| Interface of cursor to indicate a record. More...
class | Visitor
| Interface to access a record. More...
## Public Member Functions
virtual | ~DB ()
| Destructor.
virtual bool | accept (const char *kbuf, size_t ksiz, Visitor *visitor, bool writable=true)=0
| Accept a visitor to a record.
virtual bool | set (const char *kbuf, size_t ksiz, const char *vbuf, size_t vsiz)=0
| Set the value of a record.
virtual bool | set (const std::string &key, const std::string &value)=0
| Set the value of a record.
virtual bool | add (const char *kbuf, size_t ksiz, const char *vbuf, size_t vsiz)=0
| Add a record.
virtual bool | add (const std::string &key, const std::string &value)=0
| Set the value of a record.
virtual bool | replace (const char *kbuf, size_t ksiz, const char *vbuf, size_t vsiz)=0
| Replace the value of a record.
virtual bool | replace (const std::string &key, const std::string &value)=0
| Replace the value of a record.
virtual bool | append (const char *kbuf, size_t ksiz, const char *vbuf, size_t vsiz)=0
| Append the value of a record.
virtual bool | append (const std::string &key, const std::string &value)=0
| Set the value of a record.
virtual int64_t | increment (const char *kbuf, size_t ksiz, int64_t num, int64_t orig=0)=0
| Add a number to the numeric integer value of a record.
virtual int64_t | increment (const std::string &key, int64_t num, int64_t orig=0)=0
| Add a number to the numeric integer value of a record.
virtual double | increment_double (const char *kbuf, size_t ksiz, double num, double orig=0)=0
| Add a number to the numeric double value of a record.
virtual double | increment_double (const std::string &key, double num, double orig=0)=0
| Add a number to the numeric double value of a record.
virtual bool | cas (const char *kbuf, size_t ksiz, const char *ovbuf, size_t ovsiz, const char *nvbuf, size_t nvsiz)=0
| Perform compare-and-swap.
virtual bool | cas (const std::string &key, const std::string &ovalue, const std::string &nvalue)=0
| Perform compare-and-swap.
virtual bool | remove (const char *kbuf, size_t ksiz)=0
| Remove a record.
virtual bool | remove (const std::string &key)=0
| Remove a record.
virtual char * | get (const char *kbuf, size_t ksiz, size_t *sp)=0
| Retrieve the value of a record.
virtual bool | get (const std::string &key, std::string *value)=0
| Retrieve the value of a record.
virtual int32_t | get (const char *kbuf, size_t ksiz, char *vbuf, size_t max)=0
| Retrieve the value of a record.
virtual int32_t | check (const char *kbuf, size_t ksiz)=0
| Check the existence of a record.
virtual int32_t | check (const std::string &key)=0
| Check the existence of a record.
virtual bool | clear ()=0
| Remove all records.
virtual int64_t | count ()=0
| Get the number of records.
virtual Cursor * | cursor ()=0
| Create a cursor object.

## Detailed Description

Interface of database abstraction.

Note:
  This class is an abstract class to prescribe the interface of record access.

## Constructor & Destructor Documentation

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

Destructor.

## Member Function Documentation

virtual bool kyotocabinet::DB::accept | ( | const char * | kbuf,
|  | size_t | ksiz,
|  | Visitor * | visitor,
|  | bool | writable = `true`
| ) |  | `[pure 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. To avoid deadlock, any explicit database operation must not be performed in this function.

Implemented in kyotocabinet::PlantDB< BASEDB, DBTYPE >, kyotocabinet::HashDB, kyotocabinet::DirDB, kyotocabinet::CacheDB, kyotocabinet::ProtoDB< STRMAP, DBTYPE >, kyotocabinet::TextDB, kyotocabinet::StashDB, and kyotocabinet::PolyDB.

virtual bool kyotocabinet::DB::set | ( | const char * | kbuf,
|  | size_t | ksiz,
|  | const char * | vbuf,
|  | size_t | vsiz
| ) |  | `[pure virtual]`

Set the value of a record.

Parameters:

  kbuf | the pointer to the key region.
  ksiz | the size of the key region.
  vbuf | the pointer to the value region.
  vsiz | the size of the value region.

Returns:
  true on success, or false on failure.

Note:
  If no record corresponds to the key, a new record is created. If the corresponding record exists, the value is overwritten.

Implemented in kyotocabinet::BasicDB.

virtual bool kyotocabinet::DB::set | ( | const std::string & | key,
|  | const std::string & | value
| ) |  | `[pure virtual]`

Set the value of a record.

Note:
  Equal to the original DB::set method except that the parameters are std::string.

Implemented in kyotocabinet::BasicDB.

virtual bool kyotocabinet::DB::add | ( | const char * | kbuf,
|  | size_t | ksiz,
|  | const char * | vbuf,
|  | size_t | vsiz
| ) |  | `[pure virtual]`

Add a record.

Parameters:

  kbuf | the pointer to the key region.
  ksiz | the size of the key region.
  vbuf | the pointer to the value region.
  vsiz | the size of the value region.

Returns:
  true on success, or false on failure.

Note:
  If no record corresponds to the key, a new record is created. If the corresponding record exists, the record is not modified and false is returned.

Implemented in kyotocabinet::BasicDB.

virtual bool kyotocabinet::DB::add | ( | const std::string & | key,
|  | const std::string & | value
| ) |  | `[pure virtual]`

Set the value of a record.

Note:
  Equal to the original DB::add method except that the parameters are std::string.

Implemented in kyotocabinet::BasicDB.

virtual bool kyotocabinet::DB::replace | ( | const char * | kbuf,
|  | size_t | ksiz,
|  | const char * | vbuf,
|  | size_t | vsiz
| ) |  | `[pure virtual]`

Replace the value of a record.

Parameters:

  kbuf | the pointer to the key region.
  ksiz | the size of the key region.
  vbuf | the pointer to the value region.
  vsiz | the size of the value region.

Returns:
  true on success, or false on failure.

Note:
  If no record corresponds to the key, no new record is created and false is returned. If the corresponding record exists, the value is modified.

Implemented in kyotocabinet::BasicDB.

virtual bool kyotocabinet::DB::replace | ( | const std::string & | key,
|  | const std::string & | value
| ) |  | `[pure virtual]`

Replace the value of a record.

Note:
  Equal to the original DB::replace method except that the parameters are std::string.

Implemented in kyotocabinet::BasicDB.

virtual bool kyotocabinet::DB::append | ( | const char * | kbuf,
|  | size_t | ksiz,
|  | const char * | vbuf,
|  | size_t | vsiz
| ) |  | `[pure virtual]`

Append the value of a record.

Parameters:

  kbuf | the pointer to the key region.
  ksiz | the size of the key region.
  vbuf | the pointer to the value region.
  vsiz | the size of the value region.

Returns:
  true on success, or false on failure.

Note:
  If no record corresponds to the key, a new record is created. If the corresponding record exists, the given value is appended at the end of the existing value.

Implemented in kyotocabinet::BasicDB.

virtual bool kyotocabinet::DB::append | ( | const std::string & | key,
|  | const std::string & | value
| ) |  | `[pure virtual]`

Set the value of a record.

Note:
  Equal to the original DB::append method except that the parameters are std::string.

Implemented in kyotocabinet::BasicDB.

virtual int64_t kyotocabinet::DB::increment | ( | const char * | kbuf,
|  | size_t | ksiz,
|  | int64_t | num,
|  | int64_t | orig = `0`
| ) |  | `[pure virtual]`

Add a number to the numeric integer value of a record.

Parameters:

  kbuf | the pointer to the key region.
  ksiz | the size of the key region.
  num | the additional number.
  orig | the origin number if no record corresponds to the key. If it is INT64MIN and no record corresponds, this function fails. If it is INT64MAX, the value is set as the additional number regardless of the current value.

Returns:
  the result value, or kyotocabinet::INT64MIN on failure.

Note:
  The value is serialized as an 8-byte binary integer in big-endian order, not a decimal string. If existing value is not 8-byte, this function fails.

Implemented in kyotocabinet::BasicDB.

virtual int64_t kyotocabinet::DB::increment | ( | const std::string & | key,
|  | int64_t | num,
|  | int64_t | orig = `0`
| ) |  | `[pure virtual]`

Add a number to the numeric integer value of a record.

Note:
  Equal to the original DB::increment method except that the parameter is std::string.

Implemented in kyotocabinet::BasicDB.

virtual double kyotocabinet::DB::increment_double | ( | const char * | kbuf,
|  | size_t | ksiz,
|  | double | num,
|  | double | orig = `0`
| ) |  | `[pure virtual]`

Add a number to the numeric double value of a record.

Parameters:

  kbuf | the pointer to the key region.
  ksiz | the size of the key region.
  num | the additional number.
  orig | the origin number if no record corresponds to the key. If it is negative infinity and no record corresponds, this function fails. If it is positive infinity, the value is set as the additional number regardless of the current value.

Returns:
  the result value, or Not-a-number on failure.

Note:
  The value is serialized as an 16-byte binary fixed-point number in big-endian order, not a decimal string. If existing value is not 16-byte, this function fails.

Implemented in kyotocabinet::BasicDB.

virtual double kyotocabinet::DB::increment_double | ( | const std::string & | key,
|  | double | num,
|  | double | orig = `0`
| ) |  | `[pure virtual]`

Add a number to the numeric double value of a record.

Note:
  Equal to the original DB::increment_double method except that the parameter is std::string.

Implemented in kyotocabinet::BasicDB.

virtual bool kyotocabinet::DB::cas | ( | const char * | kbuf,
|  | size_t | ksiz,
|  | const char * | ovbuf,
|  | size_t | ovsiz,
|  | const char * | nvbuf,
|  | size_t | nvsiz
| ) |  | `[pure virtual]`

Perform compare-and-swap.

Parameters:

  kbuf | the pointer to the key region.
  ksiz | the size of the key region.
  ovbuf | the pointer to the old value region. NULL means that no record corresponds.
  ovsiz | the size of the old value region.
  nvbuf | the pointer to the new value region. NULL means that the record is removed.
  nvsiz | the size of new old value region.

Returns:
  true on success, or false on failure.

Implemented in kyotocabinet::BasicDB.

virtual bool kyotocabinet::DB::cas | ( | const std::string & | key,
|  | const std::string & | ovalue,
|  | const std::string & | nvalue
| ) |  | `[pure virtual]`

Perform compare-and-swap.

Note:
  Equal to the original DB::cas method except that the parameters are std::string.

Implemented in kyotocabinet::BasicDB.

virtual bool kyotocabinet::DB::remove | ( | const char * | kbuf,
|  | size_t | ksiz
| ) |  | `[pure virtual]`

Remove a record.

Parameters:

  kbuf | the pointer to the key region.
  ksiz | the size of the key region.

Returns:
  true on success, or false on failure.

Note:
  If no record corresponds to the key, false is returned.

Implemented in kyotocabinet::BasicDB.

virtual bool kyotocabinet::DB::remove | ( | const std::string & | key | ) | `[pure virtual]`

Remove a record.

Note:
  Equal to the original DB::remove method except that the parameter is std::string.

Implemented in kyotocabinet::BasicDB.

virtual char* kyotocabinet::DB::get | ( | const char * | kbuf,
|  | size_t | ksiz,
|  | size_t * | sp
| ) |  | `[pure virtual]`

Retrieve the value of a record.

Parameters:

  kbuf | the pointer to the key region.
  ksiz | the size of the key region.
  sp | the pointer to the variable into which the size of the region of the return value is assigned.

Returns:
  the pointer to the value region of the corresponding record, or NULL on failure.

Note:
  If no record corresponds to the key, NULL is returned. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a C-style string. Because the region of the return value is allocated with the the new[] operator, it should be released with the delete[] operator when it is no longer in use.

Implemented in kyotocabinet::BasicDB.

virtual bool kyotocabinet::DB::get | ( | const std::string & | key,
|  | std::string * | value
| ) |  | `[pure virtual]`

Retrieve the value of a record.

Note:
  Equal to the original DB::get method except that the first parameters is the key string and the second parameter is a string to contain the result and the return value is bool for success.

Implemented in kyotocabinet::BasicDB.

virtual int32_t kyotocabinet::DB::get | ( | const char * | kbuf,
|  | size_t | ksiz,
|  | char * | vbuf,
|  | size_t | max
| ) |  | `[pure virtual]`

Retrieve the value of a record.

Parameters:

  kbuf | the pointer to the key region.
  ksiz | the size of the key region.
  vbuf | the pointer to the buffer into which the value of the corresponding record is written.
  max | the size of the buffer.

Returns:
  the size of the value, or -1 on failure.

Implemented in kyotocabinet::BasicDB.

virtual int32_t kyotocabinet::DB::check | ( | const char * | kbuf,
|  | size_t | ksiz
| ) |  | `[pure virtual]`

Check the existence of a record.

Parameters:

  kbuf | the pointer to the key region.
  ksiz | the size of the key region.

Returns:
  the size of the value, or -1 on failure.

Implemented in kyotocabinet::BasicDB.

virtual int32_t kyotocabinet::DB::check | ( | const std::string & | key | ) | `[pure virtual]`

Check the existence of a record.

Note:
  Equal to the original DB::check method except that the parameter is std::string.

Implemented in kyotocabinet::BasicDB.

virtual bool kyotocabinet::DB::clear | ( |  | ) | `[pure virtual]`

Remove all records.

Returns:
  true on success, or false on failure.

Implemented in kyotocabinet::PlantDB< BASEDB, DBTYPE >, kyotocabinet::HashDB, kyotocabinet::PolyDB, kyotocabinet::DirDB, kyotocabinet::ProtoDB< STRMAP, DBTYPE >, kyotocabinet::CacheDB, kyotocabinet::StashDB, and kyotocabinet::TextDB.

virtual int64_t kyotocabinet::DB::count | ( |  | ) | `[pure virtual]`

Get the number of records.

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

Implemented in kyotocabinet::PlantDB< BASEDB, DBTYPE >, kyotocabinet::HashDB, kyotocabinet::PolyDB, kyotocabinet::DirDB, kyotocabinet::ProtoDB< STRMAP, DBTYPE >, kyotocabinet::CacheDB, kyotocabinet::StashDB, and kyotocabinet::TextDB.

virtual Cursor* kyotocabinet::DB::cursor | ( |  | ) | `[pure 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.

Implemented in kyotocabinet::BasicDB, kyotocabinet::PlantDB< BASEDB, DBTYPE >, kyotocabinet::PolyDB, kyotocabinet::HashDB, kyotocabinet::DirDB, kyotocabinet::ProtoDB< STRMAP, DBTYPE >, kyotocabinet::CacheDB, kyotocabinet::StashDB, and kyotocabinet::TextDB.