From e5cd144dd78ef6a63639d053ac348aead9705109 Mon Sep 17 00:00:00 2001 From: Sascha Ballach Date: Tue, 19 Feb 2002 07:29:29 +0000 Subject: #95584#; compare and remove method added; use bitset instead of map --- .../accessibility/accessiblestatesethelper.cxx | 74 +++++++++++++++++++--- 1 file changed, 64 insertions(+), 10 deletions(-) (limited to 'unotools/source/accessibility/accessiblestatesethelper.cxx') diff --git a/unotools/source/accessibility/accessiblestatesethelper.cxx b/unotools/source/accessibility/accessiblestatesethelper.cxx index b82cd2049045..10d75b3cf3bc 100644 --- a/unotools/source/accessibility/accessiblestatesethelper.cxx +++ b/unotools/source/accessibility/accessiblestatesethelper.cxx @@ -2,9 +2,9 @@ * * $RCSfile: accessiblestatesethelper.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: vg $ $Date: 2002-02-05 13:09:25 $ + * last change: $Author: sab $ $Date: 2002-02-19 08:29:29 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -65,7 +65,13 @@ #ifndef _RTL_UUID_H_ #include #endif -#include +#ifndef _TOOLS_DEBUG_HXX +#include +#endif +#include + +// defines how many states the bitfield can contain +#define BITFIELDSIZE 30 using namespace ::utl; using namespace ::rtl; @@ -84,9 +90,15 @@ public: throw (uno::RuntimeException); void AddState(sal_Int16 aState) throw (uno::RuntimeException); + void RemoveState(sal_Int16 aState) + throw (uno::RuntimeException); + void Compare(const AccessibleStateSetHelperImpl* pComparativeValue, + AccessibleStateSetHelperImpl* pOldStates, + AccessibleStateSetHelperImpl* pNewStates) + throw (uno::RuntimeException); private: - std::map maStates; + std::bitset maStates; //Bitfield }; AccessibleStateSetHelperImpl::AccessibleStateSetHelperImpl() @@ -100,23 +112,48 @@ AccessibleStateSetHelperImpl::~AccessibleStateSetHelperImpl() sal_Bool AccessibleStateSetHelperImpl::IsEmpty () throw (uno::RuntimeException) { - return maStates.empty(); + return maStates.none(); } sal_Bool AccessibleStateSetHelperImpl::Contains (sal_Int16 aState) throw (uno::RuntimeException) { - std::map::const_iterator aItr(maStates.find(aState)); - return (aItr != maStates.end()); + DBG_ASSERT(aState >= BITFIELDSIZE, "the statesset is to small") + return maStates.test(aState); } void AccessibleStateSetHelperImpl::AddState(sal_Int16 aState) throw (uno::RuntimeException) { - std::pair< const sal_Int16, sal_Bool > aStatePair(aState, sal_True); - maStates.insert(aStatePair); + DBG_ASSERT(aState >= BITFIELDSIZE, "the statesset is to small") + maStates.set(aState); +} + +void AccessibleStateSetHelperImpl::RemoveState(sal_Int16 aState) + throw (uno::RuntimeException) +{ + DBG_ASSERT(aState >= BITFIELDSIZE, "the statesset is to small") + maStates.set(aState, 0); +} + +void AccessibleStateSetHelperImpl::Compare( + const AccessibleStateSetHelperImpl* pComparativeValue, + AccessibleStateSetHelperImpl* pOldStates, + AccessibleStateSetHelperImpl* pNewStates) + throw (uno::RuntimeException) +{ + if (pComparativeValue && pOldStates && pNewStates) + { + std::bitset aTempBitSet(maStates); + aTempBitSet ^= pComparativeValue->maStates; + pOldStates->maStates = aTempBitSet; + pOldStates->maStates &= maStates; + pNewStates->maStates = aTempBitSet; + pNewStates->maStates &= pComparativeValue->maStates; + } } + //===== internal ============================================================ AccessibleStateSetHelper::AccessibleStateSetHelper () @@ -199,9 +236,27 @@ sal_Bool SAL_CALL AccessibleStateSetHelper::containsAll void AccessibleStateSetHelper::AddState(sal_Int16 aState) throw (uno::RuntimeException) { + ::vos::OGuard aGuard (maMutex); mpHelperImpl->AddState(aState); } +void AccessibleStateSetHelper::RemoveState(sal_Int16 aState) + throw (uno::RuntimeException) +{ + ::vos::OGuard aGuard (maMutex); + mpHelperImpl->RemoveState(aState); +} + +void AccessibleStateSetHelper::Compare( + const AccessibleStateSetHelper& rComparativeValue, + AccessibleStateSetHelper& rOldStates, + AccessibleStateSetHelper& rNewStates) + throw (uno::RuntimeException) +{ + ::vos::OGuard aGuard (maMutex); + mpHelperImpl->Compare(rComparativeValue.mpHelperImpl, + rOldStates.mpHelperImpl, rNewStates.mpHelperImpl); +} //===== XTypeProvider ======================================================= @@ -209,7 +264,6 @@ uno::Sequence< ::com::sun::star::uno::Type> AccessibleStateSetHelper::getTypes (void) throw (::com::sun::star::uno::RuntimeException) { - ::vos::OGuard aGuard (maMutex); const ::com::sun::star::uno::Type aTypeList[] = { ::getCppuType((const uno::Reference< XAccessibleStateSet>*)0), -- cgit v1.2.3