Kyoto Tycoon
Public Member Functions | Friends
kyototycoon::TimedDB::Cursor Class Reference

Cursor to indicate a record. More...

#include <kttimeddb.h>

List of all members.

Public Member Functions

 Cursor (TimedDB *db)
 Constructor.
virtual ~Cursor ()
 Destructor.
bool jump ()
 Jump the cursor to the first record for forward scan.
bool jump (const char *kbuf, size_t ksiz)
 Jump the cursor to a record for forward scan.
bool jump (const std::string &key)
 Jump the cursor to a record for forward scan.
bool jump_back ()
 Jump the cursor to the last record for backward scan.
bool jump_back (const char *kbuf, size_t ksiz)
 Jump the cursor to a record for backward scan.
bool jump_back (const std::string &key)
 Jump the cursor to a record for backward scan.
bool step ()
 Step the cursor to the next record.
bool step_back ()
 Step the cursor to the previous record.
bool accept (Visitor *visitor, bool writable=true, bool step=false)
 Accept a visitor to the current record.
bool set_value (const char *vbuf, size_t vsiz, int64_t xt=kc::INT64MAX, bool step=false)
 Set the value of the current record.
bool set_value_str (const std::string &value, int64_t xt=kc::INT64MAX, bool step=false)
 Set the value of the current record.
bool remove ()
 Remove the current record.
char * get_key (size_t *sp, bool step=false)
 Get the key of the current record.
bool get_key (std::string *key, bool step=false)
 Get the key of the current record.
char * get_value (size_t *sp, bool step=false)
 Get the value of the current record.
bool get_value (std::string *value, bool step=false)
 Get the value of the current record.
char * get (size_t *ksp, const char **vbp, size_t *vsp, int64_t *xtp=NULL, bool step=false)
 Get a pair of the key and the value of the current record.
bool get (std::string *key, std::string *value, int64_t *xtp=NULL, bool step=false)
 Get a pair of the key and the value of the current record.
char * seize (size_t *ksp, const char **vbp, size_t *vsp, int64_t *xtp=NULL)
 Get a pair of the key and the value of the current record and remove it atomically.
bool seize (std::string *key, std::string *value, int64_t *xtp=NULL)
 Get a pair of the key and the value of the current record and remove it atomically.
TimedDBdb ()
 Get the database object.
kc::BasicDB::Error error ()
 Get the last happened error.

Friends

class TimedDB

Detailed Description

Cursor to indicate a record.


Constructor & Destructor Documentation

Constructor.

Parameters:
dbthe container database object.

Destructor.


Member Function Documentation

Jump the cursor to the first record for forward scan.

Returns:
true on success, or false on failure.
bool kyototycoon::TimedDB::Cursor::jump ( const char *  kbuf,
size_t  ksiz 
)

Jump the cursor to a record for forward scan.

Parameters:
kbufthe pointer to the key region.
ksizthe size of the key region.
Returns:
true on success, or false on failure.
bool kyototycoon::TimedDB::Cursor::jump ( const std::string &  key)

Jump the cursor to a record for forward scan.

Note:
Equal to the original Cursor::jump method except that the parameter is std::string.

Jump the cursor to the last record for backward scan.

Returns:
true on success, or false on failure.
Note:
This method is dedicated to tree databases. Some database types, especially hash databases, may provide a dummy implementation.
bool kyototycoon::TimedDB::Cursor::jump_back ( const char *  kbuf,
size_t  ksiz 
)

Jump the cursor to a record for backward scan.

Parameters:
kbufthe pointer to the key region.
ksizthe size of the key region.
Returns:
true on success, or false on failure.
Note:
This method is dedicated to tree databases. Some database types, especially hash databases, will provide a dummy implementation.
bool kyototycoon::TimedDB::Cursor::jump_back ( const std::string &  key)

Jump the cursor to a record for backward scan.

Note:
Equal to the original Cursor::jump_back method except that the parameter is std::string.

Step the cursor to the next record.

Returns:
true on success, or false on failure.

Step the cursor to the previous record.

Returns:
true on success, or false on failure.
Note:
This method is dedicated to tree databases. Some database types, especially hash databases, may provide a dummy implementation.
bool kyototycoon::TimedDB::Cursor::accept ( Visitor visitor,
bool  writable = true,
bool  step = false 
)

Accept a visitor to the current record.

Parameters:
visitora visitor object.
writabletrue for writable operation, or false for read-only operation.
steptrue to move the cursor to the next record, or false for no move.
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.
bool kyototycoon::TimedDB::Cursor::set_value ( const char *  vbuf,
size_t  vsiz,
int64_t  xt = kc::INT64MAX,
bool  step = false 
)

Set the value of the current record.

Parameters:
vbufthe pointer to the value region.
vsizthe size of the value region.
xtthe expiration time from now in seconds. If it is negative, the absolute value is treated as the epoch time.
steptrue to move the cursor to the next record, or false for no move.
Returns:
true on success, or false on failure.
bool kyototycoon::TimedDB::Cursor::set_value_str ( const std::string &  value,
int64_t  xt = kc::INT64MAX,
bool  step = false 
)

Set the value of the current record.

Note:
Equal to the original Cursor::set_value method except that the parameter is std::string.

Remove the current record.

Returns:
true on success, or false on failure.
Note:
If no record corresponds to the key, false is returned. The cursor is moved to the next record implicitly.
char* kyototycoon::TimedDB::Cursor::get_key ( size_t *  sp,
bool  step = false 
)

Get the key of the current record.

Parameters:
spthe pointer to the variable into which the size of the region of the return value is assigned.
steptrue to move the cursor to the next record, or false for no move.
Returns:
the pointer to the key region of the current record, or NULL on failure.
Note:
If the cursor is invalidated, 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.
bool kyototycoon::TimedDB::Cursor::get_key ( std::string *  key,
bool  step = false 
)

Get the key of the current record.

Note:
Equal to the original Cursor::get_key method except that a parameter is a string to contain the result and the return value is bool for success.
char* kyototycoon::TimedDB::Cursor::get_value ( size_t *  sp,
bool  step = false 
)

Get the value of the current record.

Parameters:
spthe pointer to the variable into which the size of the region of the return value is assigned.
steptrue to move the cursor to the next record, or false for no move.
Returns:
the pointer to the value region of the current record, or NULL on failure.
Note:
If the cursor is invalidated, 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.
bool kyototycoon::TimedDB::Cursor::get_value ( std::string *  value,
bool  step = false 
)

Get the value of the current record.

Note:
Equal to the original Cursor::get_value method except that a parameter is a string to contain the result and the return value is bool for success.
char* kyototycoon::TimedDB::Cursor::get ( size_t *  ksp,
const char **  vbp,
size_t *  vsp,
int64_t *  xtp = NULL,
bool  step = false 
)

Get a pair of the key and the value of the current record.

Parameters:
kspthe pointer to the variable into which the size of the region of the return value is assigned.
vbpthe pointer to the variable into which the pointer to the value region is assigned.
vspthe pointer to the variable into which the size of the value region is assigned.
xtpthe pointer to the variable into which the absolute expiration time is assigned. If it is NULL, it is ignored.
steptrue to move the cursor to the next record, or false for no move.
Returns:
the pointer to the pair of the key region, or NULL on failure.
Note:
If the cursor is invalidated, NULL is returned. Because an additional zero code is appended at the end of each region of the key and the value, each region can be treated as a C-style string. The return value should be deleted explicitly by the caller with the detele[] operator.
bool kyototycoon::TimedDB::Cursor::get ( std::string *  key,
std::string *  value,
int64_t *  xtp = NULL,
bool  step = false 
)

Get a pair of the key and the value of the current record.

Note:
Equal to the original Cursor::get method except that parameters are strings to contain the result and the return value is bool for success.
char* kyototycoon::TimedDB::Cursor::seize ( size_t *  ksp,
const char **  vbp,
size_t *  vsp,
int64_t *  xtp = NULL 
)

Get a pair of the key and the value of the current record and remove it atomically.

Parameters:
kspthe pointer to the variable into which the size of the region of the return value is assigned.
vbpthe pointer to the variable into which the pointer to the value region is assigned.
vspthe pointer to the variable into which the size of the value region is assigned.
xtpthe pointer to the variable into which the absolute expiration time is assigned. If it is NULL, it is ignored.
Returns:
the pointer to the pair of the key region, or NULL on failure.
Note:
If the cursor is invalidated, NULL is returned. Because an additional zero code is appended at the end of each region of the key and the value, each region can be treated as a C-style string. The return value should be deleted explicitly by the caller with the detele[] operator.
bool kyototycoon::TimedDB::Cursor::seize ( std::string *  key,
std::string *  value,
int64_t *  xtp = NULL 
)

Get a pair of the key and the value of the current record and remove it atomically.

Note:
Equal to the original Cursor::seize method except that parameters are strings to contain the result and the return value is bool for success.

Get the database object.

Returns:
the database object.
kc::BasicDB::Error kyototycoon::TimedDB::Cursor::error ( )

Get the last happened error.

Returns:
the last happened error.