pica/database/resource.cpp

39 lines
806 B
C++
Raw Normal View History

2023-12-30 22:42:11 +00:00
//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
//SPDX-License-Identifier: GPL-3.0-or-later
2023-12-29 17:40:00 +00:00
#include "resource.h"
#include "pool.h"
DB::Resource::Resource (
std::unique_ptr<Interface> interface,
std::weak_ptr<Pool> parent
):
parent(parent),
interface(std::move(interface))
{}
DB::Resource::Resource(Resource&& other):
parent(other.parent),
interface(std::move(other.interface))
{}
DB::Resource::~Resource() {
if (!interface)
return;
if (std::shared_ptr<Pool> p = parent.lock())
p->free(std::move(interface));
}
DB::Resource& DB::Resource::operator = (Resource&& other) {
parent = other.parent;
interface = std::move(other.interface);
return *this;
}
DB::Interface* DB::Resource::operator -> () {
return interface.get();
}