forked from blue/lmdbal
73 lines
1.7 KiB
C++
73 lines
1.7 KiB
C++
/*
|
|
* LMDB Abstraction Layer.
|
|
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "session.h"
|
|
|
|
LMDBAL::Session::Session():
|
|
parent(nullptr) {}
|
|
|
|
LMDBAL::Session::Session(Base* parent):
|
|
parent(parent)
|
|
{
|
|
parent->registerSession(this);
|
|
}
|
|
|
|
LMDBAL::Session::Session(Session&& other):
|
|
parent(other.parent)
|
|
{
|
|
if (parent)
|
|
parent->replaceSession(&other, this);
|
|
}
|
|
|
|
LMDBAL::Session::~Session() {
|
|
if (parent)
|
|
parent->unregisterSession(this);
|
|
}
|
|
|
|
LMDBAL::Session& LMDBAL::Session::operator = (Session&& other) {
|
|
if (parent)
|
|
if (other.parent)
|
|
parent->unregisterSession(&other);
|
|
else
|
|
parent->unregisterSession(this);
|
|
else
|
|
if (other.parent)
|
|
other.parent->replaceSession(&other, this);
|
|
|
|
parent = other.parent;
|
|
other.terminate();
|
|
|
|
return *this;
|
|
}
|
|
|
|
void LMDBAL::Session::close() {
|
|
if (!parent)
|
|
return;
|
|
|
|
parent->unregisterSession(this);
|
|
terminate();
|
|
}
|
|
|
|
bool LMDBAL::Session::opened() const {
|
|
return parent != nullptr;
|
|
}
|
|
|
|
void LMDBAL::Session::terminate() {
|
|
parent = nullptr;
|
|
}
|
|
|