LCOV - code coverage report
Current view: top level - unotools/source/accessibility - accessiblerelationsethelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 44 76 57.9 %
Date: 2012-08-25 Functions: 13 19 68.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 28 106 26.4 %

           Branch data     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 ::rtl;
      27                 :            : using namespace ::com::sun::star;
      28                 :            : using namespace ::com::sun::star::accessibility;
      29                 :            : 
      30                 :            : class AccessibleRelationSetHelperImpl
      31                 :            : {
      32                 :            : public:
      33                 :            :     AccessibleRelationSetHelperImpl();
      34                 :            :     AccessibleRelationSetHelperImpl(const AccessibleRelationSetHelperImpl& rImpl);
      35                 :            :     ~AccessibleRelationSetHelperImpl();
      36                 :            : 
      37                 :            :     sal_Int32 getRelationCount(  )
      38                 :            :         throw (uno::RuntimeException);
      39                 :            :     AccessibleRelation getRelation( sal_Int32 nIndex )
      40                 :            :             throw (lang::IndexOutOfBoundsException,
      41                 :            :                     uno::RuntimeException);
      42                 :            :     sal_Bool containsRelation( sal_Int16 aRelationType )
      43                 :            :         throw (uno::RuntimeException);
      44                 :            :     AccessibleRelation getRelationByType( sal_Int16 aRelationType )
      45                 :            :             throw (uno::RuntimeException);
      46                 :            :     void AddRelation(const AccessibleRelation& rRelation)
      47                 :            :             throw (uno::RuntimeException);
      48                 :            : 
      49                 :            : private:
      50                 :            :     std::vector<AccessibleRelation> maRelations;
      51                 :            : };
      52                 :            : 
      53                 :         69 : AccessibleRelationSetHelperImpl::AccessibleRelationSetHelperImpl()
      54                 :            : {
      55                 :         69 : }
      56                 :            : 
      57                 :          4 : AccessibleRelationSetHelperImpl::AccessibleRelationSetHelperImpl(const AccessibleRelationSetHelperImpl& rImpl)
      58                 :          4 :     : maRelations(rImpl.maRelations)
      59                 :            : {
      60                 :          4 : }
      61                 :            : 
      62                 :         73 : AccessibleRelationSetHelperImpl::~AccessibleRelationSetHelperImpl()
      63                 :            : {
      64                 :         73 : }
      65                 :            : 
      66                 :         10 : sal_Int32 AccessibleRelationSetHelperImpl::getRelationCount(  )
      67                 :            :     throw (uno::RuntimeException)
      68                 :            : {
      69                 :         10 :     return maRelations.size();
      70                 :            : }
      71                 :            : 
      72                 :         12 : AccessibleRelation AccessibleRelationSetHelperImpl::getRelation( sal_Int32 nIndex )
      73                 :            :     throw (lang::IndexOutOfBoundsException,
      74                 :            :             uno::RuntimeException)
      75                 :            : {
      76 [ +  - ][ -  + ]:         12 :     if ((nIndex < 0) || (static_cast<sal_uInt32>(nIndex) >= maRelations.size()))
                 [ -  + ]
      77         [ #  # ]:          0 :         throw lang::IndexOutOfBoundsException();
      78                 :         12 :     return maRelations[nIndex];
      79                 :            : }
      80                 :            : 
      81                 :          0 : sal_Bool AccessibleRelationSetHelperImpl::containsRelation( sal_Int16 aRelationType )
      82                 :            :     throw (uno::RuntimeException)
      83                 :            : {
      84         [ #  # ]:          0 :     AccessibleRelation defaultRelation; // default is INVALID
      85         [ #  # ]:          0 :     AccessibleRelation relationByType = getRelationByType(aRelationType);
      86 [ #  # ][ #  # ]:          0 :     return relationByType.RelationType != defaultRelation.RelationType;
      87                 :            : }
      88                 :            : 
      89                 :          0 : AccessibleRelation AccessibleRelationSetHelperImpl::getRelationByType( sal_Int16 aRelationType )
      90                 :            :     throw (uno::RuntimeException)
      91                 :            : {
      92                 :          0 :     sal_Int32 nCount(getRelationCount());
      93                 :          0 :     sal_Int32 i(0);
      94                 :          0 :     sal_Bool bFound(sal_False);
      95 [ #  # ][ #  # ]:          0 :     while ((i < nCount) && !bFound)
                 [ #  # ]
      96                 :            :     {
      97         [ #  # ]:          0 :         if (maRelations[i].RelationType == aRelationType)
      98                 :          0 :             return maRelations[i];
      99                 :            :         else
     100                 :          0 :             i++;
     101                 :            :     }
     102                 :          0 :     return AccessibleRelation();
     103                 :            : }
     104                 :            : 
     105                 :          6 : void AccessibleRelationSetHelperImpl::AddRelation(const AccessibleRelation& rRelation)
     106                 :            :     throw (uno::RuntimeException)
     107                 :            : {
     108                 :          6 :     sal_Int32 nCount(getRelationCount());
     109                 :          6 :     sal_Int32 i(0);
     110                 :          6 :     sal_Bool bFound(sal_False);
     111 [ +  + ][ +  - ]:          8 :     while ((i < nCount) && !bFound)
                 [ +  + ]
     112                 :            :     {
     113         [ -  + ]:          2 :         if (maRelations[i].RelationType == rRelation.RelationType)
     114                 :          0 :             bFound = sal_True;
     115                 :            :         else
     116                 :          2 :             i++;
     117                 :            :     }
     118         [ -  + ]:          6 :     if (bFound)
     119         [ #  # ]:          0 :         maRelations[i].TargetSet = comphelper::concatSequences(maRelations[i].TargetSet, rRelation.TargetSet);
     120                 :            :     else
     121                 :          6 :         maRelations.push_back(rRelation);
     122                 :          6 : }
     123                 :            : 
     124                 :            : //=====  internal  ============================================================
     125                 :            : 
     126                 :         69 : AccessibleRelationSetHelper::AccessibleRelationSetHelper ()
     127         [ +  - ]:         69 :     : mpHelperImpl(NULL)
     128                 :            : {
     129 [ +  - ][ +  - ]:         69 :     mpHelperImpl = new AccessibleRelationSetHelperImpl();
     130                 :         69 : }
     131                 :            : 
     132                 :          4 : AccessibleRelationSetHelper::AccessibleRelationSetHelper (const AccessibleRelationSetHelper& rHelper)
     133                 :            :     : cppu::WeakImplHelper1<XAccessibleRelationSet>()
     134         [ +  - ]:          4 :     , mpHelperImpl(NULL)
     135                 :            : {
     136         [ +  - ]:          4 :     if (rHelper.mpHelperImpl)
     137 [ +  - ][ +  - ]:          4 :         mpHelperImpl = new AccessibleRelationSetHelperImpl(*rHelper.mpHelperImpl);
     138                 :            :     else
     139 [ #  # ][ #  # ]:          0 :         mpHelperImpl = new AccessibleRelationSetHelperImpl();
     140                 :          4 : }
     141                 :            : 
     142         [ +  - ]:         73 : AccessibleRelationSetHelper::~AccessibleRelationSetHelper(void)
     143                 :            : {
     144         [ +  - ]:         73 :     delete mpHelperImpl;
     145         [ -  + ]:        146 : }
     146                 :            : 
     147                 :            : //=====  XAccessibleRelationSet  ==============================================
     148                 :            : 
     149                 :            :     /** Returns the number of relations in this relation set.
     150                 :            : 
     151                 :            :         @return
     152                 :            :             Returns the number of relations or zero if there are none.
     153                 :            :     */
     154                 :            : sal_Int32 SAL_CALL
     155                 :          4 :     AccessibleRelationSetHelper::getRelationCount(  )
     156                 :            :         throw (uno::RuntimeException)
     157                 :            : {
     158         [ +  - ]:          4 :     osl::MutexGuard aGuard (maMutex);
     159         [ +  - ]:          4 :     return mpHelperImpl->getRelationCount();
     160                 :            : }
     161                 :            : 
     162                 :            :     /** Returns the relation of this relation set that is specified by
     163                 :            :         the given index.
     164                 :            : 
     165                 :            :         @param nIndex
     166                 :            :             This index specifies the relatio to return.
     167                 :            : 
     168                 :            :         @return
     169                 :            :             For a valid index, i.e. inside the range 0 to the number of
     170                 :            :             relations minus one, the returned value is the requested
     171                 :            :             relation.  If the index is invalid then the returned relation
     172                 :            :             has the type INVALID.
     173                 :            : 
     174                 :            :     */
     175                 :            :  AccessibleRelation SAL_CALL
     176                 :         12 :         AccessibleRelationSetHelper::getRelation( sal_Int32 nIndex )
     177                 :            :             throw (lang::IndexOutOfBoundsException,
     178                 :            :                     uno::RuntimeException)
     179                 :            : {
     180         [ +  - ]:         12 :     osl::MutexGuard aGuard (maMutex);
     181 [ +  - ][ +  - ]:         12 :     return mpHelperImpl->getRelation(nIndex);
     182                 :            : }
     183                 :            : 
     184                 :            :     /** Tests whether the relation set contains a relation matching the
     185                 :            :         specified key.
     186                 :            : 
     187                 :            :         @param aRelationType
     188                 :            :             The type of relation to look for in this set of relations.  This
     189                 :            :             has to be one of the constants of
     190                 :            :             <type>AccessibleRelationType</type>.
     191                 :            : 
     192                 :            :         @return
     193                 :            :             Returns <TRUE/> if there is a (at least one) relation of the
     194                 :            :             given type and <FALSE/> if there is no such relation in the set.
     195                 :            :     */
     196                 :            : sal_Bool SAL_CALL
     197                 :          0 :     AccessibleRelationSetHelper::containsRelation( sal_Int16 aRelationType )
     198                 :            :         throw (uno::RuntimeException)
     199                 :            : {
     200         [ #  # ]:          0 :     osl::MutexGuard aGuard (maMutex);
     201 [ #  # ][ #  # ]:          0 :     return mpHelperImpl->containsRelation(aRelationType);
     202                 :            : }
     203                 :            : 
     204                 :            :     /** Retrieve and return the relation with the given relation type.
     205                 :            : 
     206                 :            :         @param aRelationType
     207                 :            :             The type of the relation to return.  This has to be one of the
     208                 :            :             constants of <type>AccessibleRelationType</type>.
     209                 :            : 
     210                 :            :         @return
     211                 :            :             If a relation with the given type could be found than (a copy
     212                 :            :             of) this relation is returned.  Otherwise a relation with the
     213                 :            :             type INVALID is returned.
     214                 :            :     */
     215                 :            : AccessibleRelation SAL_CALL
     216                 :          0 :         AccessibleRelationSetHelper::getRelationByType( sal_Int16 aRelationType )
     217                 :            :             throw (uno::RuntimeException)
     218                 :            : {
     219         [ #  # ]:          0 :     osl::MutexGuard aGuard (maMutex);
     220 [ #  # ][ #  # ]:          0 :     return mpHelperImpl->getRelationByType(aRelationType);
     221                 :            : }
     222                 :            : 
     223                 :          6 : void AccessibleRelationSetHelper::AddRelation(const AccessibleRelation& rRelation)
     224                 :            :             throw (uno::RuntimeException)
     225                 :            : {
     226         [ +  - ]:          6 :     osl::MutexGuard aGuard (maMutex);
     227 [ +  - ][ +  - ]:          6 :     mpHelperImpl->AddRelation(rRelation);
     228                 :          6 : }
     229                 :            : 
     230                 :            : //=====  XTypeProvider  =======================================================
     231                 :            : 
     232                 :            : uno::Sequence< ::com::sun::star::uno::Type>
     233                 :          0 :     AccessibleRelationSetHelper::getTypes (void)
     234                 :            :     throw (::com::sun::star::uno::RuntimeException)
     235                 :            : {
     236         [ #  # ]:          0 :     osl::MutexGuard aGuard (maMutex);
     237                 :            :     const ::com::sun::star::uno::Type aTypeList[] = {
     238                 :            :         ::getCppuType((const uno::Reference<
     239         [ #  # ]:          0 :             XAccessibleRelationSet>*)0),
     240                 :            :         ::getCppuType((const uno::Reference<
     241         [ #  # ]:          0 :             lang::XTypeProvider>*)0)
     242   [ #  #  #  # ]:          0 :         };
     243                 :            :     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type>
     244         [ #  # ]:          0 :         aTypeSequence (aTypeList, 2);
     245 [ #  # ][ #  # ]:          0 :     return aTypeSequence;
                 [ #  # ]
     246                 :            : }
     247                 :            : 
     248                 :            : namespace
     249                 :            : {
     250                 :            :     class theAccessibleRelationSetHelperUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theAccessibleRelationSetHelperUnoTunnelId > {};
     251                 :            : }
     252                 :            : 
     253                 :            : uno::Sequence<sal_Int8> SAL_CALL
     254                 :          0 :     AccessibleRelationSetHelper::getImplementationId (void)
     255                 :            :     throw (::com::sun::star::uno::RuntimeException)
     256                 :            : {
     257                 :          0 :     return theAccessibleRelationSetHelperUnoTunnelId::get().getSeq();
     258                 :            : }
     259                 :            : 
     260                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10