blob: bd220ddcd8dcb30b2c3423a60d4834984a1389f7 [file] [log] [blame]
#pragma once
#include <functional>
#include <sdeventplus/internal/sdevent.hpp>
#include <type_traits>
namespace sdeventplus
{
namespace internal
{
template <typename T> class SdRef
{
public:
using Func = std::function<T*(SdEvent*, T*)>;
SdRef(T* ref, Func take_ref, Func release_ref,
SdEvent* sdevent = &sdevent_impl);
SdRef(T* ref, Func take_ref, Func release_ref, std::false_type,
SdEvent* sdevent = &sdevent_impl);
virtual ~SdRef();
SdRef(const SdRef& other);
SdRef& operator=(const SdRef& other);
SdRef(SdRef&& other) = default;
SdRef& operator=(SdRef&& other);
T* get() const;
private:
SdEvent* sdevent;
Func take_ref;
Func release_ref;
T* ref;
};
} // namespace internal
} // namespace sdeventplus