mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Device: Allow the suppression of disconnects from extensions
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
#ifndef __ICSNEO_LIFETIME_H_
|
||||
#define __ICSNEO_LIFETIME_H_
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class Lifetime {
|
||||
public:
|
||||
Lifetime() = default;
|
||||
Lifetime(std::function<void(void)> onDeath) : fnOnDeath(onDeath) {}
|
||||
~Lifetime() {
|
||||
if(fnOnDeath)
|
||||
fnOnDeath();
|
||||
}
|
||||
|
||||
// Disallow copies so the fnOnDeath only happens once
|
||||
Lifetime(const Lifetime&) = delete;
|
||||
Lifetime& operator=(const Lifetime&) = delete;
|
||||
|
||||
// Explicitly allow moves
|
||||
Lifetime(Lifetime&& moved) { *this = std::move(moved); }
|
||||
Lifetime& operator=(Lifetime&& rhs) {
|
||||
fnOnDeath = std::move(rhs.fnOnDeath);
|
||||
rhs.fnOnDeath = std::function<void(void)>();
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
std::function<void(void)> fnOnDeath;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user