1
0
Fork 0
forked from blue/lmdbal

tests, set method, tests for set method

This commit is contained in:
Blue 2023-11-01 19:45:42 -03:00
parent 96d7d9ef64
commit 3307860ca6
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
7 changed files with 316 additions and 15 deletions

View file

@ -81,13 +81,11 @@ LMDBAL::Cursor<K, V>::Cursor(Cursor&& other):
state(other.state),
id(other.id)
{
other.terminated();
if (id != 0)
storage->cursors[id] = this;
other.cursor = nullptr;
other.storage = nullptr;
other.id = 0;
other.state = closed;
other.freed();
}
/**
@ -109,9 +107,7 @@ LMDBAL::Cursor<K, V>& LMDBAL::Cursor<K, V>::operator = (Cursor&& other) {
id = other.id;
if (id != 0) {
other.cursor = nullptr;
other.storage = nullptr;
other.id = 0;
other.freed();
other.state = closed;
storage->cursors[id] = this;
@ -146,20 +142,29 @@ void LMDBAL::Cursor<K, V>::drop () {
if (id != 0)
storage->cursors.erase(id);
cursor = nullptr;
storage = nullptr;
id = 0;
freed();
}
/**
* \brief A private method that turns cursor into an empty one
*
* This function is called from LMDBAL::Storage, when it gets destroyed, but still has some valid.
* This function is called from LMDBAL::Storage, when it gets destroyed, but still has some valid cursors.
* Those cursors will become empty, and can't be used anymore
*/
template<class K, class V>
void LMDBAL::Cursor<K, V>::dropped () {
terminated();
freed();
}
/**
* \brief A private method that turns cursor into an empty one (submethod)
*
* This function is called from LMDBAL::Storage, when the cursor is getting destoryed.
* Those cursors will become empty, and can't be used anymore
*/
template<class K, class V>
void LMDBAL::Cursor<K, V>::freed () {
cursor = nullptr;
storage = nullptr;
id = 0;
@ -585,6 +590,34 @@ std::pair<K, V> LMDBAL::Cursor<K, V>::current () const {
return result;
}
/**
* \brief Sets cursors to the defined position
*
* If exactly the same element wasn't found it sets the cursor to the first
* element greater then the key and returns false
*
* \param[in] key a key of the element you would like the cursor to be
* \returns true if the exact value was found, false otherwise
*
* \exception LMDBAL::CursorNotReady thrown if you try to call this method on a closed cursor
* \exception LMDBAL::Unknown thrown if there was some unexpected problem
*/
template<class K, class V>
bool LMDBAL::Cursor<K, V>::set (const K& key) {
if (state == closed)
storage->throwCursorNotReady(setMethodName);
MDB_val mdbKey = storage->keySerializer.setData(key);
int result = mdb_cursor_get(cursor, &mdbKey, nullptr, MDB_SET);
if (result == MDB_SUCCESS)
return true;
else if (result == MDB_NOTFOUND)
return false;
storage->throwUnknown(result);
return false; //unreachable, just to suppress the warning
}
/**
* \brief a private mothod that actually doing all the reading
*