You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by hd...@apache.org on 2013/05/08 19:16:49 UTC

svn commit: r1480359 - in /openoffice/branches/rejuvenate01/main/stlport/systemstl: functional hash_map hash_set numeric slist vector

Author: hdu
Date: Wed May  8 17:16:49 2013
New Revision: 1480359

URL: http://svn.apache.org/r1480359
Log:
#i122208# #i121585# update STL wrappers to boost/tr1 or libc++

Modified wrappers around the STL to emulate stlport4 and to let the compiler
find compatibility issues. This approach also allows to keep the diffs minimal
for now which makes reviewing easier. Once we decide that we can drop these
wrappers then the replacement of all stlport4 includes by their TR1 counterparts
(such as boost/tr1 or the powerful libc++ library) will be mechanical and
aided by compiler diagnostics.

Modified:
    openoffice/branches/rejuvenate01/main/stlport/systemstl/functional
    openoffice/branches/rejuvenate01/main/stlport/systemstl/hash_map
    openoffice/branches/rejuvenate01/main/stlport/systemstl/hash_set
    openoffice/branches/rejuvenate01/main/stlport/systemstl/numeric
    openoffice/branches/rejuvenate01/main/stlport/systemstl/slist
    openoffice/branches/rejuvenate01/main/stlport/systemstl/vector

Modified: openoffice/branches/rejuvenate01/main/stlport/systemstl/functional
URL: http://svn.apache.org/viewvc/openoffice/branches/rejuvenate01/main/stlport/systemstl/functional?rev=1480359&r1=1480358&r2=1480359&view=diff
==============================================================================
--- openoffice/branches/rejuvenate01/main/stlport/systemstl/functional (original)
+++ openoffice/branches/rejuvenate01/main/stlport/systemstl/functional Wed May  8 17:16:49 2013
@@ -22,35 +22,68 @@
 #ifndef SYSTEM_STL_FUNCTIONAL
 #define SYSTEM_STL_FUNCTIONAL
 
-#ifdef GCC
-# ifdef __MINGW32__
-#  define _SYSTEM_STL_MAKE_HEADER(path,header) <path/header>
-#  include _SYSTEM_STL_MAKE_HEADER(GXX_INCLUDE_PATH,functional)
-# else
-#  include <ext/../functional>
-# endif
-#  include <ext/functional>
+#ifdef HAVE_STL_INCLUDE_PATH
+	// TODO: use computed include file name
+	#include_next <functional>
+#else // fall back to boost/tr1
+	#include <boost/tr1/functional.hpp>
+	#undef TR1_NS
+	#define TR1_NS std::tr1
+	#define TR1_INNER_NS tr1
+#endif
+
+
+#ifndef NO_STLPORT4_EMULATION
 
 namespace std
 {
-	using __gnu_cxx::project1st;
-	using __gnu_cxx::project2nd;
-	using __gnu_cxx::select1st;
-	using __gnu_cxx::select2nd;
-	using __gnu_cxx::compose1;
-	using __gnu_cxx::compose2;
-	using __gnu_cxx::unary_compose;
-	using __gnu_cxx::binary_compose;
-# ifndef __GXX_EXPERIMENTAL_CXX0X__
-	using __gnu_cxx::identity;
-	using __gnu_cxx::mem_fun1;
-	using __gnu_cxx::mem_fun1_ref;
-# endif
-}
+// emulate SGI extensions to the STL using http://www.sgi.com/tech/stl/stl_function.h as reference
+template< typename T> struct identity : unary_function<T,T> { T operator()(const T& t) const { return t;} };
+template< typename T, typename U> struct project2nd : public binary_function<T,U,U> { U operator()(const T&, const U& u) const { return u;}};
+template<typename P> struct select1st : public unary_function<P, typename P::first_type> { const typename P::first_type& operator()(const P& p) const { return p.first; }};
+template<typename P> struct select2nd : public unary_function<P, typename P::second_type> { const typename P::second_type& operator()(const P& p) const { return p.second; }};
+
+//template<typename I, typename V> inline void iota( I first, I last, V value) { while(first!=last) *(first++) = value++; }
+
+#if (defined(_MSC_VER) && (_MSC_VER >= 1600)) || defined(__GXX_EXPERIMENTAL_CXX0X__)
+template<typename T> inline T&& forward( typename identity<T>::type&& t) { return t; }
+#endif // C++11 move semantics
+
+template<typename Op1, typename Op2> class unary_compose : public unary_function<typename Op2::argument_type, typename Op1::result_type> 
+{
+protected:
+  Op1 aOp1;
+  Op2 aOp2;
+public:
+  unary_compose( const Op1& rOp1, const Op2& rOp2) : aOp1(rOp1), aOp2(rOp2) {}
+  typename Op1::result_type operator()( const typename Op2::argument_type& x) const { return aOp1(aOp2(x)); }
+};
 
-#else
-# error UNSUPPORTED COMPILER
+template<typename Op1, typename Op2> inline unary_compose<Op1,Op2> compose1( const Op1& rOp1, const Op2& rOp2) { return unary_compose<Op1,Op2>(rOp1, rOp2); }
+
+// empty equal_to specializations to detect invocations
+// that are dangerous because their semantic might
+// differ significantly from the stlport<=4 semantic
+template<> struct equal_to<const signed char*> {void operator()(void){}};
+template<> struct equal_to<const unsigned char*> {void operator()(void){}};
+
+#if defined(TR1_INNER_NS)
+namespace TR1_INNER_NS {
+#endif
+    // empty hash specializations to detect invocations
+    // that are dangerous because their semantic might
+    // differ significantly from the stlport<=4 semantic
+    template<> struct hash<char*> {void operator()(void){}};
+    template<> struct hash<const unsigned char*> {void operator()(){}};
+    template<> struct hash<const signed char*> {void operator()(){}};
+#if defined(TR1_INNER_NS)
+}
+using TR1_NS::hash;
 #endif
 
+} // namespace std
+
+#endif // NO_STLPORT4_EMULATION
+
 #endif
-/* vi:set tabstop=4 shiftwidth=4 expandtab: */
+

Modified: openoffice/branches/rejuvenate01/main/stlport/systemstl/hash_map
URL: http://svn.apache.org/viewvc/openoffice/branches/rejuvenate01/main/stlport/systemstl/hash_map?rev=1480359&r1=1480358&r2=1480359&view=diff
==============================================================================
--- openoffice/branches/rejuvenate01/main/stlport/systemstl/hash_map (original)
+++ openoffice/branches/rejuvenate01/main/stlport/systemstl/hash_map Wed May  8 17:16:49 2013
@@ -22,54 +22,75 @@
 #ifndef SYSTEM_STL_HASHMAP
 #define SYSTEM_STL_HASHMAP
 
-#ifdef GCC
+#ifdef HAVE_STL_INCLUDE_PATH
+	// TODO: use computed include file name
+	#include_next <unordered_map>
+#else // fall back to boost/tr1
+	#include <boost/tr1/unordered_map.hpp>
+	#undef TR1_NS
+	#define TR1_NS std::tr1
+#endif
 
-# include <functional>
 
-# define _BACKWARD_BACKWARD_WARNING_H 1
-# include <ext/hash_map>
-# undef _BACKWARD_BACKWARD_WARNING_H
+#ifndef NO_STLPORT4_EMULATION
 
-namespace __gnu_cxx
+namespace std
 {
-    template<> struct hash < std::string >
-    {
-        size_t operator()(const std::string & x) const
-        {
-            return hash< const char* >()(x.c_str());
-        }
-    };
-
-    template<> struct hash< long long int >
-    { 
-        size_t operator()(long long int __x) const 
-        { 
-            return __x; 
-        } 
-    };
-
-    template<> struct hash< unsigned long long int >
-    { 
-        size_t operator()(unsigned long long int __x) const 
-        { 
-            return __x; 
-        } 
-    };
-}
+#ifdef TR1_NS
+using TR1_NS::hash;
+using TR1_NS::unordered_map;
+using TR1_NS::unordered_multimap;
+#endif
 
-namespace std
+template<
+	typename K,
+	typename T,
+	typename H = hash<K>,
+	typename E = equal_to<K>,
+	typename A = allocator<pair<K,T> > >
+class hash_map
+:	public unordered_map<K,T,H,E,A>
 {
-# ifndef __GXX_EXPERIMENTAL_CXX0X__
-	using __gnu_cxx::hash;
-# endif
-	using __gnu_cxx::hash_map;
-	using __gnu_cxx::hash_multimap;
-}
+public:
+	typedef unordered_map<K,T,H,E,A> _super;
+	typedef typename _super::mapped_type data_type;
+
+	hash_map( void) {}
+	hash_map( size_t n) : _super( n) {}
+	hash_map& operator=( const hash_map& r) { hash_map t(r); _super::swap(t); return *this;} //####################
+
+	void resize( size_t n) { _super::rehash(n); }
+private:
+	// setting the hasher dynamically is not supported in the emulation!
+	hash_map( size_t, const H&, const E& rE=E(), const A& rA=A()); // not implemented
+};
+
+template<
+	typename K,
+	typename T,
+	typename H = hash<K>,
+	typename E = equal_to<K>,
+	typename A = allocator<pair<K,T> > >
+class hash_multimap
+:	public unordered_multimap<K,T,H,E,A>
+{
+public:
+	typedef unordered_multimap<K,T,H,E,A> _super;
+	typedef typename _super::mapped_type data_type;
+
+	hash_multimap( void) {}
+	hash_multimap( size_t n) : _super( n) {}
+	hash_multimap& operator=( const hash_multimap& r) { hash_multimap t(r); _super::swap(t); return *this;}//####################
+
+	void resize( size_t n) { _super::rehash(n); }
+private:
+	// setting the hasher dynamically is not supported in the emulation!
+	hash_multimap( size_t, const H&, const E& rE=E(), const A& rA=A()); // not implemented
+};
 
-#else
-# error UNSUPPORTED COMPILER
-#endif
+} // namespace std
 
+#endif // NO_STLPORT4_EMULATION
 
 #endif
-/* vi:set tabstop=4 shiftwidth=4 expandtab: */
+

Modified: openoffice/branches/rejuvenate01/main/stlport/systemstl/hash_set
URL: http://svn.apache.org/viewvc/openoffice/branches/rejuvenate01/main/stlport/systemstl/hash_set?rev=1480359&r1=1480358&r2=1480359&view=diff
==============================================================================
--- openoffice/branches/rejuvenate01/main/stlport/systemstl/hash_set (original)
+++ openoffice/branches/rejuvenate01/main/stlport/systemstl/hash_set Wed May  8 17:16:49 2013
@@ -22,25 +22,67 @@
 #ifndef SYSTEM_STL_HASHSET
 #define SYSTEM_STL_HASHSET
 
-#ifdef GCC
+#ifdef HAVE_STL_INCLUDE_PATH
+	// TODO: use computed include file name
+	#include_next <unordered_set>
+#else // fall back to boost/tr1
+	#include <boost/tr1/unordered_set.hpp>
+	#undef TR1_NS
+	#define TR1_NS std::tr1
+#endif
 
-# include <functional>
 
-# define _BACKWARD_BACKWARD_WARNING_H 1
-# include <ext/hash_set>
-# undef _BACKWARD_BACKWARD_WARNING_H 
+#ifndef NO_STLPORT4_EMULATION
 
 namespace std
 {
-# ifndef __GXX_EXPERIMENTAL_CXX0X__
-	using __gnu_cxx::hash;
-# endif
-	using __gnu_cxx::hash_set;
-	using __gnu_cxx::hash_multiset;
-}
-#else
-# error UNSUPPORTED COMPILER
-#endif
+#ifdef TR1_NS
+using TR1_NS::hash;
+using TR1_NS::unordered_set;
+using TR1_NS::unordered_multiset;
+#endif // TR1_NS
+
+template<
+	typename K,
+	typename H = hash<K>,
+	typename E = equal_to<K>,
+	typename A = allocator<K> >
+class hash_set
+:	public unordered_set<K,H,E,A>
+{
+	typedef unordered_set<K,H,E,A> _super;
+public:
+	hash_set( void) {}
+	hash_set( size_t n) : _super(n) {}
+	hash_set& operator=(const hash_set& r) { hash_set t(r); _super::swap(t); return *this;};//#################
+	void resize( size_t n) { _super::rehash( n); }
+private:
+	// setting the hasher dynamically is not supported in the emulation!
+	hash_set( size_t, const H&, const E& rE=E(), const A& rA=A()); // not implemented
+};
+
+template<
+	typename K,
+	typename H = hash<K>,
+	typename E = equal_to<K>,
+	typename A = allocator<K> >
+class hash_multiset
+:	public unordered_multiset<K,H,E,A>
+{
+	typedef unordered_multiset<K,H,E,A> _super;
+public:
+	hash_multiset( void) {}
+	hash_multiset( size_t n) : _super( n) {}
+	hash_multiset& operator=(const hash_multiset& r) { hash_multiset t(r); _super::swap(t); return *this;}//#################
+	void resize( size_t n) { _super::rehash( n); }
+private:
+	// setting the hasher dynamically is not supported in the emulation!
+	hash_multiset( size_t, const H&, const E& rE=E(), const A& rA=A()); // not implemented
+};
+
+} // namespace std
+
+#endif // NO_STLPORT4_EMULATION
 
 #endif
-/* vi:set tabstop=4 shiftwidth=4 expandtab: */
+

Modified: openoffice/branches/rejuvenate01/main/stlport/systemstl/numeric
URL: http://svn.apache.org/viewvc/openoffice/branches/rejuvenate01/main/stlport/systemstl/numeric?rev=1480359&r1=1480358&r2=1480359&view=diff
==============================================================================
--- openoffice/branches/rejuvenate01/main/stlport/systemstl/numeric (original)
+++ openoffice/branches/rejuvenate01/main/stlport/systemstl/numeric Wed May  8 17:16:49 2013
@@ -22,26 +22,12 @@
 #ifndef SYSTEM_STL_NUMERIC
 #define SYSTEM_STL_NUMERIC
 
-#ifdef GCC
-# include <functional>
-# ifdef __MINGW32__
-#  define _SYSTEM_STL_MAKE_HEADER(path,header) <path/header>
-#  include _SYSTEM_STL_MAKE_HEADER(GXX_INCLUDE_PATH,numeric)
-# else
-#  include <ext/../numeric>
-# endif
-# include <ext/numeric>
-
-# ifndef __GXX_EXPERIMENTAL_CXX0X__
-namespace std
-{
-	using __gnu_cxx::iota;
-}
-# endif
-
-#else
-# error UNSUPPORTED COMPILER
+#ifdef HAVE_STL_INCLUDE_PATH
+	// TODO: use computed include file name
+	#include_next <numeric>
+#else // fall back to boost/tr1
+	#include <boost/tr1/tr1/numeric.hpp>
 #endif
 
 #endif
-/* vi:set tabstop=4 shiftwidth=4 expandtab: */
+

Modified: openoffice/branches/rejuvenate01/main/stlport/systemstl/slist
URL: http://svn.apache.org/viewvc/openoffice/branches/rejuvenate01/main/stlport/systemstl/slist?rev=1480359&r1=1480358&r2=1480359&view=diff
==============================================================================
--- openoffice/branches/rejuvenate01/main/stlport/systemstl/slist (original)
+++ openoffice/branches/rejuvenate01/main/stlport/systemstl/slist Wed May  8 17:16:49 2013
@@ -22,18 +22,48 @@
 #ifndef SYSTEM_STL_SLIST
 #define SYSTEM_STL_SLIST
 
-#ifdef GCC
+#ifdef HAVE_STL_INCLUDE_PATH
+	// TODO: use computed include file name
+	#include_next <forward_list>
+#else // fall back to boost/tr1 (forward_list or plain list)
+	#include <boost/config.hpp>
+	#ifndef BOOST_NO_0X_HDR_FORWARD_LIST
+		#include <boost/tr1/tr1/forward_list.hpp>
+	#else // fall back to the classic list
+		#include <boost/tr1/tr1/list.hpp>
+		#define STLP4_SLIST_WITH_LIST
+	#endif
+#endif
+
+
+#ifndef NO_STLPORT4_EMULATION
 
-#include <ext/slist>
+#ifndef STLP4_SLIST_WITH_LIST
+    #define STLP4_SLIST_EMUBASE std::forward_list
+#else
+    #define STLP4_SLIST_EMUBASE std::list
+#endif
 
 namespace std
 {
-	using __gnu_cxx::slist;
-}
-#else
-#error UNSUPPORTED COMPILER
+using STLP4_SLIST_EMUBASE;
+
+// lame emulation of the pre-C++11 slist using the std::forward_list (or std::list)
+template< typename T, class A=allocator<T> >
+class slist : public STLP4_SLIST_EMUBASE<T,A>
+{
+public:
+	typedef typename STLP4_SLIST_EMUBASE<T,A> _super;
+	typedef typename _super::iterator slist_mit;
+	typedef typename _super::const_iterator slist_cit;
+#ifndef STLP4_SLIST_WITH_LIST
+	slist_mit insert( slist_cit aI, const T& rT) { return _super::insert_after( aI, rT); }
 #endif
+};
 
+}
+
+#endif // NO_STLPORT4_EMULATION
 
 #endif
-/* vi:set tabstop=4 shiftwidth=4 expandtab: */
+

Modified: openoffice/branches/rejuvenate01/main/stlport/systemstl/vector
URL: http://svn.apache.org/viewvc/openoffice/branches/rejuvenate01/main/stlport/systemstl/vector?rev=1480359&r1=1480358&r2=1480359&view=diff
==============================================================================
--- openoffice/branches/rejuvenate01/main/stlport/systemstl/vector (original)
+++ openoffice/branches/rejuvenate01/main/stlport/systemstl/vector Wed May  8 17:16:49 2013
@@ -22,22 +22,35 @@
 #ifndef SYSTEM_STL_VECTOR
 #define SYSTEM_STL_VECTOR
 
-#ifdef GCC
-
-#ifdef __MINGW32__
-#  define _SYSTEM_STL_MAKE_HEADER(path,header) <path/header>
-#  include _SYSTEM_STL_MAKE_HEADER(GXX_INCLUDE_PATH,vector)
-#else
-#  include <ext/../vector>
+#ifdef HAVE_STL_INCLUDE_PATH
+	// TODO: use computed include file name
+	#include_next <vector>
+#else // fall back to boost/tr1
+	#include <boost/tr1/tr1/vector.hpp>
 #endif
 
+
+#ifndef NO_STLPORT4_EMULATION
+
 namespace std
 {
-    typedef vector<bool, std::allocator<bool> > bit_vector;
+    typedef vector<bool> bit_vector;
 }
 
+inline int std_bitset_count( std::bit_vector::const_iterator it, std::bit_vector::const_iterator itEnd, bool bValue)
+{
+#if false && defined(_LIBCPP___BIT_REFERENCE) // TODO: reenable for libc++ >= r156543/r156546/etc.
+	int nCount = std::count( it, itEnd, bValue);
 #else
-#error UNSUPPORTED COMPILER
+	int nCount = 0;
+	for(; it != itEnd; ++it)
+		if( *it == bValue)
+			++nCount;
 #endif
+	return nCount;
+}
+
+#endif // NO_STLPORT4_EMULATION
+
 #endif
-/* vi:set tabstop=4 shiftwidth=4 expandtab: */
+