From: Krzysztof Kosiński Date: Thu, 4 Mar 2010 21:54:38 +0000 (+0100) Subject: Clean up the unordered containers fix. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=afa4f5baaf7ffebeb9e731423b95800f60e942c7;p=inkscape.git Clean up the unordered containers fix. --- diff --git a/configure.ac b/configure.ac index 8a8a5a702..00b0e91cb 100644 --- a/configure.ac +++ b/configure.ac @@ -125,29 +125,24 @@ if test "x$GXX" = "xyes"; then fi fi -# Test for various hash_set/unordered_set issues: -# This is a system header so we check it as soon as possible -AC_CHECK_HEADER(tr1/unordered_set, - AC_MSG_CHECKING([TR1 unordered_set usability]) - AC_COMPILE_IFELSE([ +# Detect a working version of unordered containers. +AC_MSG_CHECKING([TR1 unordered_set usability]) +AC_COMPILE_IFELSE([ #include int main() { std::tr1::unordered_set i, j; i = j; return 0; } -], [unordered_set_broken=no], [unordered_set_broken=yet]) -if test "x$unordered_set_broken" = "xyes"; then - AC_MSG_RESULT([broken]) -else +], [unordered_set_works=yes], [unordered_set_works=no]) +if test "x$unordered_set_works" = "xyes"; then AC_MSG_RESULT([ok]) - AC_DEFINE(HAVE_TR1_UNORDERED_SET, 1, [Has the standard TR1 unordered_set]) + AC_DEFINE(HAVE_TR1_UNORDERED_SET, 1, [Has working standard TR1 unordered_set]) +else + AC_MSG_RESULT([not working]) fi -, []) - -AC_CHECK_HEADER(ext/hash_set, AC_DEFINE(HAVE_EXT_HASH_SET, 1, [Legacy ext/hash_set]), []) -AC_CHECK_HEADER(unordered_set, AC_DEFINE(HAVE_UNORDERED_SET, 1, [Legacy unordered_set]), []) - +AC_CHECK_HEADER([boost/unordered_set.hpp], [AC_DEFINE(HAVE_BOOST_UNORDERED_SET, 1, [Boost unordered_set (Boost >= 1.36)])], []) +AC_CHECK_HEADER([ext/hash_set], [AC_DEFINE(HAVE_EXT_HASH_SET, 1, [Legacy GNU ext/hash_set])], []) # Test whether GCC emits a spurious warning when using boost::optional # If yes, turn off strict aliasing warnings to reduce noise diff --git a/src/libnrtype/FontFactory.cpp b/src/libnrtype/FontFactory.cpp index 8ab2ee696..06fb93f2d 100644 --- a/src/libnrtype/FontFactory.cpp +++ b/src/libnrtype/FontFactory.cpp @@ -10,25 +10,19 @@ #define PANGO_ENABLE_ENGINE -#include "FontFactory.h" -#include - -#include - - #ifdef HAVE_CONFIG_H # include "config.h" #endif +#include #include #include // _() +#include +#include "libnrtype/FontFactory.h" +#include "libnrtype/font-instance.h" +#include "util/unordered-containers.h" -/* Freetype2 */ -# include - -#include "util/set-types.h" - -typedef optim_map FaceMapType; +typedef INK_UNORDERED_MAP FaceMapType; // need to avoid using the size field size_t font_descr_hash::operator()( PangoFontDescription *const &x) const { diff --git a/src/libnrtype/FontInstance.cpp b/src/libnrtype/FontInstance.cpp index 61cd28190..be5eb86c8 100644 --- a/src/libnrtype/FontInstance.cpp +++ b/src/libnrtype/FontInstance.cpp @@ -11,25 +11,22 @@ #define PANGO_ENABLE_ENGINE #ifdef HAVE_CONFIG_H -# include +# include "config.h" #endif -#include -#include -#include -#include <2geom/pathvector.h> -#include - -#include "RasterFont.h" -/* Freetype 2 */ -# include -# include FT_OUTLINE_H -# include FT_BBOX_H -# include FT_TRUETYPE_TAGS_H -# include FT_TRUETYPE_TABLES_H -# include - -#include "util/set-types.h" +#include +#include FT_OUTLINE_H +#include FT_BBOX_H +#include FT_TRUETYPE_TAGS_H +#include FT_TRUETYPE_TABLES_H +#include +#include <2geom/pathvector.h> +#include "libnr/nr-rect.h" +#include "libnrtype/font-glyph.h" +#include "libnrtype/font-instance.h" +#include "libnrtype/RasterFont.h" +#include "livarot/Path.h" +#include "util/unordered-containers.h" struct font_style_hash : public std::unary_function { @@ -40,7 +37,7 @@ struct font_style_equal : public std::binary_function StyleMap; +typedef INK_UNORDERED_MAP StyleMap; diff --git a/src/ui/tool/control-point-selection.h b/src/ui/tool/control-point-selection.h index 6efb63b67..514ecb2e3 100644 --- a/src/ui/tool/control-point-selection.h +++ b/src/ui/tool/control-point-selection.h @@ -14,13 +14,13 @@ #include #include -#include "util/set-types.h" #include #include <2geom/forward.h> #include <2geom/point.h> #include <2geom/rect.h> #include "display/display-forward.h" #include "util/accumulators.h" +#include "util/unordered-containers.h" #include "ui/tool/commit-events.h" #include "ui/tool/manipulator.h" @@ -33,17 +33,6 @@ class SelectableControlPoint; } } -#ifdef USE_GNU_HASHES -namespace __gnu_cxx { -template<> -struct hash { - size_t operator()(Inkscape::UI::SelectableControlPoint *p) const { - return reinterpret_cast(p); - } -}; -} // namespace __gnu_cxx -#endif // USE_GNU_HASHES - namespace Inkscape { namespace UI { @@ -51,7 +40,7 @@ class ControlPointSelection : public Manipulator, public sigc::trackable { public: ControlPointSelection(SPDesktop *d, SPCanvasGroup *th_group); ~ControlPointSelection(); - typedef optim_set< SelectableControlPoint * > set_type; + typedef INK_UNORDERED_SET set_type; typedef set_type Set; // convenience alias typedef set_type::iterator iterator; @@ -142,7 +131,7 @@ private: set_type _points; set_type _all_points; - optim_map _original_positions; + INK_UNORDERED_MAP _original_positions; boost::optional _rot_radius; boost::optional _mouseover_rot_radius; Geom::OptRect _bounds; diff --git a/src/ui/tool/multi-path-manipulator.cpp b/src/ui/tool/multi-path-manipulator.cpp index d86a7e9e0..b79a29437 100644 --- a/src/ui/tool/multi-path-manipulator.cpp +++ b/src/ui/tool/multi-path-manipulator.cpp @@ -8,7 +8,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "util/set-types.h" #include #include #include @@ -24,6 +23,7 @@ #include "ui/tool/node.h" #include "ui/tool/multi-path-manipulator.h" #include "ui/tool/path-manipulator.h" +#include "util/unordered-containers.h" #ifdef USE_GNU_HASHES namespace __gnu_cxx { @@ -40,9 +40,18 @@ namespace Inkscape { namespace UI { namespace { + +struct hash_nodelist_iterator + : public std::unary_function +{ + std::size_t operator()(NodeList::iterator i) const { + return INK_HASH()(&*i); + } +}; + typedef std::pair IterPair; typedef std::vector IterPairList; -typedef optim_set IterSet; +typedef INK_UNORDERED_SET IterSet; typedef std::multimap DistanceMap; typedef std::pair DistanceMapItem; diff --git a/src/util/Makefile_insert b/src/util/Makefile_insert index 3d3c88940..1908aea19 100644 --- a/src/util/Makefile_insert +++ b/src/util/Makefile_insert @@ -16,12 +16,12 @@ ink_common_sources += \ util/map-list.h \ util/mathfns.h \ util/reverse-list.h \ - util/set-types.h \ util/share.h \ util/share.cpp \ util/tuple.h \ util/units.cpp \ - util/units.h + util/units.h \ + util/unordered-containers.h # ###################### # ### CxxTest stuff #### diff --git a/src/util/set-types.h b/src/util/set-types.h deleted file mode 100644 index f6752fb64..000000000 --- a/src/util/set-types.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef SEEN_SET_TYPES_H -#define SEEN_SET_TYPES_H - - -/** @file - * Simple wrapper to disambiguate hash/unordered lists & sets. - */ -/* Authors: - * Jon A. Cruz - * - * Copyright (C) 2010 Authors - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#if defined(HAVE_TR1_UNORDERED_SET) - -# include -# include -# define optim_set std::tr1::unordered_set -# define optim_map std::tr1::unordered_map - -// TODO test on platform with this detected: -//#elif defined(HAVE_UNORDERED_SET) -// -//# include -//# include -//#define optim_set std::unordered_set -//#define optim_map std::unordered_map - -#elif defined(HAVE_EXT_HASH_SET) - -# include -# include -# define optim_set __gnu_cxx::hash_set -# define optim_map __gnu_cxx::hash_map -# define USE_GNU_HASHES 1 - -#endif - - -#endif // SEEN_SET_TYPES_H -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/util/unordered-containers.h b/src/util/unordered-containers.h new file mode 100644 index 000000000..aaf771959 --- /dev/null +++ b/src/util/unordered-containers.h @@ -0,0 +1,78 @@ +/** @file + * @brief Compatibility wrapper for unordered containers. + */ +/* Authors: + * Jon A. Cruz + * Krzysztof Kosiński + * + * Copyright (C) 2010 Authors + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef SEEN_INK_UTIL_UNORDERED_CONTAINERS_H +#define SEEN_INK_UTIL_UNORDERED_CONTAINERS_H + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +#if defined(HAVE_TR1_UNORDERED_SET) + +# include +# include +# define INK_UNORDERED_SET std::tr1::unordered_set +# define INK_UNORDERED_MAP std::tr1::unordered_map +# define INK_HASH std::tr1::hash + +#elif defined(HAVE_BOOST_UNORDERED_SET) +# include +# include +# define INK_UNORDERED_SET boost::unordered_set +# define INK_UNORDERED_MAP boost::unordered_map +# define INK_HASH boost::hash + +#elif defined(HAVE_EXT_HASH_SET) + +# include +# include +# include +# define INK_UNORDERED_SET __gnu_cxx::hash_set +# define INK_UNORDERED_MAP __gnu_cxx::hash_map +# define INK_HASH __gnu_cxx::hash + +namespace __gnu_cxx { +// hash function for pointers +// TR1 and Boost have this defined by default, __gnu_cxx doesn't +template +struct hash : public std::unary_function { + std::size_t operator()(T *p) const { + // Taken from Boost + std::size_t x = static_cast(reinterpret_cast(p)); + return x + (x >> 3); + } +}; +} // namespace __gnu_cxx +#endif + +#else +/// Name (with namespace) of the unordered set template. +#define INK_UNORDERED_SET +/// Name (with namespace) of the unordered map template. +#define INK_UNORDERED_MAP +/// Name (with namespace) of the hash template. +#define INK_HASH + +#endif + +#endif // SEEN_SET_TYPES_H +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :