blue_noise_generation/src/utility.cpp
Stephen Seo d29d2434ab utility::Cleanup: Replace "Nop"
A default constructor suffices where "Nop" was used, so it was removed.
2024-03-20 19:18:37 +09:00

32 lines
663 B
C++

#include "utility.hpp"
utility::Cleanup::Cleanup(std::function<void(void *)> fn, void *ptr)
: fn(fn), ptr(ptr) {}
utility::Cleanup::Cleanup() : fn(), ptr(nullptr) {}
utility::Cleanup::~Cleanup() {
if (this->fn.has_value()) {
this->fn.value()(this->ptr);
}
}
utility::Cleanup::Cleanup(Cleanup &&other) : fn(other.fn), ptr(other.ptr) {
other.fn = std::nullopt;
other.ptr = nullptr;
}
utility::Cleanup &utility::Cleanup::operator=(utility::Cleanup &&other) {
if (this->fn.has_value()) {
this->fn.value()(this->ptr);
}
this->fn = other.fn;
this->ptr = other.ptr;
other.fn = std::nullopt;
other.ptr = nullptr;
return *this;
}