LCOV - code coverage report
Current view: top level - unotools/source/accessibility - accessiblerelationsethelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 44 76 57.9 %
Date: 2014-11-03 Functions: 13 19 68.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <unotools/accessiblerelationsethelper.hxx>
      21             : #include <vector>
      22             : #include <comphelper/sequence.hxx>
      23             : #include <comphelper/servicehelper.hxx>
      24             : 
      25             : using namespace ::utl;
      26             : using namespace ::com::sun::star;
      27             : using namespace ::com::sun::star::accessibility;
      28             : 
      29             : class AccessibleRelationSetHelperImpl
      30             : {
      31             : public:
      32             :     AccessibleRelationSetHelperImpl();
      33             :     AccessibleRelationSetHelperImpl(const AccessibleRelationSetHelperImpl& rImpl);
      34             :     ~AccessibleRelationSetHelperImpl();
      35             : 
      36             :     sal_Int32 getRelationCount(  )
      37             :         throw (uno::RuntimeException);
      38             :     AccessibleRelation getRelation( sal_Int32 nIndex )
      39             :             throw (lang::IndexOutOfBoundsException,
      40             :                     uno::RuntimeException);
      41             :     bool containsRelation( sal_Int16 aRelationType )
      42             :         throw (uno::RuntimeException);
      43             :     AccessibleRelation getRelationByType( sal_Int16 aRelationType )
      44             :             throw (uno::RuntimeException);
      45             :     void AddRelation(const AccessibleRelation& rRelation)
      46             :             throw (uno::RuntimeException);
      47             : 
      48             : private:
      49             :     std::vector<AccessibleRelation> maRelations;
      50             : };
      51             : 
      52          72 : AccessibleRelationSetHelperImpl::AccessibleRelationSetHelperImpl()
      53             : {
      54          72 : }
      55             : 
      56           2 : AccessibleRelationSetHelperImpl::AccessibleRelationSetHelperImpl(const AccessibleRelationSetHelperImpl& rImpl)
      57           2 :     : maRelations(rImpl.maRelations)
      58             : {
      59           2 : }
      60             : 
      61          74 : AccessibleRelationSetHelperImpl::~AccessibleRelationSetHelperImpl()
      62             : {
      63          74 : }
      64             : 
      65          12 : sal_Int32 AccessibleRelationSetHelperImpl::getRelationCount(  )
      66             :     throw (uno::RuntimeException)
      67             : {
      68          12 :     return maRelations.size();
      69             : }
      70             : 
      71          12 : AccessibleRelation AccessibleRelationSetHelperImpl::getRelation( sal_Int32 nIndex )
      72             :     throw (lang::IndexOutOfBoundsException,
      73             :             uno::RuntimeException)
      74             : {
      75          12 :     if ((nIndex < 0) || (static_cast<sal_uInt32>(nIndex) >= maRelations.size()))
      76           0 :         throw lang::IndexOutOfBoundsException();
      77          12 :     return maRelations[nIndex];
      78             : }
      79             : 
      80           0 : bool AccessibleRelationSetHelperImpl::containsRelation( sal_Int16 aRelationType )
      81             :     throw (uno::RuntimeException)
      82             : {
      83           0 :     AccessibleRelation defaultRelation; // default is INVALID
      84           0 :     AccessibleRelation relationByType = getRelationByType(aRelationType);
      85           0 :     return relationByType.RelationType != defaultRelation.RelationType;
      86             : }
      87             : 
      88           0 : AccessibleRelation AccessibleRelationSetHelperImpl::getRelationByType( sal_Int16 aRelationType )
      89             :     throw (uno::RuntimeException)
      90             : {
      91           0 :     sal_Int32 nCount(getRelationCount());
      92           0 :     sal_Int32 i(0);
      93           0 :     bool bFound(false);
      94           0 :     while ((i < nCount) && !bFound)
      95             :     {
      96           0 :         if (maRelations[i].RelationType == aRelationType)
      97           0 :             return maRelations[i];
      98             :         else
      99           0 :             i++;
     100             :     }
     101           0 :     return AccessibleRelation();
     102             : }
     103             : 
     104           8 : void AccessibleRelationSetHelperImpl::AddRelation(const AccessibleRelation& rRelation)
     105             :     throw (uno::RuntimeException)
     106             : {
     107           8 :     sal_Int32 nCount(getRelationCount());
     108           8 :     sal_Int32 i(0);
     109           8 :     bool bFound(false);
     110          18 :     while ((i < nCount) && !bFound)
     111             :     {
     112           2 :         if (maRelations[i].RelationType == rRelation.RelationType)
     113           0 :             bFound = true;
     114             :         else
     115           2 :             i++;
     116             :     }
     117           8 :     if (bFound)
     118           0 :         maRelations[i].TargetSet = comphelper::concatSequences(maRelations[i].TargetSet, rRelation.TargetSet);
     119             :     else
     120           8 :         maRelations.push_back(rRelation);
     121           8 : }
     122             : 
     123             : //=====  internal  ============================================================
     124             : 
     125          72 : AccessibleRelationSetHelper::AccessibleRelationSetHelper ()
     126          72 :     : mpHelperImpl(NULL)
     127             : {
     128          72 :     mpHelperImpl = new AccessibleRelationSetHelperImpl();
     129          72 : }
     130             : 
     131           2 : AccessibleRelationSetHelper::AccessibleRelationSetHelper (const AccessibleRelationSetHelper& rHelper)
     132             :     : cppu::WeakImplHelper1<XAccessibleRelationSet>()
     133           2 :     , mpHelperImpl(NULL)
     134             : {
     135           2 :     if (rHelper.mpHelperImpl)
     136           2 :         mpHelperImpl = new AccessibleRelationSetHelperImpl(*rHelper.mpHelperImpl);
     137             :     else
     138           0 :         mpHelperImpl = new AccessibleRelationSetHelperImpl();
     139           2 : }
     140             : 
     141         222 : AccessibleRelationSetHelper::~AccessibleRelationSetHelper(void)
     142             : {
     143          74 :     delete mpHelperImpl;
     144         148 : }
     145             : 
     146             : //=====  XAccessibleRelationSet  ==============================================
     147             : 
     148             :     /** Returns the number of relations in this relation set.
     149             : 
     150             :         @return
     151             :             Returns the number of relations or zero if there are none.
     152             :     */
     153             : sal_Int32 SAL_CALL
     154           4 :     AccessibleRelationSetHelper::getRelationCount(  )
     155             :         throw (uno::RuntimeException, std::exception)
     156             : {
     157           4 :     osl::MutexGuard aGuard (maMutex);
     158           4 :     return mpHelperImpl->getRelationCount();
     159             : }
     160             : 
     161             :     /** Returns the relation of this relation set that is specified by
     162             :         the given index.
     163             : 
     164             :         @param nIndex
     165             :             This index specifies the relatio to return.
     166             : 
     167             :         @return
     168             :             For a valid index, i.e. inside the range 0 to the number of
     169             :             relations minus one, the returned value is the requested
     170             :             relation.  If the index is invalid then the returned relation
     171             :             has the type INVALID.
     172             : 
     173             :     */
     174             :  AccessibleRelation SAL_CALL
     175          12 :         AccessibleRelationSetHelper::getRelation( sal_Int32 nIndex )
     176             :             throw (lang::IndexOutOfBoundsException,
     177             :                     uno::RuntimeException, std::exception)
     178             : {
     179          12 :     osl::MutexGuard aGuard (maMutex);
     180          12 :     return mpHelperImpl->getRelation(nIndex);
     181             : }
     182             : 
     183             :     /** Tests whether the relation set contains a relation matching the
     184             :         specified key.
     185             : 
     186             :         @param aRelationType
     187             :             The type of relation to look for in this set of relations.  This
     188             :             has to be one of the constants of
     189             :             <type>AccessibleRelationType</type>.
     190             : 
     191             :         @return
     192             :             Returns <TRUE/> if there is a (at least one) relation of the
     193             :             given type and <FALSE/> if there is no such relation in the set.
     194             :     */
     195             : sal_Bool SAL_CALL
     196           0 :     AccessibleRelationSetHelper::containsRelation( sal_Int16 aRelationType )
     197             :         throw (uno::RuntimeException, std::exception)
     198             : {
     199           0 :     osl::MutexGuard aGuard (maMutex);
     200           0 :     return mpHelperImpl->containsRelation(aRelationType);
     201             : }
     202             : 
     203             :     /** Retrieve and return the relation with the given relation type.
     204             : 
     205             :         @param aRelationType
     206             :             The type of the relation to return.  This has to be one of the
     207             :             constants of <type>AccessibleRelationType</type>.
     208             : 
     209             :         @return
     210             :             If a relation with the given type could be found than (a copy
     211             :             of) this relation is returned.  Otherwise a relation with the
     212             :             type INVALID is returned.
     213             :     */
     214             : AccessibleRelation SAL_CALL
     215           0 :         AccessibleRelationSetHelper::getRelationByType( sal_Int16 aRelationType )
     216             :             throw (uno::RuntimeException, std::exception)
     217             : {
     218           0 :     osl::MutexGuard aGuard (maMutex);
     219           0 :     return mpHelperImpl->getRelationByType(aRelationType);
     220             : }
     221             : 
     222           8 : void AccessibleRelationSetHelper::AddRelation(const AccessibleRelation& rRelation)
     223             :             throw (uno::RuntimeException)
     224             : {
     225           8 :     osl::MutexGuard aGuard (maMutex);
     226           8 :     mpHelperImpl->AddRelation(rRelation);
     227           8 : }
     228             : 
     229             : //=====  XTypeProvider  =======================================================
     230             : 
     231             : uno::Sequence< ::com::sun::star::uno::Type>
     232           0 :     AccessibleRelationSetHelper::getTypes (void)
     233             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     234             : {
     235           0 :     osl::MutexGuard aGuard (maMutex);
     236             :     const ::com::sun::star::uno::Type aTypeList[] = {
     237           0 :         cppu::UnoType<XAccessibleRelationSet>::get(),
     238           0 :         cppu::UnoType<lang::XTypeProvider>::get()
     239           0 :         };
     240             :     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type>
     241           0 :         aTypeSequence (aTypeList, 2);
     242           0 :     return aTypeSequence;
     243             : }
     244             : 
     245             : uno::Sequence<sal_Int8> SAL_CALL
     246           0 :     AccessibleRelationSetHelper::getImplementationId (void)
     247             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     248             : {
     249           0 :     return css::uno::Sequence<sal_Int8>();
     250             : }
     251             : 
     252             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10