From 9411511e647f0847506bd1143a19f33af79d376f Mon Sep 17 00:00:00 2001 From: Arnaud Versini Date: Sun, 25 Oct 2020 16:39:38 +0100 Subject: [PATCH] UNOTOOLS : simplify AccessibleRelationHelper by removing useless impl pattern Change-Id: I6cb14c5c973067c0ea1c64eab40e38b8b548174f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104776 Tested-by: Jenkins Reviewed-by: Noel Grandin --- .../unotools/accessiblerelationsethelper.hxx | 6 +- .../accessiblerelationsethelper.cxx | 122 +++++------------- 2 files changed, 35 insertions(+), 93 deletions(-) diff --git a/include/unotools/accessiblerelationsethelper.hxx b/include/unotools/accessiblerelationsethelper.hxx index 6417401796d5..b4edb6b95159 100644 --- a/include/unotools/accessiblerelationsethelper.hxx +++ b/include/unotools/accessiblerelationsethelper.hxx @@ -25,9 +25,7 @@ #include #include #include -#include - -class AccessibleRelationSetHelperImpl; +#include //= XAccessibleRelationSet helper classes @@ -123,7 +121,7 @@ private: /// Mutex guarding this object. ::osl::Mutex maMutex; /// The implementation of this helper interface. - std::unique_ptr mpHelperImpl; + std::vector maRelations; }; } diff --git a/unotools/source/accessibility/accessiblerelationsethelper.cxx b/unotools/source/accessibility/accessiblerelationsethelper.cxx index 8f70623435dc..02b3ad572e34 100644 --- a/unotools/source/accessibility/accessiblerelationsethelper.cxx +++ b/unotools/source/accessibility/accessiblerelationsethelper.cxx @@ -22,108 +22,34 @@ #include #include #include -#include #include using namespace ::utl; using namespace ::com::sun::star; using namespace ::com::sun::star::accessibility; -class AccessibleRelationSetHelperImpl +namespace { -public: - AccessibleRelationSetHelperImpl(); - AccessibleRelationSetHelperImpl(const AccessibleRelationSetHelperImpl& rImpl); - - /// @throws uno::RuntimeException - sal_Int32 getRelationCount() const; - /// @throws lang::IndexOutOfBoundsException - /// @throws uno::RuntimeException - AccessibleRelation const & getRelation( sal_Int32 nIndex ) const; - /// @throws uno::RuntimeException - bool containsRelation( sal_Int16 aRelationType ) const; - /// @throws uno::RuntimeException - AccessibleRelation getRelationByType( sal_Int16 aRelationType ) const; - /// @throws uno::RuntimeException - void AddRelation(const AccessibleRelation& rRelation); - -private: - std::vector maRelations; -}; - -AccessibleRelationSetHelperImpl::AccessibleRelationSetHelperImpl() -{ -} - -AccessibleRelationSetHelperImpl::AccessibleRelationSetHelperImpl(const AccessibleRelationSetHelperImpl& rImpl) - : maRelations(rImpl.maRelations) -{ -} - -sal_Int32 AccessibleRelationSetHelperImpl::getRelationCount() const -{ - return maRelations.size(); -} - -AccessibleRelation const & AccessibleRelationSetHelperImpl::getRelation( sal_Int32 nIndex ) const -{ - if ((nIndex < 0) || (o3tl::make_unsigned(nIndex) >= maRelations.size())) - throw lang::IndexOutOfBoundsException(); - return maRelations[nIndex]; -} - -bool AccessibleRelationSetHelperImpl::containsRelation( sal_Int16 aRelationType ) const -{ - AccessibleRelation defaultRelation; // default is INVALID - AccessibleRelation relationByType = getRelationByType(aRelationType); - return relationByType.RelationType != defaultRelation.RelationType; -} - -AccessibleRelation AccessibleRelationSetHelperImpl::getRelationByType( sal_Int16 aRelationType ) const -{ - sal_Int32 nCount(getRelationCount()); - sal_Int32 i(0); - while (i < nCount) + AccessibleRelation lcl_getRelationByType( std::vector& raRelations, sal_Int16 aRelationType ) { - if (maRelations[i].RelationType == aRelationType) - return maRelations[i]; - i++; + for (const auto& aRelation: raRelations) + { + if (aRelation.RelationType == aRelationType) + return aRelation; + } + return AccessibleRelation(); } - return AccessibleRelation(); } - -void AccessibleRelationSetHelperImpl::AddRelation(const AccessibleRelation& rRelation) -{ - sal_Int32 nCount(getRelationCount()); - sal_Int32 i(0); - bool bFound(false); - while ((i < nCount) && !bFound) - { - if (maRelations[i].RelationType == rRelation.RelationType) - bFound = true; - else - i++; - } - if (bFound) - maRelations[i].TargetSet = comphelper::concatSequences(maRelations[i].TargetSet, rRelation.TargetSet); - else - maRelations.push_back(rRelation); -} - //===== internal ============================================================ AccessibleRelationSetHelper::AccessibleRelationSetHelper () - : mpHelperImpl(new AccessibleRelationSetHelperImpl) { } AccessibleRelationSetHelper::AccessibleRelationSetHelper (const AccessibleRelationSetHelper& rHelper) - : cppu::WeakImplHelper(rHelper) + : cppu::WeakImplHelper(rHelper), + maRelations(rHelper.maRelations) { - if (rHelper.mpHelperImpl) - mpHelperImpl.reset(new AccessibleRelationSetHelperImpl(*rHelper.mpHelperImpl)); - else - mpHelperImpl.reset(new AccessibleRelationSetHelperImpl()); } AccessibleRelationSetHelper::~AccessibleRelationSetHelper() @@ -141,7 +67,8 @@ sal_Int32 SAL_CALL AccessibleRelationSetHelper::getRelationCount( ) { osl::MutexGuard aGuard (maMutex); - return mpHelperImpl->getRelationCount(); + + return maRelations.size(); } /** Returns the relation of this relation set that is specified by @@ -161,7 +88,11 @@ sal_Int32 SAL_CALL AccessibleRelationSetHelper::getRelation( sal_Int32 nIndex ) { osl::MutexGuard aGuard (maMutex); - return mpHelperImpl->getRelation(nIndex); + + if ((nIndex < 0) || (o3tl::make_unsigned(nIndex) >= maRelations.size())) + throw lang::IndexOutOfBoundsException(); + + return maRelations[nIndex]; } /** Tests whether the relation set contains a relation matching the @@ -180,7 +111,10 @@ sal_Bool SAL_CALL AccessibleRelationSetHelper::containsRelation( sal_Int16 aRelationType ) { osl::MutexGuard aGuard (maMutex); - return mpHelperImpl->containsRelation(aRelationType); + + AccessibleRelation defaultRelation; // default is INVALID + AccessibleRelation relationByType = lcl_getRelationByType(maRelations, aRelationType); + return relationByType.RelationType != defaultRelation.RelationType; } /** Retrieve and return the relation with the given relation type. @@ -198,13 +132,23 @@ AccessibleRelation SAL_CALL AccessibleRelationSetHelper::getRelationByType( sal_Int16 aRelationType ) { osl::MutexGuard aGuard (maMutex); - return mpHelperImpl->getRelationByType(aRelationType); + + return lcl_getRelationByType(maRelations, aRelationType); } void AccessibleRelationSetHelper::AddRelation(const AccessibleRelation& rRelation) { osl::MutexGuard aGuard (maMutex); - mpHelperImpl->AddRelation(rRelation); + + for (auto& aRelation: maRelations) + { + if (aRelation.RelationType == rRelation.RelationType) + { + aRelation.TargetSet = comphelper::concatSequences(aRelation.TargetSet, rRelation.TargetSet); + return; + } + } + maRelations.push_back(rRelation); } //===== XTypeProvider =======================================================