1
0
mirror of https://github.com/Zygo/bees.git synced 2025-05-18 05:45:45 +02:00

crucible: add cleanup class

Store a function (or closure) in an instance and invoke the function
from the destructor.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
Zygo Blaxell 2017-10-01 15:52:15 -04:00
parent 5a8c655fc4
commit a3cd3ca07f
3 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1,18 @@
#ifndef CRUCIBLE_CLEANER_H
#define CRUCIBLE_CLEANER_H
#include <functional>
namespace crucible {
using namespace std;
class Cleanup {
function<void()> m_cleaner;
public:
Cleanup(function<void()> func);
~Cleanup();
};
}
#endif // CRUCIBLE_CLEANER_H

View File

@ -1,8 +1,9 @@
default: libcrucible.so
OBJS = \
crc64.o \
chatter.o \
cleanup.o \
crc64.o \
error.o \
extentwalker.o \
fd.o \

17
lib/cleanup.cc Normal file
View File

@ -0,0 +1,17 @@
#include <crucible/cleanup.h>
namespace crucible {
Cleanup::Cleanup(function<void()> func) :
m_cleaner(func)
{
}
Cleanup::~Cleanup()
{
if (m_cleaner) {
m_cleaner();
}
}
}