[Libreoffice-commits] core.git: include/unotools unotools/source

Arnaud Versini (via logerrit) logerrit at kemper.freedesktop.org
Sun Oct 25 17:12:51 UTC 2020


 include/unotools/accessiblerelationsethelper.hxx              |    6 
 unotools/source/accessibility/accessiblerelationsethelper.cxx |  122 ++--------
 2 files changed, 35 insertions(+), 93 deletions(-)

New commits:
commit 9411511e647f0847506bd1143a19f33af79d376f
Author:     Arnaud Versini <arnaud.versini at libreoffice.org>
AuthorDate: Sun Oct 25 16:39:38 2020 +0100
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sun Oct 25 18:12:05 2020 +0100

    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 at collabora.co.uk>

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 <com/sun/star/accessibility/XAccessibleRelationSet.hpp>
 #include <osl/mutex.hxx>
 #include <cppuhelper/implbase.hxx>
-#include <memory>
-
-class AccessibleRelationSetHelperImpl;
+#include <vector>
 
 //= XAccessibleRelationSet helper classes
 
@@ -123,7 +121,7 @@ private:
     /// Mutex guarding this object.
     ::osl::Mutex maMutex;
     /// The implementation of this helper interface.
-    std::unique_ptr<AccessibleRelationSetHelperImpl>    mpHelperImpl;
+    std::vector<css::accessibility::AccessibleRelation> 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 <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  =======================================================


More information about the Libreoffice-commits mailing list