summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a73e5f9)
raw | patch | inline | side by side (parent: a73e5f9)
author | tweenk <tweenk@users.sourceforge.net> | |
Sat, 21 Feb 2009 02:38:12 +0000 (02:38 +0000) | ||
committer | tweenk <tweenk@users.sourceforge.net> | |
Sat, 21 Feb 2009 02:38:12 +0000 (02:38 +0000) |
src/util/glib-list-iterators.h | patch | blob | history |
index 586bc314a9321db3db3de3fc2a5e86a605e3a770..3779cad1e4c46a819459b0fe5b53f3a365b34dc6 100644 (file)
-/*
- * Inkscape::Util::GSListIterator - STL iterator for GSList
+/** @file
+ * @brief STL iterators for Glib list types
+ */
+/* Inkscape::Util::GSListIterator - STL iterator for GSList
* Inkscape::Util::GSListConstIterator - STL iterator for GSList
* Inkscape::Util::GListIterator - STL iterator for GList
* Inkscape::Util::GListConstIterator - STL iterator for GList
*
* Authors:
* MenTaLguY <mental@rydia.net>
+ * Krzysztof KosiĆski <tweenk.pl@gmail.com>
*
* Copyright (C) 2005 MenTaLguY
*
#include "glib/glist.h"
namespace Inkscape {
-
namespace Util {
template <typename T> class GSListConstIterator;
GSList const *list() const { return _list; }
reference operator*() const {
- return *reinterpret_cast<pointer>(&_list->data);
+ _ref_union u;
+ u._gp = _list->data;
+ return *u._p;
}
bool operator==(GSListConstIterator const &other) {
}
private:
+ union _ref_union {gpointer _gp; pointer _p;};
GSList const *_list;
};
GSList *list() { return _list; }
const_reference operator*() const {
- return *reinterpret_cast<pointer>(&_list->data);
+ return const_cast<GSListIterator<T *> *>(this)->operator*();
}
reference operator*() {
- return *reinterpret_cast<pointer>(&_list->data);
+ _ref_union u;
+ u._gp = _list->data;
+ return *u._p;
}
bool operator==(GSListIterator const &other) {
}
private:
+ union _ref_union {gpointer _gp; pointer _p;};
GSList *_list;
};
GList const *list() const { return _list; }
reference operator*() const {
- return *reinterpret_cast<pointer>(&_list->data);
+ _ref_union u;
+ u._gp = _list->data;
+ return *u._p;
}
bool operator==(GListConstIterator const &other) {
}
private:
+ union _ref_union {gpointer _gp; pointer _p;};
GList const *_list;
};
GList *list() { return _list; }
const_reference operator*() const {
- return *reinterpret_cast<pointer>(&_list->data);
+ return const_cast<GListIterator<T *> *>(this)->operator*();
+ }
+ reference operator*() {
+ _ref_union u;
+ u._gp = _list->data;
+ return *u._p;
}
- reference operator*() { return *reinterpret_cast<pointer>(&_list->data); }
bool operator==(GListIterator const &other) {
return other._list == _list;
}
private:
+ union _ref_union {gpointer _gp; pointer _p;};
GList *_list;
};
-}
-
-}
+} // namespace Util
+} // Namespace Inkscape
#endif
/*