mn_auto_release.hpp
Go to the documentation of this file.
1 
19 #ifndef _MINILIB_cd8c0484_ab57_11eb_9d1f_f714def23089_H__
20 #define _MINILIB_cd8c0484_ab57_11eb_9d1f_f714def23089_H__
21 
22 #include "mn_config.hpp"
23 #include "container/mn_list.hpp"
24 
25 namespace mn {
26 
28  public:
29  using pointer = void*;
31 
32  virtual pointer release() { return nullptr; }
33  virtual selt_type* duplicate() { return this; }
34  };
35 
42  template <class TRELOBJ = auto_release_object, class TALLOCATOR = memory::default_allocator_t >
43  class auto_release {
44  public:
46  using value_type = TRELOBJ;
47  using pointer = TRELOBJ*;
48  using reference = TRELOBJ&;
50 
56 
60  void add(pointer pObject) {
61  if(pObject) m_listReleaseble.push_back(pObject);
62  }
63 
67  void release() {
68  while(!m_listReleaseble.empty()) {
69  m_listReleaseble.front()->release();
71  }
72  }
73 
75  return m_listReleaseble.front();
76  }
78  return m_listReleaseble.back();
79  }
80 
81 
82  private:
84  };
85 }
86 
87 #endif // _MINILIB_cd8c0484_ab57_11eb_9d1f_f714def23089_H__
Definition: mn_auto_release.hpp:27
virtual pointer release()
Definition: mn_auto_release.hpp:32
void * pointer
Definition: mn_auto_release.hpp:29
virtual selt_type * duplicate()
Definition: mn_auto_release.hpp:33
A simple garbage collector - pool based, a object for this colector must be extends auto_release_obje...
Definition: mn_auto_release.hpp:43
list_type m_listReleaseble
Definition: mn_auto_release.hpp:83
void add(pointer pObject)
Add a Object to the pool.
Definition: mn_auto_release.hpp:60
pointer back()
Definition: mn_auto_release.hpp:77
TRELOBJ value_type
Definition: mn_auto_release.hpp:46
auto_release()
Definition: mn_auto_release.hpp:51
void release()
Release all objects in the pool.
Definition: mn_auto_release.hpp:67
pointer front()
Definition: mn_auto_release.hpp:74
TRELOBJ & reference
Definition: mn_auto_release.hpp:48
~auto_release()
Destroy this pool and release all objects.
Definition: mn_auto_release.hpp:55
TRELOBJ * pointer
Definition: mn_auto_release.hpp:47
Definition: mn_list.hpp:77
bool empty() const
Definition: mn_list.hpp:184
const T & back() const
Definition: mn_list.hpp:130
void push_back(const T &value)
Definition: mn_list.hpp:144
void pop_front()
Definition: mn_list.hpp:137
const T & front() const
Definition: mn_list.hpp:127
Definition: mn_allocator_typetraits.hpp:25