From cc1ed7fbce20f90650f96acc2846b6f232c8ab0f Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 27 Sep 2017 09:11:35 +0200 Subject: loplugin:flatten in various Change-Id: I42dca691ffadbddad38a7e8f978b1da9d5d9a7b0 Reviewed-on: https://gerrit.libreoffice.org/42842 Tested-by: Jenkins Reviewed-by: Noel Grandin --- framework/source/fwi/uielement/itemcontainer.cxx | 56 ++++++++++------------ .../source/fwi/uielement/rootitemcontainer.cxx | 54 ++++++++++----------- 2 files changed, 49 insertions(+), 61 deletions(-) (limited to 'framework/source/fwi') diff --git a/framework/source/fwi/uielement/itemcontainer.cxx b/framework/source/fwi/uielement/itemcontainer.cxx index fd9149376162..ec57f33b07a4 100644 --- a/framework/source/fwi/uielement/itemcontainer.cxx +++ b/framework/source/fwi/uielement/itemcontainer.cxx @@ -166,60 +166,54 @@ sal_Int32 SAL_CALL ItemContainer::getCount() Any SAL_CALL ItemContainer::getByIndex( sal_Int32 Index ) { ShareGuard aLock( m_aShareMutex ); - if ( sal_Int32( m_aItemVector.size()) > Index ) - return makeAny( m_aItemVector[Index] ); - else + if ( sal_Int32( m_aItemVector.size()) <= Index ) throw IndexOutOfBoundsException( OUString(), static_cast(this) ); + + return makeAny( m_aItemVector[Index] ); } // XIndexContainer void SAL_CALL ItemContainer::insertByIndex( sal_Int32 Index, const Any& aItem ) { Sequence< PropertyValue > aSeq; - if ( aItem >>= aSeq ) + if ( !(aItem >>= aSeq) ) + throw IllegalArgumentException( WRONG_TYPE_EXCEPTION, + static_cast(this), 2 ); + + ShareGuard aLock( m_aShareMutex ); + if ( sal_Int32( m_aItemVector.size()) == Index ) + m_aItemVector.push_back( aSeq ); + else if ( sal_Int32( m_aItemVector.size()) >Index ) { - ShareGuard aLock( m_aShareMutex ); - if ( sal_Int32( m_aItemVector.size()) == Index ) - m_aItemVector.push_back( aSeq ); - else if ( sal_Int32( m_aItemVector.size()) >Index ) - { - std::vector< Sequence< PropertyValue > >::iterator aIter = m_aItemVector.begin(); - aIter += Index; - m_aItemVector.insert( aIter, aSeq ); - } - else - throw IndexOutOfBoundsException( OUString(), static_cast(this) ); + std::vector< Sequence< PropertyValue > >::iterator aIter = m_aItemVector.begin(); + aIter += Index; + m_aItemVector.insert( aIter, aSeq ); } else - throw IllegalArgumentException( WRONG_TYPE_EXCEPTION, - static_cast(this), 2 ); + throw IndexOutOfBoundsException( OUString(), static_cast(this) ); } void SAL_CALL ItemContainer::removeByIndex( sal_Int32 nIndex ) { ShareGuard aLock( m_aShareMutex ); - if ( (sal_Int32)m_aItemVector.size() > nIndex ) - { - m_aItemVector.erase(m_aItemVector.begin() + nIndex); - } - else + if ( (sal_Int32)m_aItemVector.size() <= nIndex ) throw IndexOutOfBoundsException( OUString(), static_cast(this) ); + + m_aItemVector.erase(m_aItemVector.begin() + nIndex); } void SAL_CALL ItemContainer::replaceByIndex( sal_Int32 Index, const Any& aItem ) { Sequence< PropertyValue > aSeq; - if ( aItem >>= aSeq ) - { - ShareGuard aLock( m_aShareMutex ); - if ( sal_Int32( m_aItemVector.size()) > Index ) - m_aItemVector[Index] = aSeq; - else - throw IndexOutOfBoundsException( OUString(), static_cast(this) ); - } - else + if ( !(aItem >>= aSeq) ) throw IllegalArgumentException( WRONG_TYPE_EXCEPTION, static_cast(this), 2 ); + + ShareGuard aLock( m_aShareMutex ); + if ( !(sal_Int32( m_aItemVector.size()) > Index) ) + throw IndexOutOfBoundsException( OUString(), static_cast(this) ); + + m_aItemVector[Index] = aSeq; } } // namespace framework diff --git a/framework/source/fwi/uielement/rootitemcontainer.cxx b/framework/source/fwi/uielement/rootitemcontainer.cxx index 5b065a835f3c..72f41e761a1e 100644 --- a/framework/source/fwi/uielement/rootitemcontainer.cxx +++ b/framework/source/fwi/uielement/rootitemcontainer.cxx @@ -182,58 +182,52 @@ sal_Int32 SAL_CALL RootItemContainer::getCount() Any SAL_CALL RootItemContainer::getByIndex( sal_Int32 Index ) { ShareGuard aLock( m_aShareMutex ); - if ( sal_Int32( m_aItemVector.size()) > Index ) - return makeAny( m_aItemVector[Index] ); - else + if ( sal_Int32( m_aItemVector.size()) <= Index ) throw IndexOutOfBoundsException( OUString(), static_cast(this) ); + + return makeAny( m_aItemVector[Index] ); } // XIndexContainer void SAL_CALL RootItemContainer::insertByIndex( sal_Int32 Index, const Any& aItem ) { Sequence< PropertyValue > aSeq; - if ( aItem >>= aSeq ) + if ( !(aItem >>= aSeq) ) + throw IllegalArgumentException( WRONG_TYPE_EXCEPTION, static_cast(this), 2 ); + + ShareGuard aLock( m_aShareMutex ); + if ( sal_Int32( m_aItemVector.size()) == Index ) + m_aItemVector.push_back( aSeq ); + else if ( sal_Int32( m_aItemVector.size()) >Index ) { - ShareGuard aLock( m_aShareMutex ); - if ( sal_Int32( m_aItemVector.size()) == Index ) - m_aItemVector.push_back( aSeq ); - else if ( sal_Int32( m_aItemVector.size()) >Index ) - { - std::vector< Sequence< PropertyValue > >::iterator aIter = m_aItemVector.begin(); - aIter += Index; - m_aItemVector.insert( aIter, aSeq ); - } - else - throw IndexOutOfBoundsException( OUString(), static_cast(this) ); + std::vector< Sequence< PropertyValue > >::iterator aIter = m_aItemVector.begin(); + aIter += Index; + m_aItemVector.insert( aIter, aSeq ); } else - throw IllegalArgumentException( WRONG_TYPE_EXCEPTION, static_cast(this), 2 ); + throw IndexOutOfBoundsException( OUString(), static_cast(this) ); } void SAL_CALL RootItemContainer::removeByIndex( sal_Int32 nIndex ) { ShareGuard aLock( m_aShareMutex ); - if ( (sal_Int32)m_aItemVector.size() > nIndex ) - { - m_aItemVector.erase(m_aItemVector.begin() + nIndex); - } - else + if ( (sal_Int32)m_aItemVector.size() <= nIndex ) throw IndexOutOfBoundsException( OUString(), static_cast(this) ); + + m_aItemVector.erase(m_aItemVector.begin() + nIndex); } void SAL_CALL RootItemContainer::replaceByIndex( sal_Int32 Index, const Any& aItem ) { Sequence< PropertyValue > aSeq; - if ( aItem >>= aSeq ) - { - ShareGuard aLock( m_aShareMutex ); - if ( sal_Int32( m_aItemVector.size()) > Index ) - m_aItemVector[Index] = aSeq; - else - throw IndexOutOfBoundsException( OUString(), static_cast(this) ); - } - else + if ( !(aItem >>= aSeq) ) throw IllegalArgumentException( WRONG_TYPE_EXCEPTION, static_cast(this), 2 ); + + ShareGuard aLock( m_aShareMutex ); + if ( !(sal_Int32( m_aItemVector.size()) > Index) ) + throw IndexOutOfBoundsException( OUString(), static_cast(this) ); + + m_aItemVector[Index] = aSeq; } Reference< XInterface > SAL_CALL RootItemContainer::createInstanceWithContext( const Reference< XComponentContext >& ) -- cgit