39 lines
806 B
C++
39 lines
806 B
C++
//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
|
//SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#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();
|
|
}
|