1 #ifndef _GLIBMM_HELPERLIST_H
2 #define _GLIBMM_HELPERLIST_H
3 
4 /* helperlist.h
5  *
6  * Copyright 2002 The gtkmm Development Team
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 // This is not hidden by GLIBMM_DISABLE_DEPRECATED
23 // because gtkmm-2.24 still uses this type in its public API.
24 // Note that gtkmm-2.24 itself is completely deprecated, so we really
25 // can remove this whole class some time soon.
26 //#ifndef GLIBMM_DISABLE_DEPRECATED
27 
28 #include <glibmm/containers.h>
29 
30 namespace Glib
31 {
32 
33 // This class has some pure virtual methods which need to be implemented by derived classes.
34 
35 /**
36  * @deprecated This class should no longer be necessary. It has not been used
37  * by glibmm or gtkmm since gtkmm-2.4.
38  */
39 template <typename T_Child, typename T_CppElement, typename T_Iterator>
40 class HelperList
41 {
42 public:
HelperList()43   HelperList() : gparent_(nullptr) {}
44 
HelperList(GObject * gp)45   HelperList(GObject*
46       gp) // We use gp instead of gparent because that can cause warnings about a shadowed member.
47     : gparent_(gp)
48   {
49   }
50 
~HelperList()51   virtual ~HelperList() noexcept {}
52 
53   using value_type = T_Child;
54   using reference = value_type&;
55   using const_reference = const value_type&;
56 
57   using iterator = T_Iterator;
58   using const_iterator = List_ConstIterator<iterator>;
59   using reverse_iterator = List_ReverseIterator<iterator>;
60   using const_reverse_iterator = List_ConstIterator<reverse_iterator>;
61 
62   using element_type = T_CppElement;
63 
64   using difference_type = std::size_t; // TODO Why not std::ptrdiff_t?
65   using size_type = std::size_t;
66 
67   // These are implemented differently for each Helper List.
68   virtual iterator erase(iterator) = 0;
69 
erase(iterator start,iterator stop)70   virtual void erase(iterator start, iterator stop)
71   {
72     while (start != stop)
73       start = erase(start); // Implemented in derived class.
74   }
75 
76   virtual void remove(const_reference) = 0;
77 
size()78   size_type size() const { return g_list_length(glist()); }
79 
max_size()80   inline size_type max_size() { return size_type(-1); }
empty()81   inline bool empty() { return glist() == nullptr; }
82 
begin()83   inline iterator begin() { return begin_(); }
end()84   inline iterator end() { return end_(); }
85 
begin()86   inline const_iterator begin() const { return const_iterator(begin_()); }
end()87   inline const_iterator end() const { return const_iterator(end_()); }
88 
rbegin()89   inline reverse_iterator rbegin() { return reverse_iterator(end_()); }
rend()90   inline reverse_iterator rend() { return reverse_iterator(begin_()); }
91 
rbegin()92   inline const_reverse_iterator rbegin() const
93   {
94     return const_reverse_iterator(reverse_iterator(end_()));
95   }
rend()96   inline const_reverse_iterator rend() const
97   {
98     return const_reverse_iterator(reverse_iterator(begin_()));
99   }
100 
front()101   reference front() const { return *begin(); }
102 
back()103   reference back() const { return *(--end()); }
104 
105   reference operator[](size_type l) const
106   {
107     size_type j = 0;
108     iterator i;
109     for (i = begin(), j = 0; i != end() && j < l; ++i, ++j)
110       ;
111     return (*i);
112   }
113 
114   //  iterator find(const_reference w)
115   //  {
116   //    iterator i = begin();
117   //    for(i = begin(); i != end() && (*i != w); i++);
118   //    return i;
119   //  }
120   //
121   //  iterator find(Widget& w)
122   //  {
123   //    iterator i;
124   //    for (i = begin(); i != end() && ((*i)->$1() != &w); i++);
125   //    return i;
126   //  }
127 
128   // Derived classes might choose to reimplement these as public:
pop_front()129   inline void pop_front() { erase(begin()); }
pop_back()130   inline void pop_back() { erase(--end()); }
131 
clear()132   void clear() { erase(begin(), end()); }
133 
gparent()134   GObject* gparent() { return gparent_; };
gparent()135   const GObject* gparent() const { return gparent_; };
136 
137 protected:
138   virtual GList*& glist() const = 0; // front of list
139 
begin_()140   iterator begin_() const { return iterator(glist(), glist()); }
141 
end_()142   iterator end_() const { return iterator(glist(), (GList*)nullptr); }
143 
144   GObject* gparent_;
145 };
146 
147 } /* namespace Glib */
148 
149 //#endif //GLIBMM_DISABLE_DEPRECATED
150 
151 #endif /* _GLIBMM_HELPERLIST_H */
152