2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-29 14:02:24 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-29 10:28:15 +00:00
|
|
|
|
|
|
|
#include <comphelper/enumhelper.hxx>
|
2004-01-28 11:46:55 +00:00
|
|
|
#include <com/sun/star/lang/XComponent.hpp>
|
|
|
|
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2000-09-29 10:28:15 +00:00
|
|
|
namespace comphelper
|
|
|
|
{
|
|
|
|
|
2014-02-25 17:52:30 +01:00
|
|
|
|
|
|
|
|
2000-09-29 10:28:15 +00:00
|
|
|
//= OEnumerationByName
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2004-01-28 11:46:55 +00:00
|
|
|
OEnumerationByName::OEnumerationByName(const staruno::Reference<starcontainer::XNameAccess>& _rxAccess)
|
|
|
|
:m_aNames(_rxAccess->getElementNames())
|
|
|
|
,m_nPos(0)
|
|
|
|
,m_xAccess(_rxAccess)
|
2014-02-16 22:51:15 +01:00
|
|
|
,m_bListening(false)
|
2004-01-28 11:46:55 +00:00
|
|
|
{
|
|
|
|
impl_startDisposeListening();
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2004-01-28 11:46:55 +00:00
|
|
|
OEnumerationByName::OEnumerationByName(const staruno::Reference<starcontainer::XNameAccess>& _rxAccess,
|
2013-04-07 12:06:47 +02:00
|
|
|
const staruno::Sequence< OUString >& _aNames )
|
2004-01-28 11:46:55 +00:00
|
|
|
:m_aNames(_aNames)
|
|
|
|
,m_nPos(0)
|
|
|
|
,m_xAccess(_rxAccess)
|
2014-02-16 22:51:15 +01:00
|
|
|
,m_bListening(false)
|
2004-01-28 11:46:55 +00:00
|
|
|
{
|
|
|
|
impl_startDisposeListening();
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2004-01-28 11:46:55 +00:00
|
|
|
OEnumerationByName::~OEnumerationByName()
|
|
|
|
{
|
|
|
|
impl_stopDisposeListening();
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
sal_Bool SAL_CALL OEnumerationByName::hasMoreElements( ) throw(staruno::RuntimeException, std::exception)
|
2000-09-29 10:28:15 +00:00
|
|
|
{
|
2004-01-28 11:46:55 +00:00
|
|
|
::osl::ResettableMutexGuard aLock(m_aLock);
|
|
|
|
|
2000-09-29 10:28:15 +00:00
|
|
|
if (m_xAccess.is() && m_aNames.getLength() > m_nPos)
|
2004-01-28 11:46:55 +00:00
|
|
|
return sal_True;
|
2000-09-29 10:28:15 +00:00
|
|
|
|
2004-01-28 11:46:55 +00:00
|
|
|
if (m_xAccess.is())
|
|
|
|
{
|
|
|
|
impl_stopDisposeListening();
|
|
|
|
m_xAccess.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
return sal_False;
|
2000-09-29 10:28:15 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2000-09-29 10:28:15 +00:00
|
|
|
staruno::Any SAL_CALL OEnumerationByName::nextElement( )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(starcontainer::NoSuchElementException, starlang::WrappedTargetException, staruno::RuntimeException, std::exception)
|
2000-09-29 10:28:15 +00:00
|
|
|
{
|
2004-01-28 11:46:55 +00:00
|
|
|
::osl::ResettableMutexGuard aLock(m_aLock);
|
|
|
|
|
2000-09-29 10:28:15 +00:00
|
|
|
staruno::Any aRes;
|
|
|
|
if (m_xAccess.is() && m_nPos < m_aNames.getLength())
|
|
|
|
aRes = m_xAccess->getByName(m_aNames.getConstArray()[m_nPos++]);
|
2004-01-28 11:46:55 +00:00
|
|
|
|
2000-09-29 10:28:15 +00:00
|
|
|
if (m_xAccess.is() && m_nPos >= m_aNames.getLength())
|
2004-01-28 11:46:55 +00:00
|
|
|
{
|
|
|
|
impl_stopDisposeListening();
|
|
|
|
m_xAccess.clear();
|
|
|
|
}
|
2000-09-29 10:28:15 +00:00
|
|
|
|
2012-02-28 00:38:23 -05:00
|
|
|
if (!aRes.hasValue()) //There are no more elements
|
2000-09-29 10:28:15 +00:00
|
|
|
throw starcontainer::NoSuchElementException();
|
|
|
|
|
|
|
|
return aRes;
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2004-01-28 11:46:55 +00:00
|
|
|
void SAL_CALL OEnumerationByName::disposing(const starlang::EventObject& aEvent)
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(staruno::RuntimeException, std::exception)
|
2004-01-28 11:46:55 +00:00
|
|
|
{
|
|
|
|
::osl::ResettableMutexGuard aLock(m_aLock);
|
|
|
|
|
|
|
|
if (aEvent.Source == m_xAccess)
|
|
|
|
m_xAccess.clear();
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2004-01-28 11:46:55 +00:00
|
|
|
void OEnumerationByName::impl_startDisposeListening()
|
|
|
|
{
|
|
|
|
::osl::ResettableMutexGuard aLock(m_aLock);
|
|
|
|
|
|
|
|
if (m_bListening)
|
|
|
|
return;
|
|
|
|
|
|
|
|
++m_refCount;
|
|
|
|
staruno::Reference< starlang::XComponent > xDisposable(m_xAccess, staruno::UNO_QUERY);
|
|
|
|
if (xDisposable.is())
|
|
|
|
{
|
|
|
|
xDisposable->addEventListener(this);
|
2014-02-16 22:51:15 +01:00
|
|
|
m_bListening = true;
|
2004-01-28 11:46:55 +00:00
|
|
|
}
|
|
|
|
--m_refCount;
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2004-01-28 11:46:55 +00:00
|
|
|
void OEnumerationByName::impl_stopDisposeListening()
|
|
|
|
{
|
|
|
|
::osl::ResettableMutexGuard aLock(m_aLock);
|
|
|
|
|
|
|
|
if (!m_bListening)
|
|
|
|
return;
|
|
|
|
|
|
|
|
++m_refCount;
|
|
|
|
staruno::Reference< starlang::XComponent > xDisposable(m_xAccess, staruno::UNO_QUERY);
|
|
|
|
if (xDisposable.is())
|
|
|
|
{
|
|
|
|
xDisposable->removeEventListener(this);
|
2014-02-16 22:51:15 +01:00
|
|
|
m_bListening = false;
|
2004-01-28 11:46:55 +00:00
|
|
|
}
|
|
|
|
--m_refCount;
|
|
|
|
}
|
|
|
|
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2000-09-29 10:28:15 +00:00
|
|
|
//= OEnumerationByIndex
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2004-01-28 11:46:55 +00:00
|
|
|
OEnumerationByIndex::OEnumerationByIndex(const staruno::Reference< starcontainer::XIndexAccess >& _rxAccess)
|
2006-06-19 21:46:20 +00:00
|
|
|
:m_nPos(0)
|
|
|
|
,m_xAccess(_rxAccess)
|
2014-02-16 22:51:15 +01:00
|
|
|
,m_bListening(false)
|
2004-01-28 11:46:55 +00:00
|
|
|
{
|
|
|
|
impl_startDisposeListening();
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2004-01-28 11:46:55 +00:00
|
|
|
OEnumerationByIndex::~OEnumerationByIndex()
|
|
|
|
{
|
|
|
|
impl_stopDisposeListening();
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
sal_Bool SAL_CALL OEnumerationByIndex::hasMoreElements( ) throw(staruno::RuntimeException, std::exception)
|
2000-09-29 10:28:15 +00:00
|
|
|
{
|
2004-01-28 11:46:55 +00:00
|
|
|
::osl::ResettableMutexGuard aLock(m_aLock);
|
|
|
|
|
2000-09-29 10:28:15 +00:00
|
|
|
if (m_xAccess.is() && m_xAccess->getCount() > m_nPos)
|
2004-01-28 11:46:55 +00:00
|
|
|
return sal_True;
|
|
|
|
|
|
|
|
if (m_xAccess.is())
|
|
|
|
{
|
|
|
|
impl_stopDisposeListening();
|
|
|
|
m_xAccess.clear();
|
|
|
|
}
|
2000-09-29 10:28:15 +00:00
|
|
|
|
2004-01-28 11:46:55 +00:00
|
|
|
return sal_False;
|
2000-09-29 10:28:15 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2000-09-29 10:28:15 +00:00
|
|
|
staruno::Any SAL_CALL OEnumerationByIndex::nextElement( )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(starcontainer::NoSuchElementException, starlang::WrappedTargetException, staruno::RuntimeException, std::exception)
|
2000-09-29 10:28:15 +00:00
|
|
|
{
|
2004-01-28 11:46:55 +00:00
|
|
|
::osl::ResettableMutexGuard aLock(m_aLock);
|
|
|
|
|
2000-09-29 10:28:15 +00:00
|
|
|
staruno::Any aRes;
|
|
|
|
if (m_xAccess.is())
|
|
|
|
{
|
|
|
|
aRes = m_xAccess->getByIndex(m_nPos++);
|
|
|
|
if (m_nPos >= m_xAccess->getCount())
|
2004-01-28 11:46:55 +00:00
|
|
|
{
|
|
|
|
impl_stopDisposeListening();
|
|
|
|
m_xAccess.clear();
|
|
|
|
}
|
2000-09-29 10:28:15 +00:00
|
|
|
}
|
|
|
|
|
2012-02-28 00:38:23 -05:00
|
|
|
if (!aRes.hasValue())
|
2000-09-29 10:28:15 +00:00
|
|
|
throw starcontainer::NoSuchElementException();
|
|
|
|
return aRes;
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2004-01-28 11:46:55 +00:00
|
|
|
void SAL_CALL OEnumerationByIndex::disposing(const starlang::EventObject& aEvent)
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(staruno::RuntimeException, std::exception)
|
2004-01-28 11:46:55 +00:00
|
|
|
{
|
|
|
|
::osl::ResettableMutexGuard aLock(m_aLock);
|
|
|
|
|
|
|
|
if (aEvent.Source == m_xAccess)
|
|
|
|
m_xAccess.clear();
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2004-01-28 11:46:55 +00:00
|
|
|
void OEnumerationByIndex::impl_startDisposeListening()
|
|
|
|
{
|
|
|
|
::osl::ResettableMutexGuard aLock(m_aLock);
|
|
|
|
|
|
|
|
if (m_bListening)
|
|
|
|
return;
|
|
|
|
|
|
|
|
++m_refCount;
|
|
|
|
staruno::Reference< starlang::XComponent > xDisposable(m_xAccess, staruno::UNO_QUERY);
|
|
|
|
if (xDisposable.is())
|
|
|
|
{
|
|
|
|
xDisposable->addEventListener(this);
|
2014-02-16 22:51:15 +01:00
|
|
|
m_bListening = true;
|
2004-01-28 11:46:55 +00:00
|
|
|
}
|
|
|
|
--m_refCount;
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2004-01-28 11:46:55 +00:00
|
|
|
void OEnumerationByIndex::impl_stopDisposeListening()
|
|
|
|
{
|
|
|
|
::osl::ResettableMutexGuard aLock(m_aLock);
|
|
|
|
|
|
|
|
if (!m_bListening)
|
|
|
|
return;
|
|
|
|
|
|
|
|
++m_refCount;
|
|
|
|
staruno::Reference< starlang::XComponent > xDisposable(m_xAccess, staruno::UNO_QUERY);
|
|
|
|
if (xDisposable.is())
|
|
|
|
{
|
|
|
|
xDisposable->removeEventListener(this);
|
2014-02-16 22:51:15 +01:00
|
|
|
m_bListening = false;
|
2004-01-28 11:46:55 +00:00
|
|
|
}
|
|
|
|
--m_refCount;
|
|
|
|
}
|
|
|
|
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2007-04-16 15:58:44 +00:00
|
|
|
//= OAnyEnumeration
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2007-04-16 15:58:44 +00:00
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2007-04-16 15:58:44 +00:00
|
|
|
OAnyEnumeration::OAnyEnumeration(const staruno::Sequence< staruno::Any >& lItems)
|
|
|
|
:m_nPos(0)
|
|
|
|
,m_lItems(lItems)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2007-04-16 15:58:44 +00:00
|
|
|
OAnyEnumeration::~OAnyEnumeration()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
sal_Bool SAL_CALL OAnyEnumeration::hasMoreElements( ) throw(staruno::RuntimeException, std::exception)
|
2007-04-16 15:58:44 +00:00
|
|
|
{
|
|
|
|
::osl::ResettableMutexGuard aLock(m_aLock);
|
|
|
|
|
|
|
|
return (m_lItems.getLength() > m_nPos);
|
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2007-04-16 15:58:44 +00:00
|
|
|
staruno::Any SAL_CALL OAnyEnumeration::nextElement( )
|
2014-02-25 21:31:58 +01:00
|
|
|
throw(starcontainer::NoSuchElementException, starlang::WrappedTargetException, staruno::RuntimeException, std::exception)
|
2007-04-16 15:58:44 +00:00
|
|
|
{
|
|
|
|
if ( ! hasMoreElements())
|
|
|
|
throw starcontainer::NoSuchElementException();
|
|
|
|
|
|
|
|
::osl::ResettableMutexGuard aLock(m_aLock);
|
|
|
|
sal_Int32 nPos = m_nPos;
|
|
|
|
++m_nPos;
|
|
|
|
return m_lItems[nPos];
|
|
|
|
}
|
|
|
|
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2000-09-29 10:28:15 +00:00
|
|
|
} // namespace comphelper
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2000-09-29 10:28:15 +00:00
|
|
|
|
|
|
|
|
2010-10-14 08:27:31 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|