diff options
author | Arnaud Versini <arnaud.versini@libreoffice.org> | 2020-10-25 16:39:38 +0100 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-10-25 18:12:05 +0100 |
commit | 9411511e647f0847506bd1143a19f33af79d376f (patch) | |
tree | 9060bff49ad3084655860393c8fc69de6f39a7dc /unotools | |
parent | 37081085fa989aa2fd07a7a0d063295819e185a0 (diff) |
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 <noel.grandin@collabora.co.uk>
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/source/accessibility/accessiblerelationsethelper.cxx | 122 |
1 files changed, 33 insertions, 89 deletions
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 <com/sun/star/lang/IndexOutOfBoundsException.hpp> #include <o3tl/safeint.hxx> #include <unotools/accessiblerelationsethelper.hxx> -#include <vector> #include <comphelper/sequence.hxx> 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<AccessibleRelation> 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) - { - if (maRelations[i].RelationType == aRelationType) - return maRelations[i]; - i++; - } - return AccessibleRelation(); -} - -void AccessibleRelationSetHelperImpl::AddRelation(const AccessibleRelation& rRelation) -{ - sal_Int32 nCount(getRelationCount()); - sal_Int32 i(0); - bool bFound(false); - while ((i < nCount) && !bFound) + AccessibleRelation lcl_getRelationByType( std::vector<AccessibleRelation>& raRelations, sal_Int16 aRelationType ) { - if (maRelations[i].RelationType == rRelation.RelationType) - bFound = true; - else - i++; + for (const auto& aRelation: raRelations) + { + if (aRelation.RelationType == aRelationType) + return aRelation; + } + return AccessibleRelation(); } - 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<XAccessibleRelationSet>(rHelper) + : cppu::WeakImplHelper<XAccessibleRelationSet>(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 ======================================================= |