summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorRelease Engineering <releng@openoffice.org>2011-02-18 11:14:19 +0100
committerRelease Engineering <releng@openoffice.org>2011-02-18 11:14:19 +0100
commit10771c040794aec3ce6e18cd0cccadd472dcf747 (patch)
tree6687cc663dd86fce488861004872007ad93a3214 /comphelper
parentce5f1dd187c3a7d8113c7653fa887b98fd50aaf6 (diff)
parentebc04bc9219f8dd341308a430c295c53c4f6813c (diff)
merged DEV300
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/Library_comphelp.mk1
-rw-r--r--comphelper/Package_inc.mk2
-rwxr-xr-xcomphelper/inc/comphelper/anycompare.hxx226
-rwxr-xr-xcomphelper/inc/comphelper/componentguard.hxx70
-rw-r--r--comphelper/source/container/enumerablemap.cxx205
-rwxr-xr-xcomphelper/source/misc/anycompare.cxx131
6 files changed, 436 insertions, 199 deletions
diff --git a/comphelper/Library_comphelp.mk b/comphelper/Library_comphelp.mk
index f077c1db4973..0228d80b2f89 100644
--- a/comphelper/Library_comphelp.mk
+++ b/comphelper/Library_comphelp.mk
@@ -113,6 +113,7 @@ $(eval $(call gb_Library_add_exception_objects,comphelper,\
comphelper/source/misc/serviceinfohelper \
comphelper/source/misc/sharedmutex \
comphelper/source/misc/stillreadwriteinteraction \
+ comphelper/source/misc/anycompare \
comphelper/source/misc/storagehelper \
comphelper/source/misc/string \
comphelper/source/misc/synchronousdispatch \
diff --git a/comphelper/Package_inc.mk b/comphelper/Package_inc.mk
index dcfb4954efb1..5794c56ab74d 100644
--- a/comphelper/Package_inc.mk
+++ b/comphelper/Package_inc.mk
@@ -35,6 +35,7 @@ $(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/basicio.hxx,comp
$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/classids.hxx,comphelper/classids.hxx))
$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/MasterPropertySet.hxx,comphelper/MasterPropertySet.hxx))
$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/stillreadwriteinteraction.hxx,comphelper/stillreadwriteinteraction.hxx))
+$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/anycompare.hxx,comphelper/anycompare.hxx))
$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/propagg.hxx,comphelper/propagg.hxx))
$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/scopeguard.hxx,comphelper/scopeguard.hxx))
$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/asyncnotification.hxx,comphelper/asyncnotification.hxx))
@@ -110,6 +111,7 @@ $(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/numbers.hxx,comp
$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/evtlistenerhlp.hxx,comphelper/evtlistenerhlp.hxx))
$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/optional.hxx,comphelper/optional.hxx))
$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/componentbase.hxx,comphelper/componentbase.hxx))
+$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/componentguard.hxx,comphelper/componentguard.hxx))
$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/InlineContainer.hxx,comphelper/InlineContainer.hxx))
$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/propertybag.hxx,comphelper/propertybag.hxx))
$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/embeddedobjectcontainer.hxx,comphelper/embeddedobjectcontainer.hxx))
diff --git a/comphelper/inc/comphelper/anycompare.hxx b/comphelper/inc/comphelper/anycompare.hxx
new file mode 100755
index 000000000000..03f41e108ba9
--- /dev/null
+++ b/comphelper/inc/comphelper/anycompare.hxx
@@ -0,0 +1,226 @@
+/*************************************************************************
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org 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 version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef COMPHELPER_ANYCOMPARE_HXX
+#define COMPHELPER_ANYCOMPARE_HXX
+
+#include "comphelper/comphelperdllapi.h"
+
+/** === begin UNO includes === **/
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
+#include <com/sun/star/i18n/XCollator.hpp>
+/** === end UNO includes === **/
+
+#include <comphelper/extract.hxx>
+
+#include <functional>
+#include <memory>
+
+//......................................................................................................................
+namespace comphelper
+{
+//......................................................................................................................
+
+ //==================================================================================================================
+ //= IKeyPredicateLess
+ //==================================================================================================================
+ class SAL_NO_VTABLE IKeyPredicateLess
+ {
+ public:
+ virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const = 0;
+ virtual ~IKeyPredicateLess() {}
+ };
+
+ //==================================================================================================================
+ //= LessPredicateAdapter
+ //==================================================================================================================
+ struct LessPredicateAdapter : public ::std::binary_function< ::com::sun::star::uno::Any, ::com::sun::star::uno::Any, bool >
+ {
+ LessPredicateAdapter( const IKeyPredicateLess& _predicate )
+ :m_predicate( _predicate )
+ {
+ }
+
+ bool operator()( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const
+ {
+ return m_predicate.isLess( _lhs, _rhs );
+ }
+
+ private:
+ IKeyPredicateLess const & m_predicate;
+
+ private:
+ LessPredicateAdapter(); // never implemented
+ };
+
+ //==================================================================================================================
+ //= ScalarPredicateLess
+ //==================================================================================================================
+ template< typename SCALAR >
+ class ScalarPredicateLess : public IKeyPredicateLess
+ {
+ public:
+ virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const
+ {
+ SCALAR lhs(0), rhs(0);
+ if ( !( _lhs >>= lhs )
+ || !( _rhs >>= rhs )
+ )
+ throw ::com::sun::star::lang::IllegalArgumentException();
+ return lhs < rhs;
+ }
+ };
+
+ //==================================================================================================================
+ //= StringPredicateLess
+ //==================================================================================================================
+ class StringPredicateLess : public IKeyPredicateLess
+ {
+ public:
+ virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const
+ {
+ ::rtl::OUString lhs, rhs;
+ if ( !( _lhs >>= lhs )
+ || !( _rhs >>= rhs )
+ )
+ throw ::com::sun::star::lang::IllegalArgumentException();
+ return lhs < rhs;
+ }
+ };
+
+ //==================================================================================================================
+ //= StringCollationPredicateLess
+ //==================================================================================================================
+ class StringCollationPredicateLess : public IKeyPredicateLess
+ {
+ public:
+ StringCollationPredicateLess( ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCollator > const & i_collator )
+ :m_collator( i_collator )
+ {
+ }
+
+ virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const
+ {
+ ::rtl::OUString lhs, rhs;
+ if ( !( _lhs >>= lhs )
+ || !( _rhs >>= rhs )
+ )
+ throw ::com::sun::star::lang::IllegalArgumentException();
+ return m_collator->compareString( lhs, rhs ) < 0;
+ }
+
+ private:
+ ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCollator > const m_collator;
+ };
+
+ //==================================================================================================================
+ //= TypePredicateLess
+ //==================================================================================================================
+ class TypePredicateLess : public IKeyPredicateLess
+ {
+ public:
+ virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const
+ {
+ ::com::sun::star::uno::Type lhs, rhs;
+ if ( !( _lhs >>= lhs )
+ || !( _rhs >>= rhs )
+ )
+ throw ::com::sun::star::lang::IllegalArgumentException();
+ return lhs.getTypeName() < rhs.getTypeName();
+ }
+ };
+
+ //==================================================================================================================
+ //= EnumPredicateLess
+ //==================================================================================================================
+ class EnumPredicateLess : public IKeyPredicateLess
+ {
+ public:
+ EnumPredicateLess( ::com::sun::star::uno::Type const & _enumType )
+ :m_enumType( _enumType )
+ {
+ }
+
+ virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const
+ {
+ sal_Int32 lhs(0), rhs(0);
+ if ( !::cppu::enum2int( lhs, _lhs )
+ || !::cppu::enum2int( rhs, _rhs )
+ || !_lhs.getValueType().equals( m_enumType )
+ || !_rhs.getValueType().equals( m_enumType )
+ )
+ throw ::com::sun::star::lang::IllegalArgumentException();
+ return lhs < rhs;
+ }
+
+ private:
+ ::com::sun::star::uno::Type const m_enumType;
+ };
+
+ //==================================================================================================================
+ //= InterfacePredicateLess
+ //==================================================================================================================
+ class InterfacePredicateLess : public IKeyPredicateLess
+ {
+ public:
+ virtual bool isLess( ::com::sun::star::uno::Any const & _lhs, ::com::sun::star::uno::Any const & _rhs ) const
+ {
+ if ( ( _lhs.getValueTypeClass() != ::com::sun::star::uno::TypeClass_INTERFACE )
+ || ( _rhs.getValueTypeClass() != ::com::sun::star::uno::TypeClass_INTERFACE )
+ )
+ throw ::com::sun::star::lang::IllegalArgumentException();
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > lhs( _lhs, ::com::sun::star::uno::UNO_QUERY );
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > rhs( _rhs, ::com::sun::star::uno::UNO_QUERY );
+ return lhs.get() < rhs.get();
+ }
+ };
+
+ //==================================================================================================================
+ //= getStandardLessPredicate
+ //==================================================================================================================
+ /** creates a default IKeyPredicateLess instance for the given UNO type
+ @param i_type
+ the type for which a predicate instance should be created
+ @param i_collator
+ specifies a collator instance to use, or <NULL/>. If <NULL/>, strings will be compared using the <code>&lt</code>
+ operator, otherwise the collator will be used. The parameter is ignored if <arg>i_type</arg> does not specify
+ the string type.
+ @return
+ a default implementation of IKeyPredicateLess, which is able to compare values of the given type. If no
+ such default implementation is known for the given type, then <NULL/> is returned.
+ */
+ ::std::auto_ptr< IKeyPredicateLess > COMPHELPER_DLLPUBLIC
+ getStandardLessPredicate(
+ ::com::sun::star::uno::Type const & i_type,
+ ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCollator > const & i_collator
+ );
+
+//......................................................................................................................
+} // namespace comphelper
+//......................................................................................................................
+
+#endif // COMPHELPER_ANYCOMPARE_HXX
diff --git a/comphelper/inc/comphelper/componentguard.hxx b/comphelper/inc/comphelper/componentguard.hxx
new file mode 100755
index 000000000000..820b901a5c55
--- /dev/null
+++ b/comphelper/inc/comphelper/componentguard.hxx
@@ -0,0 +1,70 @@
+/*************************************************************************
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org 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 version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef COMPHELPER_COMPONENTGUARD_HXX
+#define COMPHELPER_COMPONENTGUARD_HXX
+
+/** === begin UNO includes === **/
+#include <com/sun/star/lang/DisposedException.hpp>
+/** === end UNO includes === **/
+
+#include <cppuhelper/weak.hxx>
+#include <cppuhelper/interfacecontainer.hxx>
+
+//......................................................................................................................
+namespace comphelper
+{
+//......................................................................................................................
+
+ //==================================================================================================================
+ //= ComponentGuard
+ //==================================================================================================================
+ class ComponentGuard
+ {
+ public:
+ ComponentGuard( ::cppu::OWeakObject& i_component, ::cppu::OBroadcastHelper & i_broadcastHelper )
+ :m_aGuard( i_broadcastHelper.rMutex )
+ {
+ if ( i_broadcastHelper.bDisposed )
+ throw ::com::sun::star::lang::DisposedException( ::rtl::OUString(), &i_component );
+ }
+
+ ~ComponentGuard()
+ {
+ }
+
+ void clear() { m_aGuard.clear(); }
+ void reset() { m_aGuard.reset(); }
+
+ private:
+ ::osl::ResettableMutexGuard m_aGuard;
+ };
+
+//......................................................................................................................
+} // namespace comphelper
+//......................................................................................................................
+
+#endif // COMPHELPER_COMPONENTGUARD_HXX
diff --git a/comphelper/source/container/enumerablemap.cxx b/comphelper/source/container/enumerablemap.cxx
index 15241cd72dd6..a73983517751 100644
--- a/comphelper/source/container/enumerablemap.cxx
+++ b/comphelper/source/container/enumerablemap.cxx
@@ -24,11 +24,11 @@
*
************************************************************************/
-// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_comphelper.hxx"
#include "comphelper_module.hxx"
#include "comphelper/anytostring.hxx"
+#include "comphelper/anycompare.hxx"
#include "comphelper/componentbase.hxx"
#include "comphelper/componentcontext.hxx"
#include "comphelper/extract.hxx"
@@ -47,9 +47,7 @@
#include <rtl/ustrbuf.hxx>
#include <typelib/typedescription.hxx>
-#include <functional>
#include <map>
-#include <memory>
#include <boost/shared_ptr.hpp>
//........................................................................
@@ -79,26 +77,14 @@ namespace comphelper
using ::com::sun::star::beans::Pair;
using ::com::sun::star::uno::TypeClass;
using ::com::sun::star::uno::TypeClass_VOID;
- using ::com::sun::star::uno::TypeClass_CHAR;
- using ::com::sun::star::uno::TypeClass_BOOLEAN;
- using ::com::sun::star::uno::TypeClass_BYTE;
- using ::com::sun::star::uno::TypeClass_SHORT;
- using ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT;
- using ::com::sun::star::uno::TypeClass_LONG;
- using ::com::sun::star::uno::TypeClass_UNSIGNED_LONG;
- using ::com::sun::star::uno::TypeClass_HYPER;
- using ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER;
- using ::com::sun::star::uno::TypeClass_FLOAT;
- using ::com::sun::star::uno::TypeClass_DOUBLE;
- using ::com::sun::star::uno::TypeClass_STRING;
- using ::com::sun::star::uno::TypeClass_TYPE;
- using ::com::sun::star::uno::TypeClass_ENUM;
- using ::com::sun::star::uno::TypeClass_INTERFACE;
using ::com::sun::star::uno::TypeClass_UNKNOWN;
using ::com::sun::star::uno::TypeClass_ANY;
using ::com::sun::star::uno::TypeClass_EXCEPTION;
using ::com::sun::star::uno::TypeClass_STRUCT;
using ::com::sun::star::uno::TypeClass_UNION;
+ using ::com::sun::star::uno::TypeClass_FLOAT;
+ using ::com::sun::star::uno::TypeClass_DOUBLE;
+ using ::com::sun::star::uno::TypeClass_INTERFACE;
using ::com::sun::star::lang::XServiceInfo;
using ::com::sun::star::uno::XComponentContext;
using ::com::sun::star::container::XEnumeration;
@@ -108,136 +94,6 @@ namespace comphelper
/** === end UNO using === **/
//====================================================================
- //= IKeyPredicateLess
- //====================================================================
- class SAL_NO_VTABLE IKeyPredicateLess
- {
- public:
- virtual bool isLess( const Any& _lhs, const Any& _rhs ) const = 0;
- virtual ~IKeyPredicateLess() {}
- };
-
- //====================================================================
- //= LessPredicateAdapter
- //====================================================================
- struct LessPredicateAdapter : public ::std::binary_function< Any, Any, bool >
- {
- LessPredicateAdapter( const IKeyPredicateLess& _predicate )
- :m_predicate( _predicate )
- {
- }
-
- bool operator()( const Any& _lhs, const Any& _rhs ) const
- {
- return m_predicate.isLess( _lhs, _rhs );
- }
-
- private:
- const IKeyPredicateLess& m_predicate;
-
- private:
- LessPredicateAdapter(); // never implemented
- };
-
- //====================================================================
- //= ScalarPredicateLess
- //====================================================================
- template< typename SCALAR >
- class ScalarPredicateLess : public IKeyPredicateLess
- {
- public:
- virtual bool isLess( const Any& _lhs, const Any& _rhs ) const
- {
- SCALAR lhs(0), rhs(0);
- if ( !( _lhs >>= lhs )
- || !( _rhs >>= rhs )
- )
- throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unsupported key type." ) ), NULL, 1 );
- return lhs < rhs;
- }
- };
-
- //====================================================================
- //= StringPredicateLess
- //====================================================================
- class StringPredicateLess : public IKeyPredicateLess
- {
- public:
- virtual bool isLess( const Any& _lhs, const Any& _rhs ) const
- {
- ::rtl::OUString lhs, rhs;
- if ( !( _lhs >>= lhs )
- || !( _rhs >>= rhs )
- )
- throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unsupported key type." ) ), NULL, 1 );
- return lhs < rhs;
- }
- };
-
- //====================================================================
- //= TypePredicateLess
- //====================================================================
- class TypePredicateLess : public IKeyPredicateLess
- {
- public:
- virtual bool isLess( const Any& _lhs, const Any& _rhs ) const
- {
- Type lhs, rhs;
- if ( !( _lhs >>= lhs )
- || !( _rhs >>= rhs )
- )
- throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unsupported key type." ) ), NULL, 1 );
- return lhs.getTypeName() < rhs.getTypeName();
- }
- };
-
- //====================================================================
- //= EnumPredicateLess
- //====================================================================
- class EnumPredicateLess : public IKeyPredicateLess
- {
- public:
- EnumPredicateLess( const Type& _enumType )
- :m_enumType( _enumType )
- {
- }
-
- virtual bool isLess( const Any& _lhs, const Any& _rhs ) const
- {
- sal_Int32 lhs(0), rhs(0);
- if ( !::cppu::enum2int( lhs, _lhs )
- || !::cppu::enum2int( rhs, _rhs )
- || !_lhs.getValueType().equals( m_enumType )
- || !_rhs.getValueType().equals( m_enumType )
- )
- throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unsupported key type." ) ), NULL, 1 );
- return lhs < rhs;
- }
-
- private:
- const Type m_enumType;
- };
-
- //====================================================================
- //= InterfacePredicateLess
- //====================================================================
- class InterfacePredicateLess : public IKeyPredicateLess
- {
- public:
- virtual bool isLess( const Any& _lhs, const Any& _rhs ) const
- {
- if ( ( _lhs.getValueTypeClass() != TypeClass_INTERFACE )
- || ( _rhs.getValueTypeClass() != TypeClass_INTERFACE )
- )
- throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unsupported key type." ) ), NULL, 1 );
-
- Reference< XInterface > lhs( _lhs, UNO_QUERY );
- Reference< XInterface > rhs( _rhs, UNO_QUERY );
- return lhs.get() < rhs.get();
- }
- };
-
- //====================================================================
//= MapData
//====================================================================
class IMapModificationListener;
@@ -549,58 +405,9 @@ namespace comphelper
throw IllegalTypeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unsupported value type." ) ), *this );
// create the comparator for the KeyType, and throw if the type is not supported
- TypeClass eKeyTypeClass = aKeyType.getTypeClass();
- ::std::auto_ptr< IKeyPredicateLess > pComparator;
- switch ( eKeyTypeClass )
- {
- case TypeClass_CHAR:
- pComparator.reset( new ScalarPredicateLess< sal_Unicode >() );
- break;
- case TypeClass_BOOLEAN:
- pComparator.reset( new ScalarPredicateLess< sal_Bool >() );
- break;
- case TypeClass_BYTE:
- pComparator.reset( new ScalarPredicateLess< sal_Int8 >() );
- break;
- case TypeClass_SHORT:
- pComparator.reset( new ScalarPredicateLess< sal_Int16 >() );
- break;
- case TypeClass_UNSIGNED_SHORT:
- pComparator.reset( new ScalarPredicateLess< sal_uInt16 >() );
- break;
- case TypeClass_LONG:
- pComparator.reset( new ScalarPredicateLess< sal_Int32 >() );
- break;
- case TypeClass_UNSIGNED_LONG:
- pComparator.reset( new ScalarPredicateLess< sal_uInt32 >() );
- break;
- case TypeClass_HYPER:
- pComparator.reset( new ScalarPredicateLess< sal_Int64 >() );
- break;
- case TypeClass_UNSIGNED_HYPER:
- pComparator.reset( new ScalarPredicateLess< sal_uInt64 >() );
- break;
- case TypeClass_FLOAT:
- pComparator.reset( new ScalarPredicateLess< float >() );
- break;
- case TypeClass_DOUBLE:
- pComparator.reset( new ScalarPredicateLess< double >() );
- break;
- case TypeClass_STRING:
- pComparator.reset( new StringPredicateLess() );
- break;
- case TypeClass_TYPE:
- pComparator.reset( new TypePredicateLess() );
- break;
- case TypeClass_ENUM:
- pComparator.reset( new EnumPredicateLess( aKeyType ) );
- break;
- case TypeClass_INTERFACE:
- pComparator.reset( new InterfacePredicateLess() );
- break;
- default:
+ ::std::auto_ptr< IKeyPredicateLess > pComparator( getStandardLessPredicate( aKeyType, NULL ) );
+ if ( !pComparator.get() )
throw IllegalTypeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unsupported key type." ) ), *this );
- }
// init members
m_aData.m_aKeyType = aKeyType;
diff --git a/comphelper/source/misc/anycompare.cxx b/comphelper/source/misc/anycompare.cxx
new file mode 100755
index 000000000000..a86174daf08e
--- /dev/null
+++ b/comphelper/source/misc/anycompare.cxx
@@ -0,0 +1,131 @@
+/*************************************************************************
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org 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 version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "precompiled_comphelper.hxx"
+
+#include "comphelper/anycompare.hxx"
+
+/** === begin UNO includes === **/
+/** === end UNO includes === **/
+
+//......................................................................................................................
+namespace comphelper
+{
+//......................................................................................................................
+
+ /** === begin UNO using === **/
+ using ::com::sun::star::uno::Reference;
+ using ::com::sun::star::uno::XInterface;
+ using ::com::sun::star::uno::UNO_QUERY;
+ using ::com::sun::star::uno::UNO_QUERY_THROW;
+ using ::com::sun::star::uno::UNO_SET_THROW;
+ using ::com::sun::star::uno::Exception;
+ using ::com::sun::star::uno::RuntimeException;
+ using ::com::sun::star::uno::Any;
+ using ::com::sun::star::uno::makeAny;
+ using ::com::sun::star::uno::Sequence;
+ using ::com::sun::star::uno::Type;
+ using ::com::sun::star::uno::TypeClass_CHAR;
+ using ::com::sun::star::uno::TypeClass_BOOLEAN;
+ using ::com::sun::star::uno::TypeClass_BYTE;
+ using ::com::sun::star::uno::TypeClass_SHORT;
+ using ::com::sun::star::uno::TypeClass_UNSIGNED_SHORT;
+ using ::com::sun::star::uno::TypeClass_LONG;
+ using ::com::sun::star::uno::TypeClass_UNSIGNED_LONG;
+ using ::com::sun::star::uno::TypeClass_HYPER;
+ using ::com::sun::star::uno::TypeClass_UNSIGNED_HYPER;
+ using ::com::sun::star::uno::TypeClass_FLOAT;
+ using ::com::sun::star::uno::TypeClass_DOUBLE;
+ using ::com::sun::star::uno::TypeClass_STRING;
+ using ::com::sun::star::uno::TypeClass_TYPE;
+ using ::com::sun::star::uno::TypeClass_ENUM;
+ using ::com::sun::star::uno::TypeClass_INTERFACE;
+ using ::com::sun::star::i18n::XCollator;
+ /** === end UNO using === **/
+
+ //------------------------------------------------------------------------------------------------------------------
+ ::std::auto_ptr< IKeyPredicateLess > getStandardLessPredicate( Type const & i_type, Reference< XCollator > const & i_collator )
+ {
+ ::std::auto_ptr< IKeyPredicateLess > pComparator;
+ switch ( i_type.getTypeClass() )
+ {
+ case TypeClass_CHAR:
+ pComparator.reset( new ScalarPredicateLess< sal_Unicode >() );
+ break;
+ case TypeClass_BOOLEAN:
+ pComparator.reset( new ScalarPredicateLess< sal_Bool >() );
+ break;
+ case TypeClass_BYTE:
+ pComparator.reset( new ScalarPredicateLess< sal_Int8 >() );
+ break;
+ case TypeClass_SHORT:
+ pComparator.reset( new ScalarPredicateLess< sal_Int16 >() );
+ break;
+ case TypeClass_UNSIGNED_SHORT:
+ pComparator.reset( new ScalarPredicateLess< sal_uInt16 >() );
+ break;
+ case TypeClass_LONG:
+ pComparator.reset( new ScalarPredicateLess< sal_Int32 >() );
+ break;
+ case TypeClass_UNSIGNED_LONG:
+ pComparator.reset( new ScalarPredicateLess< sal_uInt32 >() );
+ break;
+ case TypeClass_HYPER:
+ pComparator.reset( new ScalarPredicateLess< sal_Int64 >() );
+ break;
+ case TypeClass_UNSIGNED_HYPER:
+ pComparator.reset( new ScalarPredicateLess< sal_uInt64 >() );
+ break;
+ case TypeClass_FLOAT:
+ pComparator.reset( new ScalarPredicateLess< float >() );
+ break;
+ case TypeClass_DOUBLE:
+ pComparator.reset( new ScalarPredicateLess< double >() );
+ break;
+ case TypeClass_STRING:
+ if ( i_collator.is() )
+ pComparator.reset( new StringCollationPredicateLess( i_collator ) );
+ else
+ pComparator.reset( new StringPredicateLess() );
+ break;
+ case TypeClass_TYPE:
+ pComparator.reset( new TypePredicateLess() );
+ break;
+ case TypeClass_ENUM:
+ pComparator.reset( new EnumPredicateLess( i_type ) );
+ break;
+ case TypeClass_INTERFACE:
+ pComparator.reset( new InterfacePredicateLess() );
+ break;
+ default:
+ break;
+ }
+ return pComparator;
+ }
+
+//......................................................................................................................
+} // namespace comphelper
+//......................................................................................................................