MythTV  master
autodeletedeque.h
Go to the documentation of this file.
1 #ifndef AUTO_DELETE_DEQUE_H
2 #define AUTO_DELETE_DEQUE_H
3 
4 // C++ headers
5 #include <deque>
6 
7 template<typename T>
9 {
10  public:
11  explicit AutoDeleteDeque(bool auto_delete = true) : m_autodelete(auto_delete) {}
13 
14  using List = typename std::deque< T >;
15  using iterator = typename List::iterator;
16  using const_iterator = typename List::const_iterator;
17  using reverse_iterator = typename List::reverse_iterator;
18  using const_reverse_iterator = typename List::const_reverse_iterator;
19 
20  T operator[](uint index)
21  {
22  if (index < m_list.size())
23  return m_list[index];
24  return nullptr;
25  }
26  T operator[](uint index) const
27  {
28  if (index < m_list.size())
29  return m_list[index];
30  return nullptr;
31  }
32 
33  T take(uint i);
35  {
36  if (m_autodelete)
37  delete *it;
38  return m_list.erase(it);
39  }
40  void clear(void)
41  {
42  while (m_autodelete && !m_list.empty())
43  {
44  delete m_list.back();
45  m_list.pop_back();
46  }
47  m_list.clear();
48  }
49 
50  iterator begin(void) { return m_list.begin(); }
51  iterator end(void) { return m_list.end(); }
52  const_iterator begin(void) const { return m_list.begin(); }
53  const_iterator end(void) const { return m_list.end(); }
54  const_iterator cbegin(void) const { return m_list.begin(); }
55  const_iterator cend(void) const { return m_list.end(); }
56  reverse_iterator rbegin(void) { return m_list.rbegin(); }
57  reverse_iterator rend(void) { return m_list.rend(); }
58  const_reverse_iterator rbegin(void) const { return m_list.rbegin(); }
59  const_reverse_iterator rend(void) const { return m_list.rend(); }
60  const_reverse_iterator crbegin(void) const { return m_list.rbegin(); }
61  const_reverse_iterator crend(void) const { return m_list.rend(); }
62 
63  T back(void) { return m_list.back(); }
64  T back(void) const { return m_list.back(); }
65 
66  bool empty(void) const { return m_list.empty(); }
67  size_t size(void) const { return m_list.size(); }
68  void push_front(T info) { m_list.push_front(info); }
69  void push_back( T info) { m_list.push_back( info); }
70 
71  // compatibility with old Q3PtrList
72  void setAutoDelete(bool auto_delete) { m_autodelete = auto_delete; }
73 
74  protected:
77 };
78 
79 template<typename T>
81 {
82  iterator it = m_list.begin();
83  for (uint i = 0; i < index; i++, ++it)
84  {
85  if (it == m_list.end())
86  return nullptr;
87  }
88  T info = *it;
89  m_list.erase(it);
90  return info;
91 }
92 
93 #endif // AUTO_DELETE_DEQUE_H
AutoDeleteDeque::~AutoDeleteDeque
~AutoDeleteDeque()
Definition: autodeletedeque.h:12
AutoDeleteDeque::take
T take(uint i)
Definition: autodeletedeque.h:80
AutoDeleteDeque::cbegin
const_iterator cbegin(void) const
Definition: autodeletedeque.h:54
AutoDeleteDeque::clear
void clear(void)
Definition: autodeletedeque.h:40
AutoDeleteDeque::empty
bool empty(void) const
Definition: autodeletedeque.h:66
AutoDeleteDeque::m_list
List m_list
Definition: autodeletedeque.h:75
AutoDeleteDeque::rend
const_reverse_iterator rend(void) const
Definition: autodeletedeque.h:59
AutoDeleteDeque::AutoDeleteDeque
AutoDeleteDeque(bool auto_delete=true)
Definition: autodeletedeque.h:11
AutoDeleteDeque::begin
iterator begin(void)
Definition: autodeletedeque.h:50
AutoDeleteDeque::back
T back(void)
Definition: autodeletedeque.h:63
AutoDeleteDeque::setAutoDelete
void setAutoDelete(bool auto_delete)
Definition: autodeletedeque.h:72
AutoDeleteDeque::rbegin
const_reverse_iterator rbegin(void) const
Definition: autodeletedeque.h:58
AutoDeleteDeque::push_front
void push_front(T info)
Definition: autodeletedeque.h:68
AutoDeleteDeque::rend
reverse_iterator rend(void)
Definition: autodeletedeque.h:57
AutoDeleteDeque< ProgramInfo * >::const_iterator
typename List::const_iterator const_iterator
Definition: autodeletedeque.h:16
AutoDeleteDeque::begin
const_iterator begin(void) const
Definition: autodeletedeque.h:52
AutoDeleteDeque::crend
const_reverse_iterator crend(void) const
Definition: autodeletedeque.h:61
AutoDeleteDeque::back
T back(void) const
Definition: autodeletedeque.h:64
uint
unsigned int uint
Definition: compat.h:81
AutoDeleteDeque::end
iterator end(void)
Definition: autodeletedeque.h:51
AutoDeleteDeque::m_autodelete
bool m_autodelete
Definition: autodeletedeque.h:76
AutoDeleteDeque
Definition: autodeletedeque.h:8
AutoDeleteDeque< ProgramInfo * >::reverse_iterator
typename List::reverse_iterator reverse_iterator
Definition: autodeletedeque.h:17
AutoDeleteDeque::push_back
void push_back(T info)
Definition: autodeletedeque.h:69
AutoDeleteDeque::end
const_iterator end(void) const
Definition: autodeletedeque.h:53
AutoDeleteDeque< ProgramInfo * >::List
typename std::deque< ProgramInfo * > List
Definition: autodeletedeque.h:14
AutoDeleteDeque::rbegin
reverse_iterator rbegin(void)
Definition: autodeletedeque.h:56
azlyrics.info
dictionary info
Definition: azlyrics.py:7
AutoDeleteDeque::cend
const_iterator cend(void) const
Definition: autodeletedeque.h:55
AutoDeleteDeque::operator[]
T operator[](uint index) const
Definition: autodeletedeque.h:26
AutoDeleteDeque::erase
iterator erase(iterator it)
Definition: autodeletedeque.h:34
AutoDeleteDeque< ProgramInfo * >::const_reverse_iterator
typename List::const_reverse_iterator const_reverse_iterator
Definition: autodeletedeque.h:18
AutoDeleteDeque< ProgramInfo * >::iterator
typename List::iterator iterator
Definition: autodeletedeque.h:15
AutoDeleteDeque::crbegin
const_reverse_iterator crbegin(void) const
Definition: autodeletedeque.h:60
AutoDeleteDeque::operator[]
T operator[](uint index)
Definition: autodeletedeque.h:20
AutoDeleteDeque::size
size_t size(void) const
Definition: autodeletedeque.h:67