First attempt to make RAII cursors, no tests yet
All checks were successful
Main LMDBAL workfow / Archlinux (push) Successful in 40s

This commit is contained in:
Blue 2023-10-25 19:18:23 -03:00
parent a0eebc978d
commit 96d7d9ef64
Signed by: blue
GPG key ID: 9B203B252A63EE38
12 changed files with 374 additions and 233 deletions

View file

@ -58,8 +58,8 @@ LMDBAL::Storage<K, V>::Storage(Base* parent, const std::string& name, bool dupli
*/
template<class K, class V>
LMDBAL::Storage<K, V>::~Storage() {
for (Cursor<K, V>* cursor : cursors)
delete cursor;
for (const std::pair<const uint32_t, Cursor<K, V>*>& pair : cursors)
pair.second->dropped();
}
/**
@ -1013,8 +1013,8 @@ int LMDBAL::Storage<K, V>::open(MDB_txn* transaction) {
*/
template<class K, class V>
void LMDBAL::Storage<K, V>::close() {
for (Cursor<K, V>* cursor : cursors)
cursor->terminated();
for (const std::pair<const uint32_t, Cursor<K, V>*>& pair : cursors)
pair.second->terminated();
iStorage::close();
}
@ -1025,11 +1025,8 @@ void LMDBAL::Storage<K, V>::close() {
* \returns LMDBAL::Cursor for this storage and returs you a pointer to a created cursor
*/
template<class K, class V>
LMDBAL::Cursor<K, V>* LMDBAL::Storage<K, V>::createCursor() {
Cursor<K, V>* cursor = new Cursor<K, V>(this);
cursors.insert(cursor);
return cursor;
LMDBAL::Cursor<K, V> LMDBAL::Storage<K, V>::createCursor() {
return Cursor<K, V>(this);
}
/**
@ -1056,25 +1053,6 @@ uint32_t LMDBAL::Storage<K, V>::flags() const {
return result;
}
/**
* \brief Destroys cursor
*
* This a normal way to discard a cursor you don't need anymore
*
* \param[in] cursor a pointer to a cursor you want to destroy
*
* \exception LMDBAL::Unknown thrown if you try to destroy something that this storage didn't create
*/
template<class K, class V>
void LMDBAL::Storage<K, V>::destroyCursor(Cursor<K, V>* cursor) {
typename std::set<Cursor<K, V>*>::const_iterator itr = cursors.find(cursor);
if (itr == cursors.end())
throwUnknown("An attempt to destroy a cursor the storage doesn't own");
cursors.erase(itr);
delete cursor;
}
/**
* \brief A private virtual method that cursor calls when he reads a record, does nothing here but populates the LMDBAL::Cache
*