/usr/include/glibmm-2.4/glibmm/containers.h is in libglibmm-2.4-dev 2.56.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | #ifndef _GLIBMM_CONTAINERS_H
#define _GLIBMM_CONTAINERS_H
/* containers.h
*
* Copyright (C) 1998-2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <glibmmconfig.h>
#include <glibmm/sarray.h> /* for backward compatibility */
#include <glibmm/wrap.h>
#include <glib.h>
#include <iterator>
#include <cstddef>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
namespace Glib
{
template <class T>
class List_Iterator;
template <class T>
class List_ConstIterator;
template <class T>
class List_ReverseIterator;
// Most of these methods in the non-template classes needs to be moved
// to implementation.
// Daniel Elstner has ideas about generating these per-widget with m4. murrayc.
extern GLIBMM_API gpointer glibmm_null_pointer;
template <class T>
class List_Iterator_Base
{
public:
using value_type = T;
using pointer = T*;
using reference = T&;
};
/// For instance, List_Iterator< Gtk::Widget >
template <class T>
class List_Iterator : public List_Iterator_Base<T>
{
public:
using iterator_category = std::bidirectional_iterator_tag;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;
using pointer = typename List_Iterator_Base<T>::pointer;
using reference = typename List_Iterator_Base<T>::reference;
GList* const* head_;
GList* node_;
using Self = List_Iterator<T>;
List_Iterator(GList* const& head, GList* node) : head_(&head), node_(node) {}
List_Iterator() : head_(nullptr), node_(nullptr) {}
List_Iterator(const Self& src) : head_(src.head_), node_(src.node_) {}
bool operator==(const Self& src) const { return node_ == src.node_; }
bool operator!=(const Self& src) const { return node_ != src.node_; }
Self& operator++()
{
if (!node_)
node_ = g_list_first(*head_);
else
node_ = (GList*)g_list_next(node_);
return *this;
}
Self operator++(int)
{
Self tmp = *this;
++*this;
return tmp;
}
Self& operator--()
{
if (!node_)
node_ = g_list_last(*head_);
else
node_ = (GList*)g_list_previous(node_);
return *this;
}
Self operator--(int)
{
Self tmp = *this;
--*this;
return tmp;
}
reference operator*() const { return *(pointer)(node_ ? node_->data : glibmm_null_pointer); }
pointer operator->() const { return &**this; }
};
/// For instance, SList_Iterator< Gtk::Widget >
template <class T>
class SList_Iterator : public List_Iterator_Base<T>
{
public:
using iterator_category = std::forward_iterator_tag;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;
using pointer = typename List_Iterator_Base<T>::pointer;
using reference = typename List_Iterator_Base<T>::reference;
GSList* node_;
using Self = SList_Iterator<T>;
SList_Iterator(GSList* node) : node_(node) {}
SList_Iterator() : node_(nullptr) {}
SList_Iterator(const Self& src) : node_(src.node_) {}
bool operator==(const Self& src) const { return node_ == src.node_; }
bool operator!=(const Self& src) const { return node_ != src.node_; }
Self& operator++()
{
node_ = g_slist_next(node_);
return *this;
}
Self operator++(int)
{
Self tmp = *this;
++*this;
return tmp;
}
reference operator*() const
{
return reinterpret_cast<T&>(node_ ? node_->data : glibmm_null_pointer);
}
pointer operator->() const { return &**this; }
};
// This iterator variation returns T_IFace (wrapped from T_Impl)
// For instance, List_Cpp_Iterator<GtkWidget, Gtk::Widget> is
// a little like std::list<Gtk::Widget>::iterator
template <class T_Impl, class T_IFace>
class List_Cpp_Iterator : public List_Iterator_Base<T_IFace>
{
public:
using iterator_category = std::bidirectional_iterator_tag;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;
using pointer = typename List_Iterator_Base<T_IFace>::pointer;
using reference = typename List_Iterator_Base<T_IFace>::reference;
using Self = List_Cpp_Iterator<T_Impl, T_IFace>;
GList** head_;
GList* node_;
bool operator==(const Self& src) const { return node_ == src.node_; }
bool operator!=(const Self& src) const { return node_ != src.node_; }
List_Cpp_Iterator(GList*& head, GList* node) : head_(&head), node_(node) {}
List_Cpp_Iterator() : head_(nullptr), node_(nullptr) {}
List_Cpp_Iterator(const Self& src) : head_(src.head_), node_(src.node_) {}
reference operator*() const
{
if (node_ && node_->data)
{
// We copy/paste the widget wrap() implementation here,
// because we can not use a specific Glib::wrap(T_Impl) overload here,
// because that would be "dependent", and g++ 3.4 does not allow that.
// The specific Glib::wrap() overloads don't do anything special anyway.
GObject* cobj = static_cast<GObject*>(node_->data);
#ifdef GLIBMM_CAN_USE_DYNAMIC_CAST_IN_UNUSED_TEMPLATE_WITHOUT_DEFINITION
return *dynamic_cast<pointer>(Glib::wrap_auto(cobj, false));
#else
// We really do need to use dynamic_cast<>, so I expect problems if this code is used.
// murrayc.
return *static_cast<pointer>(Glib::wrap_auto(cobj, false));
#endif
}
return *static_cast<pointer>(nullptr); // boom!
}
pointer operator->() const { return &**this; }
Self& operator++()
{
if (!node_)
node_ = g_list_first(*head_);
else
node_ = (GList*)g_list_next(node_);
return *this;
}
Self operator++(int)
{
Self tmp = *this;
++*this;
return tmp;
}
Self& operator--()
{
if (!node_)
node_ = g_list_last(*head_);
else
node_ = (GList*)g_list_previous(node_);
return *this;
}
Self operator--(int)
{
Self tmp = *this;
--*this;
return tmp;
}
};
template <class T_Base>
class List_ReverseIterator : private T_Base
{
public:
using iterator_category = typename T_Base::iterator_category;
using size_type = typename T_Base::size_type;
using difference_type = typename T_Base::difference_type;
using value_type = typename T_Base::value_type;
using pointer = typename T_Base::pointer;
using reference = typename T_Base::reference;
using Self = List_ReverseIterator<T_Base>;
bool operator==(const Self& src) const { return T_Base::operator==(src); }
bool operator!=(const Self& src) const { return T_Base::operator!=(src); }
List_ReverseIterator(GList* const& head, GList* node) : T_Base(head, node) {}
List_ReverseIterator() : T_Base() {}
List_ReverseIterator(const Self& src) : T_Base(src) {}
List_ReverseIterator(const T_Base& src) : T_Base(src) { ++(*this); }
Self& operator++()
{
T_Base::operator--();
return *this;
}
Self& operator--()
{
T_Base::operator++();
return *this;
}
Self operator++(int)
{
Self src = *this;
T_Base::operator--();
return src;
}
Self operator--(int)
{
Self src = *this;
T_Base::operator++();
return src;
}
reference operator*() const { return T_Base::operator*(); }
pointer operator->() const { return T_Base::operator->(); }
};
template <class T_Base>
class List_ConstIterator : public T_Base
{
public:
using iterator_category = typename T_Base::iterator_category;
using size_type = typename T_Base::size_type;
using difference_type = typename T_Base::difference_type;
using value_type = const typename T_Base::value_type;
using pointer = const typename T_Base::pointer;
using reference = const typename T_Base::reference;
using Self = List_ConstIterator<T_Base>;
bool operator==(const Self& src) const { return T_Base::operator==(src); }
bool operator!=(const Self& src) const { return T_Base::operator!=(src); }
List_ConstIterator(GList* const& head, GList* node) : T_Base(head, node) {}
List_ConstIterator() : T_Base() {}
List_ConstIterator(const Self& src) : T_Base(src) {}
List_ConstIterator(const T_Base& src) : T_Base(src) {}
Self& operator++()
{
T_Base::operator++();
return *this;
}
Self& operator--()
{
T_Base::operator--();
return *this;
}
Self operator++(int)
{
Self src = *this;
T_Base::operator++();
return src;
}
Self operator--(int)
{
Self src = *this;
T_Base::operator--();
return src;
}
reference operator*() const { return T_Base::operator*(); }
pointer operator->() const { return T_Base::operator->(); }
};
} // namespace Glib
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
#endif /* _GLIBMM_CONTAINERS_H */
|