2 #ifndef _GLIBMM_HELPERLIST_H
3 #define _GLIBMM_HELPERLIST_H
4 /* $Id: helperlist.h 386 2007-03-23 17:31:16Z murrayc $ */
8 * Copyright 2002 The gtkmm Development Team
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the Free
22 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <glibmm/containers.h>
30 // This class has some pure virtual methods which need to be implemented by derived classes.
31 template< typename T_Child, typename T_CppElement, typename T_Iterator >
39 HelperList(GObject* gp) //We use gp instead of gparent because that can cause warnings about a shadowed member.
46 typedef T_Child value_type;
47 typedef value_type& reference;
48 typedef const value_type& const_reference;
50 typedef T_Iterator iterator;
51 typedef List_ConstIterator<iterator> const_iterator;
52 typedef List_ReverseIterator<iterator> reverse_iterator;
53 typedef List_ConstIterator<reverse_iterator> const_reverse_iterator;
55 typedef T_CppElement element_type;
57 typedef size_t difference_type;
58 typedef size_t size_type;
60 //These are implemented differently for each Helper List.
61 virtual iterator erase(iterator) = 0;
63 virtual void erase(iterator start, iterator stop)
66 start = erase(start); //Implemented in derived class.
69 virtual void remove(const_reference) = 0;
71 size_type size() const
73 return g_list_length(glist());
76 inline size_type max_size() { return size_type(-1); }
77 inline bool empty() { return glist() == 0; }
79 inline iterator begin()
84 inline const_iterator begin() const
85 { return const_iterator(begin_()); }
86 inline const_iterator end() const
87 { return const_iterator(end_()); }
89 inline reverse_iterator rbegin()
90 { return reverse_iterator(end_()); }
91 inline reverse_iterator rend()
92 { return reverse_iterator(begin_()); }
94 inline const_reverse_iterator rbegin() const
95 { return const_reverse_iterator(reverse_iterator(end_())); }
96 inline const_reverse_iterator rend() const
97 { return const_reverse_iterator(reverse_iterator(begin_())); }
99 reference front() const
104 reference back() const
109 reference operator[](size_type l) const
113 for(i = begin(), j = 0; i != end(), j < l; ++i, ++j);
117 // iterator find(const_reference w)
119 // iterator i = begin();
120 // for(i = begin(); i != end() && (*i != w); i++);
124 // iterator find(Widget& w)
127 // for (i = begin(); i != end() && ((*i)->$1() != &w); i++);
131 //Derived classes might choose to reimplement these as public:
132 inline void pop_front()
134 inline void pop_back()
138 { erase(begin(), end()); }
141 { return gparent_; };
142 const GObject* gparent() const
143 { return gparent_; };
146 virtual GList*& glist() const = 0; // front of list
148 iterator begin_() const
150 return iterator(glist(), glist());
153 iterator end_() const
155 return iterator(glist(), (GList*)0);
162 } /* namespace Glib */
164 #endif /* _GLIBMM_HELPERLIST_H */