Itasca C++ Interface
Loading...
Searching...
No Matches
ideletenotice.h
1#pragma once
2
3#include <cassert>
4
5namespace itasca {
6 class IThing;
7
8 // Note: This class does not auto-remove itself on destruction!
10 public:
11 inline IDeleteNotice() { }
12 virtual inline ~IDeleteNotice() { assert(next_ == nullptr); assert(prev_ == nullptr); }
13 virtual void onDelete(IThing *pnt)=0;
14 virtual void changeToNewPointer(IThing *oldPnt,IThing *newPnt)=0;
15 inline void insert(IDeleteNotice **head);
16 inline void remove(IDeleteNotice **head);
17 inline bool isInserted() const { return next_ ? true : false; }
18 inline IDeleteNotice *nextDeleteNotice() { return next_; }
19 private:
20 IDeleteNotice(const IDeleteNotice &) = delete;
21 IDeleteNotice(IDeleteNotice &&) = delete;
22 void operator=(const IDeleteNotice &) = delete;
23 IDeleteNotice *next_ = nullptr;
24 IDeleteNotice *prev_ = nullptr;
25 };
26
27 inline void IDeleteNotice::insert(IDeleteNotice **head) {
28 assert(prev_==nullptr);
29 assert(next_==nullptr);
30 assert(head);
31 next_ = *head;
32 if (*head) (*head)->prev_ = this;
33 *head = this;
34 }
35
36 inline void IDeleteNotice::remove(IDeleteNotice **head) {
37 assert(head);
38 if (prev_) prev_->next_ = next_;
39 else if (*head==this) *head = next_;
40 if (next_) next_->prev_ = prev_;
41 next_ = prev_ = nullptr;
42 }
43
44} // namespace itasca
45// EoF
Definition ideletenotice.h:9
Base class for items that will be stored in containers.
Definition ithing.h:30
namespace Itasca
Definition basememory.cpp:14