Files
ORB_SLAM3_Win/Thirdparty/Pangolin/include/pangolin/utils/registration.h
PodmogilnyjIvan ff4acf84be raw
2021-12-03 03:34:31 -08:00

65 lines
1.0 KiB
C++

#pragma once
#include <functional>
namespace pangolin {
template<typename TokenType=void>
class Registration
{
public:
using UnregisterFunc = std::function<void(const TokenType&)>;
Registration()
: token()
{
}
Registration(TokenType token, UnregisterFunc unregister)
: token(token), unregister(unregister)
{
}
// No copy constructor
Registration(const Registration&) = delete;
// Default move constructor
Registration(Registration&& o)
{
*this = std::move(o);
}
Registration<TokenType>& operator =(Registration<TokenType>&& o)
{
token = o.token;
unregister = std::move(o.unregister);
o.unregister = nullptr;
return *this;
}
~Registration()
{
Release();
}
void Release()
{
if(unregister) {
unregister(token);
token = TokenType();
}
}
const TokenType& Token()
{
return token;
}
private:
TokenType token;
UnregisterFunc unregister;
};
}