added delete callback to const_list_node

This commit is contained in:
cyborg1811m 2024-01-28 07:58:54 +01:00
parent c328859e2d
commit 5145c5894c
1 changed files with 25 additions and 2 deletions

View File

@ -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>
@ -212,11 +213,18 @@ namespace cc {
const_list_node *_prev = nullptr; const_list_node *_prev = nullptr;
const_list_node *_next = nullptr; const_list_node *_next = nullptr;
const_list<D> *_owner = nullptr; const_list<D> *_owner = nullptr;
void (*_delete_cb)() = nullptr;
public: 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_