LCOV - code coverage report
Current view: top level - unotools/source/accessibility - accessiblestatesethelper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 60 92 65.2 %
Date: 2015-06-13 12:38:46 Functions: 15 22 68.2 %
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/accessiblestatesethelper.hxx>
      21             : #include <tools/debug.hxx>
      22             : #include <comphelper/servicehelper.hxx>
      23             : 
      24             : // defines how many states the bitfield can contain
      25             : // it has the size of 64 because I use a uInt64
      26             : #define BITFIELDSIZE 64
      27             : 
      28             : using namespace ::utl;
      29             : using namespace ::com::sun::star;
      30             : using namespace ::com::sun::star::accessibility;
      31             : 
      32             : class AccessibleStateSetHelperImpl
      33             : {
      34             : public:
      35             :     AccessibleStateSetHelperImpl();
      36             :     AccessibleStateSetHelperImpl(const AccessibleStateSetHelperImpl& rImpl);
      37             :     ~AccessibleStateSetHelperImpl();
      38             : 
      39             :     bool IsEmpty () const
      40             :         throw (uno::RuntimeException);
      41             :     bool Contains (sal_Int16 aState) const
      42             :         throw (uno::RuntimeException);
      43             :     uno::Sequence<sal_Int16> GetStates() const
      44             :         throw (uno::RuntimeException);
      45             :     void AddState(sal_Int16 aState)
      46             :         throw (uno::RuntimeException);
      47             :     void RemoveState(sal_Int16 aState)
      48             :         throw (uno::RuntimeException);
      49             : 
      50             :     inline void AddStates( const sal_Int64 _nStates );
      51             : 
      52             : private:
      53             :     sal_uInt64 maStates;
      54             : };
      55             : 
      56        4265 : AccessibleStateSetHelperImpl::AccessibleStateSetHelperImpl()
      57        4265 :     : maStates(0)
      58             : {
      59        4265 : }
      60             : 
      61          42 : AccessibleStateSetHelperImpl::AccessibleStateSetHelperImpl(const AccessibleStateSetHelperImpl& rImpl)
      62          42 :     : maStates(rImpl.maStates)
      63             : {
      64          42 : }
      65             : 
      66        4307 : AccessibleStateSetHelperImpl::~AccessibleStateSetHelperImpl()
      67             : {
      68        4307 : }
      69             : 
      70           0 : inline bool AccessibleStateSetHelperImpl::IsEmpty () const
      71             :     throw (uno::RuntimeException)
      72             : {
      73           0 :     return maStates == 0;
      74             : }
      75             : 
      76        5023 : inline bool AccessibleStateSetHelperImpl::Contains (sal_Int16 aState) const
      77             :     throw (uno::RuntimeException)
      78             : {
      79             :     DBG_ASSERT(aState < BITFIELDSIZE, "the statesset is too small");
      80        5023 :     sal_uInt64 aTempBitSet(1);
      81        5023 :     aTempBitSet <<= aState;
      82        5023 :     return ((aTempBitSet & maStates) != 0);
      83             : }
      84             : 
      85          12 : inline uno::Sequence<sal_Int16> AccessibleStateSetHelperImpl::GetStates() const
      86             :     throw (uno::RuntimeException)
      87             : {
      88          12 :     uno::Sequence<sal_Int16> aRet(BITFIELDSIZE);
      89          12 :     sal_Int16* pSeq = aRet.getArray();
      90          12 :     sal_Int16 nStateCount(0);
      91         780 :     for (sal_Int16 i = 0; i < BITFIELDSIZE; ++i)
      92         768 :         if (Contains(i))
      93             :         {
      94         102 :             *pSeq = i;
      95         102 :             ++pSeq;
      96         102 :             ++nStateCount;
      97             :         }
      98          12 :     aRet.realloc(nStateCount);
      99          12 :     return aRet;
     100             : }
     101             : 
     102           0 : inline void AccessibleStateSetHelperImpl::AddStates( const sal_Int64 _nStates )
     103             : {
     104           0 :     maStates |= _nStates;
     105           0 : }
     106             : 
     107       19696 : inline void AccessibleStateSetHelperImpl::AddState(sal_Int16 aState)
     108             :     throw (uno::RuntimeException)
     109             : {
     110             :     DBG_ASSERT(aState < BITFIELDSIZE, "the statesset is too small");
     111       19696 :     sal_uInt64 aTempBitSet(1);
     112       19696 :     aTempBitSet <<= aState;
     113       19696 :     maStates |= aTempBitSet;
     114       19696 : }
     115             : 
     116          63 : inline void AccessibleStateSetHelperImpl::RemoveState(sal_Int16 aState)
     117             :     throw (uno::RuntimeException)
     118             : {
     119             :     DBG_ASSERT(aState < BITFIELDSIZE, "the statesset is too small");
     120          63 :     sal_uInt64 aTempBitSet(1);
     121          63 :     aTempBitSet <<= aState;
     122          63 :     aTempBitSet = ~aTempBitSet;
     123          63 :     maStates &= aTempBitSet;
     124          63 : }
     125             : 
     126             : //=====  internal  ============================================================
     127             : 
     128        4265 : AccessibleStateSetHelper::AccessibleStateSetHelper ()
     129        4265 :     : mpHelperImpl(NULL)
     130             : {
     131        4265 :     mpHelperImpl = new AccessibleStateSetHelperImpl();
     132        4265 : }
     133             : 
     134           0 : AccessibleStateSetHelper::AccessibleStateSetHelper ( const sal_Int64 _nInitialStates )
     135           0 :     : mpHelperImpl(NULL)
     136             : {
     137           0 :     mpHelperImpl = new AccessibleStateSetHelperImpl();
     138           0 :     mpHelperImpl->AddStates( _nInitialStates );
     139           0 : }
     140             : 
     141          42 : AccessibleStateSetHelper::AccessibleStateSetHelper (const AccessibleStateSetHelper& rHelper)
     142             :     : cppu::WeakImplHelper1<XAccessibleStateSet>()
     143          42 :     , mpHelperImpl(NULL)
     144             : {
     145          42 :     if (rHelper.mpHelperImpl)
     146          42 :         mpHelperImpl = new AccessibleStateSetHelperImpl(*rHelper.mpHelperImpl);
     147             :     else
     148           0 :         mpHelperImpl = new AccessibleStateSetHelperImpl();
     149          42 : }
     150             : 
     151       12921 : AccessibleStateSetHelper::~AccessibleStateSetHelper()
     152             : {
     153        4307 :     delete mpHelperImpl;
     154        8614 : }
     155             : 
     156             : //=====  XAccessibleStateSet  ==============================================
     157             : 
     158             :     /** Checks whether the current state set is empty.
     159             : 
     160             :         @return
     161             :             Returns <TRUE/> if there is no state in this state set and
     162             :             <FALSE/> if there is at least one state set in it.
     163             :     */
     164           0 : sal_Bool SAL_CALL AccessibleStateSetHelper::isEmpty ()
     165             :     throw (uno::RuntimeException, std::exception)
     166             : {
     167           0 :     osl::MutexGuard aGuard (maMutex);
     168           0 :     return mpHelperImpl->IsEmpty();
     169             : }
     170             : 
     171             :     /** Checks if the given state is a member of the state set of this
     172             :         object.
     173             : 
     174             :         @param aState
     175             :             The state for which to check membership.  This has to be one of
     176             :             the constants of <type>AccessibleStateType</type>.
     177             : 
     178             :         @return
     179             :             Returns <TRUE/> if the given state is a member of this object's
     180             :             state set and <FALSE/> otherwise.
     181             :     */
     182        4255 : sal_Bool SAL_CALL AccessibleStateSetHelper::contains (sal_Int16 aState)
     183             :     throw (uno::RuntimeException, std::exception)
     184             : {
     185        4255 :     osl::MutexGuard aGuard (maMutex);
     186        4255 :     return mpHelperImpl->Contains(aState);
     187             : }
     188             : 
     189             :     /** Checks if all of the given states are in this object's state
     190             :         set.
     191             : 
     192             :         @param aStateSet
     193             :             This sequence of states is interpreted as set and every of its
     194             :             members, duplicates are ignored, is checked for membership in
     195             :             this object's state set.  Each state has to be one of the
     196             :             constants of <type>AccessibleStateType</type>.
     197             : 
     198             :         @return
     199             :             Returns <TRUE/> if all states of the given state set are members
     200             :             of this object's state set.  <FALSE/> is returned if at least
     201             :             one of the states in the given state is not a member of this
     202             :             object's state set.
     203             :     */
     204           0 : sal_Bool SAL_CALL AccessibleStateSetHelper::containsAll
     205             :     (const uno::Sequence<sal_Int16>& rStateSet)
     206             :     throw (uno::RuntimeException, std::exception)
     207             : {
     208           0 :     osl::MutexGuard aGuard (maMutex);
     209           0 :     sal_Int32 nCount(rStateSet.getLength());
     210           0 :     const sal_Int16* pStates = rStateSet.getConstArray();
     211           0 :     sal_Int32 i = 0;
     212           0 :     bool bFound(true);
     213           0 :     while (i < nCount)
     214             :     {
     215           0 :         bFound = mpHelperImpl->Contains(pStates[i]);
     216           0 :         i++;
     217             :     }
     218           0 :     return bFound;
     219             : }
     220             : 
     221          12 : uno::Sequence<sal_Int16> SAL_CALL AccessibleStateSetHelper::getStates()
     222             :     throw (uno::RuntimeException, std::exception)
     223             : {
     224          12 :     osl::MutexGuard aGuard(maMutex);
     225          12 :     return mpHelperImpl->GetStates();
     226             : }
     227             : 
     228       19696 : void AccessibleStateSetHelper::AddState(sal_Int16 aState)
     229             :     throw (uno::RuntimeException)
     230             : {
     231       19696 :     osl::MutexGuard aGuard (maMutex);
     232       19696 :     mpHelperImpl->AddState(aState);
     233       19696 : }
     234             : 
     235          63 : void AccessibleStateSetHelper::RemoveState(sal_Int16 aState)
     236             :     throw (uno::RuntimeException)
     237             : {
     238          63 :     osl::MutexGuard aGuard (maMutex);
     239          63 :     mpHelperImpl->RemoveState(aState);
     240          63 : }
     241             : 
     242             : //=====  XTypeProvider  =======================================================
     243             : 
     244             : uno::Sequence< ::com::sun::star::uno::Type>
     245           0 :     AccessibleStateSetHelper::getTypes()
     246             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     247             : {
     248             :     const ::com::sun::star::uno::Type aTypeList[] = {
     249           0 :         cppu::UnoType<XAccessibleStateSet>::get(),
     250           0 :         cppu::UnoType<lang::XTypeProvider>::get()
     251           0 :         };
     252             :     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type>
     253           0 :         aTypeSequence (aTypeList, 2);
     254           0 :     return aTypeSequence;
     255             : }
     256             : 
     257             : uno::Sequence<sal_Int8> SAL_CALL
     258           0 :     AccessibleStateSetHelper::getImplementationId()
     259             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
     260             : {
     261           0 :     return css::uno::Sequence<sal_Int8>();
     262             : }
     263             : 
     264             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11