added delete callback to const_list_node
This commit is contained in:
parent
c328859e2d
commit
5145c5894c
|
|
@ -6,6 +6,7 @@
|
||||||
#define UDIFF_CONST_LIST_H_
|
#define UDIFF_CONST_LIST_H_
|
||||||
|
|
||||||
#include <concepts>
|
#include <concepts>
|
||||||
|
#include <functional>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
||||||
|
|
@ -213,10 +214,17 @@ namespace cc {
|
||||||
const_list_node *_next = nullptr;
|
const_list_node *_next = nullptr;
|
||||||
const_list<D> *_owner = nullptr;
|
const_list<D> *_owner = nullptr;
|
||||||
|
|
||||||
public:
|
void (*_delete_cb)() = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
constexpr const_list_node() noexcept { asserts(); }
|
constexpr const_list_node() noexcept { asserts(); }
|
||||||
virtual constexpr ~const_list_node();
|
virtual constexpr ~const_list_node();
|
||||||
|
|
||||||
|
constexpr void on_delete(void (*cb)());
|
||||||
|
|
||||||
|
private:
|
||||||
|
void notify_delete();
|
||||||
|
|
||||||
friend class const_list<D>;
|
friend class const_list<D>;
|
||||||
friend class _const_list_iterator_base<D>;
|
friend class _const_list_iterator_base<D>;
|
||||||
};
|
};
|
||||||
|
|
@ -320,9 +328,24 @@ namespace cc {
|
||||||
template<typename D>
|
template<typename D>
|
||||||
constexpr const_list_node<D>::~const_list_node()
|
constexpr const_list_node<D>::~const_list_node()
|
||||||
{
|
{
|
||||||
|
if (_delete_cb)
|
||||||
|
(*_delete_cb)();
|
||||||
_owner->remove(*this);
|
_owner->remove(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename D>
|
||||||
|
constexpr void const_list_node<D>::on_delete(void (*cb)())
|
||||||
|
{
|
||||||
|
_delete_cb = cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename D>
|
||||||
|
void const_list_node<D>::notify_delete()
|
||||||
|
{
|
||||||
|
if (_delete_cb)
|
||||||
|
(*_delete_cb)();
|
||||||
|
}
|
||||||
|
|
||||||
} // cc
|
} // cc
|
||||||
|
|
||||||
#endif //UDIFF_CONST_LIST_H_
|
#endif //UDIFF_CONST_LIST_H_
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue