LCOV - code coverage report
Current view: top level - libreoffice/unotools/source/accessibility - accessiblerelationsethelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 76 0.0 %
Date: 2012-12-27 Functions: 0 19 0.0 %
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 ::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           0 : AccessibleRelationSetHelperImpl::AccessibleRelationSetHelperImpl()
      54             : {
      55           0 : }
      56             : 
      57           0 : AccessibleRelationSetHelperImpl::AccessibleRelationSetHelperImpl(const AccessibleRelationSetHelperImpl& rImpl)
      58           0 :     : maRelations(rImpl.maRelations)
      59             : {
      60           0 : }
      61             : 
      62           0 : AccessibleRelationSetHelperImpl::~AccessibleRelationSetHelperImpl()
      63             : {
      64           0 : }
      65             : 
      66           0 : sal_Int32 AccessibleRelationSetHelperImpl::getRelationCount(  )
      67             :     throw (uno::RuntimeException)
      68             : {
      69           0 :     return maRelations.size();
      70             : }
      71             : 
      72           0 : AccessibleRelation AccessibleRelationSetHelperImpl::getRelation( sal_Int32 nIndex )
      73             :     throw (lang::IndexOutOfBoundsException,
      74             :             uno::RuntimeException)
      75             : {
      76           0 :     if ((nIndex < 0) || (static_cast<sal_uInt32>(nIndex) >= maRelations.size()))
      77           0 :         throw lang::IndexOutOfBoundsException();
      78           0 :     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           0 : void AccessibleRelationSetHelperImpl::AddRelation(const AccessibleRelation& rRelation)
     106             :     throw (uno::RuntimeException)
     107             : {
     108           0 :     sal_Int32 nCount(getRelationCount());
     109           0 :     sal_Int32 i(0);
     110           0 :     sal_Bool bFound(sal_False);
     111           0 :     while ((i < nCount) && !bFound)
     112             :     {
     113           0 :         if (maRelations[i].RelationType == rRelation.RelationType)
     114           0 :             bFound = sal_True;
     115             :         else
     116           0 :             i++;
     117             :     }
     118           0 :     if (bFound)
     119           0 :         maRelations[i].TargetSet = comphelper::concatSequences(maRelations[i].TargetSet, rRelation.TargetSet);
     120             :     else
     121           0 :         maRelations.push_back(rRelation);
     122           0 : }
     123             : 
     124             : //=====  internal  ============================================================
     125             : 
     126           0 : AccessibleRelationSetHelper::AccessibleRelationSetHelper ()
     127           0 :     : mpHelperImpl(NULL)
     128             : {
     129           0 :     mpHelperImpl = new AccessibleRelationSetHelperImpl();
     130           0 : }
     131             : 
     132           0 : AccessibleRelationSetHelper::AccessibleRelationSetHelper (const AccessibleRelationSetHelper& rHelper)
     133             :     : cppu::WeakImplHelper1<XAccessibleRelationSet>()
     134           0 :     , mpHelperImpl(NULL)
     135             : {
     136           0 :     if (rHelper.mpHelperImpl)
     137           0 :         mpHelperImpl = new AccessibleRelationSetHelperImpl(*rHelper.mpHelperImpl);
     138             :     else
     139           0 :         mpHelperImpl = new AccessibleRelationSetHelperImpl();
     140           0 : }
     141             : 
     142           0 : AccessibleRelationSetHelper::~AccessibleRelationSetHelper(void)
     143             : {
     144           0 :     delete mpHelperImpl;
     145           0 : }
     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           0 :     AccessibleRelationSetHelper::getRelationCount(  )
     156             :         throw (uno::RuntimeException)
     157             : {
     158           0 :     osl::MutexGuard aGuard (maMutex);
     159           0 :     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           0 :         AccessibleRelationSetHelper::getRelation( sal_Int32 nIndex )
     177             :             throw (lang::IndexOutOfBoundsException,
     178             :                     uno::RuntimeException)
     179             : {
     180           0 :     osl::MutexGuard aGuard (maMutex);
     181           0 :     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           0 : void AccessibleRelationSetHelper::AddRelation(const AccessibleRelation& rRelation)
     224             :             throw (uno::RuntimeException)
     225             : {
     226           0 :     osl::MutexGuard aGuard (maMutex);
     227           0 :     mpHelperImpl->AddRelation(rRelation);
     228           0 : }
     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