mirror of
https://github.com/Zygo/bees.git
synced 2025-05-17 21:35: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:
parent
6d6aedd8ec
commit
8a68b5f20b
18
include/crucible/cleanup.h
Normal file
18
include/crucible/cleanup.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef CRUCIBLE_CLEANUP_H
|
||||||
|
#define CRUCIBLE_CLEANUP_H
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
namespace crucible {
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class Cleanup {
|
||||||
|
function<void()> m_cleaner;
|
||||||
|
public:
|
||||||
|
Cleanup(function<void()> func);
|
||||||
|
~Cleanup();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // CRUCIBLE_CLEANUP_H
|
@ -3,8 +3,9 @@ TAG := $(shell git describe --always --dirty || echo UNKNOWN)
|
|||||||
default: libcrucible.so
|
default: libcrucible.so
|
||||||
|
|
||||||
OBJS = \
|
OBJS = \
|
||||||
crc64.o \
|
|
||||||
chatter.o \
|
chatter.o \
|
||||||
|
cleanup.o \
|
||||||
|
crc64.o \
|
||||||
error.o \
|
error.o \
|
||||||
extentwalker.o \
|
extentwalker.o \
|
||||||
fd.o \
|
fd.o \
|
||||||
|
17
lib/cleanup.cc
Normal file
17
lib/cleanup.cc
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user