diff options
| author | Krzysztof Kosi??ski <tweenk.pl@gmail.com> | 2009-02-21 02:38:12 +0000 |
|---|---|---|
| committer | tweenk <tweenk@users.sourceforge.net> | 2009-02-21 02:38:12 +0000 |
| commit | 122af757912e1a809bb00c4006f7746f269bf5a9 (patch) | |
| tree | 86b0dcf33fcac42a788b63407e6b126689407f35 /src | |
| parent | Move files from the src/dialogs/ directory to the places where they (diff) | |
| download | inkscape-122af757912e1a809bb00c4006f7746f269bf5a9.tar.gz inkscape-122af757912e1a809bb00c4006f7746f269bf5a9.zip | |
Fix aliasing rules violation in glib-list-iterators.h
(bzr r7338)
Diffstat (limited to 'src')
| -rw-r--r-- | src/util/glib-list-iterators.h | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/src/util/glib-list-iterators.h b/src/util/glib-list-iterators.h index 586bc314a..3779cad1e 100644 --- a/src/util/glib-list-iterators.h +++ b/src/util/glib-list-iterators.h @@ -1,11 +1,14 @@ -/* - * 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 * @@ -21,7 +24,6 @@ #include "glib/glist.h" namespace Inkscape { - namespace Util { template <typename T> class GSListConstIterator; @@ -44,7 +46,9 @@ public: 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) { @@ -65,6 +69,7 @@ public: } private: + union _ref_union {gpointer _gp; pointer _p;}; GSList const *_list; }; @@ -86,10 +91,12 @@ public: 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) { @@ -110,6 +117,7 @@ public: } private: + union _ref_union {gpointer _gp; pointer _p;}; GSList *_list; }; @@ -128,7 +136,9 @@ public: 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) { @@ -159,6 +169,7 @@ public: } private: + union _ref_union {gpointer _gp; pointer _p;}; GList const *_list; }; @@ -186,9 +197,13 @@ public: 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; @@ -218,12 +233,12 @@ public: } private: + union _ref_union {gpointer _gp; pointer _p;}; GList *_list; }; -} - -} +} // namespace Util +} // Namespace Inkscape #endif /* |
