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

Generated by: LCOV version 1.10