Tkrzw-RPC
Public Member Functions | Friends | List of all members
tkrzw::RemoteDBM::Iterator Class Reference

Iterator for each record. More...

#include <tkrzw_dbm_remote.h>

Public Member Functions

 ~Iterator ()
 Destructor. More...
 
 Iterator (const Iterator &rhs)=delete
 Copy and assignment are disabled. More...
 
Iteratoroperator= (const Iterator &rhs)=delete
 
void Cancel ()
 Cancels the current operation. More...
 
Status First ()
 Initializes the iterator to indicate the first record. More...
 
Status Last ()
 Initializes the iterator to indicate the last record. More...
 
Status Jump (std::string_view key)
 Initializes the iterator to indicate a specific record. More...
 
Status JumpLower (std::string_view key, bool inclusive=false)
 Initializes the iterator to indicate the last record whose key is lower than a given key. More...
 
Status JumpUpper (std::string_view key, bool inclusive=false)
 Initializes the iterator to indicate the first record whose key is upper than a given key. More...
 
Status Next ()
 Moves the iterator to the next record. More...
 
Status Previous ()
 Moves the iterator to the previous record. More...
 
Status Get (std::string *key=nullptr, std::string *value=nullptr)
 Gets the key and the value of the current record of the iterator. More...
 
std::string GetKey (std::string_view default_value="")
 Gets the key of the current record, in a simple way. More...
 
std::string GetValue (std::string_view default_value="")
 Gets the value of the current record, in a simple way. More...
 
Status Set (std::string_view value)
 Sets the value of the current record. More...
 
Status Remove ()
 Removes the current record. More...
 
Status Step (std::string *key=nullptr, std::string *value=nullptr)
 Gets the current record and moves the iterator to the next record. More...
 

Friends

class tkrzw::RemoteDBM
 

Detailed Description

Iterator for each record.

When the database is updated, some iterators may or may not be invalided. Operations with invalidated iterators fails gracefully with NOT_FOUND_ERROR.

An instance of this class dominates a thread on the server so you should destroy when it is no longer in use.

Constructor & Destructor Documentation

◆ ~Iterator()

tkrzw::RemoteDBM::Iterator::~Iterator ( )

Destructor.

◆ Iterator()

tkrzw::RemoteDBM::Iterator::Iterator ( const Iterator rhs)
explicitdelete

Copy and assignment are disabled.

Member Function Documentation

◆ Cancel()

void tkrzw::RemoteDBM::Iterator::Cancel ( )

Cancels the current operation.

This is called by another thread than the thread doing the operation.

◆ First()

Status tkrzw::RemoteDBM::Iterator::First ( )

Initializes the iterator to indicate the first record.

Returns
The result status.

Even if there's no record, the operation doesn't fail.

◆ Last()

Status tkrzw::RemoteDBM::Iterator::Last ( )

Initializes the iterator to indicate the last record.

Returns
The result status.

Even if there's no record, the operation doesn't fail. This method is suppoerted only by ordered databases.

◆ Jump()

Status tkrzw::RemoteDBM::Iterator::Jump ( std::string_view  key)

Initializes the iterator to indicate a specific record.

Parameters
keyThe key of the record to look for.
Returns
The result status.

Ordered databases can support "lower bound" jump; If there's no record with the same key, the iterator refers to the first record whose key is greater than the given key. The operation fails with unordered databases if there's no record with the same key.

◆ JumpLower()

Status tkrzw::RemoteDBM::Iterator::JumpLower ( std::string_view  key,
bool  inclusive = false 
)

Initializes the iterator to indicate the last record whose key is lower than a given key.

Parameters
keyThe key to compare with.
inclusiveIf true, the condition is inclusive: equal to or lower than the key.
Returns
The result status.

Even if there's no matching record, the operation doesn't fail. This method is suppoerted only by ordered databases.

◆ JumpUpper()

Status tkrzw::RemoteDBM::Iterator::JumpUpper ( std::string_view  key,
bool  inclusive = false 
)

Initializes the iterator to indicate the first record whose key is upper than a given key.

Parameters
keyThe key to compare with.
inclusiveIf true, the condition is inclusive: equal to or upper than the key.
Returns
The result status.

Even if there's no matching record, the operation doesn't fail. This method is suppoerted only by ordered databases.

◆ Next()

Status tkrzw::RemoteDBM::Iterator::Next ( )

Moves the iterator to the next record.

Returns
The result status.

If the current record is missing, the operation fails. Even if there's no next record, the operation doesn't fail.

◆ Previous()

Status tkrzw::RemoteDBM::Iterator::Previous ( )

Moves the iterator to the previous record.

Returns
The result status.

If the current record is missing, the operation fails. Even if there's no previous record, the operation doesn't fail. This method is suppoerted only by ordered databases.

◆ Get()

Status tkrzw::RemoteDBM::Iterator::Get ( std::string *  key = nullptr,
std::string *  value = nullptr 
)

Gets the key and the value of the current record of the iterator.

Parameters
keyThe pointer to a string object to contain the record key. If it is nullptr, the key data is ignored.
valueThe pointer to a string object to contain the record value. If it is nullptr, the value data is ignored.
Returns
The result status.

◆ GetKey()

std::string tkrzw::RemoteDBM::Iterator::GetKey ( std::string_view  default_value = "")

Gets the key of the current record, in a simple way.

Parameters
default_valueThe value to be returned on failure.
Returns
The key of the current record on success, or the default value on failure.

◆ GetValue()

std::string tkrzw::RemoteDBM::Iterator::GetValue ( std::string_view  default_value = "")

Gets the value of the current record, in a simple way.

Parameters
default_valueThe value to be returned on failure.
Returns
The value of the current record on success, or the default value on failure.

◆ Set()

Status tkrzw::RemoteDBM::Iterator::Set ( std::string_view  value)

Sets the value of the current record.

Parameters
valueThe value of the record.
Returns
The result status.

◆ Remove()

Status tkrzw::RemoteDBM::Iterator::Remove ( )

Removes the current record.

Returns
The result status.

If possible, the iterator moves to the next record.

◆ Step()

Status tkrzw::RemoteDBM::Iterator::Step ( std::string *  key = nullptr,
std::string *  value = nullptr 
)

Gets the current record and moves the iterator to the next record.

Parameters
keyThe pointer to a string object to contain the record key. If it is nullptr, the key data is ignored.
valueThe pointer to a string object to contain the record value. If it is nullptr, the value data is ignored.
Returns
The result status.