diff options
author | Frank Schoenheit [fs] <frank.schoenheit@oracle.com> | 2011-01-31 13:14:07 +0100 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@oracle.com> | 2011-01-31 13:14:07 +0100 |
commit | 158ec11b26c4180a56fba9f6b2ab26b2b6d60846 (patch) | |
tree | 75d5b6e52eafc4f22b27fca76986d440f92a9871 /comphelper/source | |
parent | b699625287f8fe517bfd018fd6a7edeacdb9c270 (diff) | |
parent | 0dde49b239427444192fc3accf2200f175842bba (diff) |
Automated merge with ssh://hg@hg.services.openoffice.org/cws/dba34b
Diffstat (limited to 'comphelper/source')
-rw-r--r-- | comphelper/source/container/enumerablemap.cxx | 205 | ||||
-rwxr-xr-x | comphelper/source/misc/anycompare.cxx | 131 | ||||
-rw-r--r--[-rwxr-xr-x] | comphelper/source/misc/makefile.mk | 1 |
3 files changed, 138 insertions, 199 deletions
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 +//...................................................................................................................... diff --git a/comphelper/source/misc/makefile.mk b/comphelper/source/misc/makefile.mk index 0bb4defb4165..2f421bdde70d 100755..100644 --- a/comphelper/source/misc/makefile.mk +++ b/comphelper/source/misc/makefile.mk @@ -93,6 +93,7 @@ SLOFILES= \ $(SLO)$/comphelper_services.obj \ $(SLO)$/componentbase.obj \ $(SLO)$/stillreadwriteinteraction.obj \ + $(SLO)$/anycompare.obj \ # --- Targets ---------------------------------- |