summaryrefslogtreecommitdiff
path: root/comphelper/source/container/enumerablemap.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'comphelper/source/container/enumerablemap.cxx')
-rw-r--r--comphelper/source/container/enumerablemap.cxx58
1 files changed, 28 insertions, 30 deletions
diff --git a/comphelper/source/container/enumerablemap.cxx b/comphelper/source/container/enumerablemap.cxx
index 55c2b9e28077..3fda3d5f67ff 100644
--- a/comphelper/source/container/enumerablemap.cxx
+++ b/comphelper/source/container/enumerablemap.cxx
@@ -18,7 +18,6 @@
*/
-#include <comphelper_module.hxx>
#include <comphelper/anytostring.hxx>
#include <comphelper/anycompare.hxx>
#include <comphelper/componentbase.hxx>
@@ -30,15 +29,17 @@
#include <com/sun/star/beans/IllegalTypeException.hpp>
#include <com/sun/star/beans/Pair.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
-#include <cppuhelper/compbase3.hxx>
+#include <cppuhelper/compbase.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/supportsservice.hxx>
-#include <rtl/math.hxx>
#include <typelib/typedescription.hxx>
+#include <cmath>
#include <map>
#include <memory>
+#include <optional>
#include <utility>
namespace comphelper
@@ -89,7 +90,7 @@ namespace comphelper
{
Type m_aKeyType;
Type m_aValueType;
- std::unique_ptr< KeyedValues > m_pValues;
+ std::optional< KeyedValues > m_pValues;
std::shared_ptr< IKeyPredicateLess > m_pKeyCompare;
bool m_bMutable;
std::vector< MapEnumerator* > m_aModListeners;
@@ -102,11 +103,10 @@ namespace comphelper
MapData( const MapData& _source )
:m_aKeyType( _source.m_aKeyType )
,m_aValueType( _source.m_aValueType )
- ,m_pValues( new KeyedValues( *_source.m_pValues ) )
,m_pKeyCompare( _source.m_pKeyCompare )
,m_bMutable( false )
- ,m_aModListeners()
{
+ m_pValues.emplace( *_source.m_pValues );
}
private:
MapData& operator=( const MapData& _source ) = delete;
@@ -143,7 +143,7 @@ namespace comphelper
// EnumerableMap
- typedef ::cppu::WeakAggComponentImplHelper3 < XInitialization
+ typedef ::cppu::WeakComponentImplHelper < XInitialization
, XEnumerableMap
, XServiceInfo
> Map_IFace;
@@ -326,37 +326,37 @@ namespace comphelper
sal_Int32 nArgumentCount = _arguments.getLength();
if ( ( nArgumentCount != 2 ) && ( nArgumentCount != 3 ) )
- throw IllegalArgumentException();
+ throw IllegalArgumentException(u"wrong number of args"_ustr, static_cast<cppu::OWeakObject*>(this), 1);
Type aKeyType, aValueType;
if ( !( _arguments[0] >>= aKeyType ) )
- throw IllegalArgumentException("com.sun.star.uno.Type expected.", *this, 1 );
+ throw IllegalArgumentException(u"com.sun.star.uno.Type expected."_ustr, *this, 1 );
if ( !( _arguments[1] >>= aValueType ) )
- throw IllegalArgumentException("com.sun.star.uno.Type expected.", *this, 2 );
+ throw IllegalArgumentException(u"com.sun.star.uno.Type expected."_ustr, *this, 2 );
Sequence< Pair< Any, Any > > aInitialValues;
bool bMutable = true;
if ( nArgumentCount == 3 )
{
if ( !( _arguments[2] >>= aInitialValues ) )
- throw IllegalArgumentException("[]com.sun.star.beans.Pair<any,any> expected.", *this, 2 );
+ throw IllegalArgumentException(u"[]com.sun.star.beans.Pair<any,any> expected."_ustr, *this, 2 );
bMutable = false;
}
// for the value, anything is allowed, except VOID
if ( ( aValueType.getTypeClass() == TypeClass_VOID ) || ( aValueType.getTypeClass() == TypeClass_UNKNOWN ) )
- throw IllegalTypeException("Unsupported value type.", *this );
+ throw IllegalTypeException(u"Unsupported value type."_ustr, *this );
// create the comparator for the KeyType, and throw if the type is not supported
std::unique_ptr< IKeyPredicateLess > pComparator( getStandardLessPredicate( aKeyType, nullptr ) );
if (!pComparator)
- throw IllegalTypeException("Unsupported key type.", *this );
+ throw IllegalTypeException(u"Unsupported key type."_ustr, *this );
// init members
- m_aData.m_aKeyType = aKeyType;
- m_aData.m_aValueType = aValueType;
+ m_aData.m_aKeyType = std::move(aKeyType);
+ m_aData.m_aValueType = std::move(aValueType);
m_aData.m_pKeyCompare = std::move(pComparator);
- m_aData.m_pValues.reset( new KeyedValues( *m_aData.m_pKeyCompare ) );
+ m_aData.m_pValues.emplace( *m_aData.m_pKeyCompare );
m_aData.m_bMutable = bMutable;
if ( aInitialValues.hasElements() )
@@ -369,15 +369,13 @@ namespace comphelper
void EnumerableMap::impl_initValues_throw( const Sequence< Pair< Any, Any > >& _initialValues )
{
OSL_PRECOND( m_aData.m_pValues && m_aData.m_pValues->empty(), "EnumerableMap::impl_initValues_throw: illegal call!" );
- if (!m_aData.m_pValues || !m_aData.m_pValues->empty())
- throw RuntimeException();
-
- const Pair< Any, Any >* mapping = _initialValues.getConstArray();
- const Pair< Any, Any >* mappingEnd = mapping + _initialValues.getLength();
- for ( ; mapping != mappingEnd; ++mapping )
+ if (!m_aData.m_pValues || !m_aData.m_pValues->empty()){
+ throw RuntimeException("EnumerableMap m_aData container is invalid or not empty.", *this);
+ }
+ for (auto& mapping : _initialValues)
{
- impl_checkValue_throw( mapping->Second );
- (*m_aData.m_pValues)[ mapping->First ] = mapping->Second;
+ impl_checkValue_throw(mapping.Second);
+ (*m_aData.m_pValues)[mapping.First] = mapping.Second;
}
}
@@ -467,7 +465,7 @@ namespace comphelper
if ( _keyOrValue >>= nValue )
if ( std::isnan( nValue ) )
throw IllegalArgumentException(
- "NaN (not-a-number) not supported by this implementation.",
+ u"NaN (not-a-number) not supported by this implementation."_ustr,
*const_cast< EnumerableMap* >( this ), 0 );
// (note that the case of _key not containing a float/double value is handled in the
// respective IKeyPredicateLess implementation, so there's no need to handle this here.)
@@ -479,7 +477,7 @@ namespace comphelper
{
if ( !_key.hasValue() )
throw IllegalArgumentException(
- "NULL keys not supported by this implementation.",
+ u"NULL keys not supported by this implementation."_ustr,
*const_cast< EnumerableMap* >( this ), 0 );
impl_checkNaN_throw( _key, m_aData.m_aKeyType );
@@ -490,7 +488,7 @@ namespace comphelper
{
if ( !m_aData.m_bMutable )
throw NoSupportException(
- "The map is immutable.",
+ u"The map is immutable."_ustr,
*const_cast< EnumerableMap* >( this ) );
}
@@ -639,7 +637,7 @@ namespace comphelper
OUString SAL_CALL EnumerableMap::getImplementationName( )
{
- return "org.openoffice.comp.comphelper.EnumerableMap";
+ return u"org.openoffice.comp.comphelper.EnumerableMap"_ustr;
}
sal_Bool SAL_CALL EnumerableMap::supportsService( const OUString& _serviceName )
@@ -650,7 +648,7 @@ namespace comphelper
Sequence< OUString > SAL_CALL EnumerableMap::getSupportedServiceNames( )
{
- return { "com.sun.star.container.EnumerableMap" };
+ return { u"com.sun.star.container.EnumerableMap"_ustr };
}
bool MapEnumerator::hasMoreElements()
@@ -666,7 +664,7 @@ namespace comphelper
if ( m_disposed )
throw DisposedException( OUString(), m_rParent );
if ( m_mapPos == m_rMapData.m_pValues->end() )
- throw NoSuchElementException("No more elements.", m_rParent );
+ throw NoSuchElementException(u"No more elements."_ustr, m_rParent );
Any aNextElement;
switch ( m_eType )