20#ifndef INCLUDED_VBAHELPER_VBACOLLECTIONIMPL_HXX
21#define INCLUDED_VBAHELPER_VBACOLLECTIONIMPL_HXX
27#include <com/sun/star/container/NoSuchElementException.hpp>
28#include <com/sun/star/container/XEnumeration.hpp>
29#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
30#include <com/sun/star/lang/WrappedTargetException.hpp>
31#include <com/sun/star/uno/Any.hxx>
32#include <com/sun/star/uno/Reference.hxx>
33#include <com/sun/star/uno/RuntimeException.hpp>
34#include <com/sun/star/uno/Sequence.hxx>
35#include <com/sun/star/uno/Type.hxx>
36#include <com/sun/star/uno/TypeClass.hpp>
40#include <ooo/vba/XCollection.hpp>
41#include <com/sun/star/container/XIndexAccess.hpp>
42#include <com/sun/star/container/XNameAccess.hpp>
43#include <com/sun/star/container/XNamed.hpp>
44#include <rtl/ustring.hxx>
51 namespace container {
class XEnumerationAccess; }
52 namespace uno {
class XComponentContext; }
56 class XHelperInterface;
75 css::uno::Reference< css::container::XIndexAccess > xIndexAccess ) :
76 mxIndexAccess(
std::move( xIndexAccess )),
mnIndex( 0 ) {}
80 return mnIndex < mxIndexAccess->getCount();
85 if( !hasMoreElements() )
86 throw css::container::NoSuchElementException();
87 return mxIndexAccess->getByIndex(
mnIndex++ );
108 const css::uno::Reference< css::container::XIndexAccess >& rxIndexAccess ) :
113 return mxEnumeration->hasMoreElements();
118 return createCollectionObject( mxEnumeration->nextElement() );
134 css::uno::WeakReference< ov::XHelperInterface >
m_xParent;
135 css::uno::Reference< css::uno::XComponentContext >
m_xContext;
139 EnumerationHelperImpl(
const css::uno::Reference< ov::XHelperInterface >& xParent, css::uno::Reference< css::uno::XComponentContext > xContext, css::uno::Reference< css::container::XEnumeration > xEnumeration ) : m_xParent( xParent ),
m_xContext(
std::move( xContext )), m_xEnumeration(
std::move( xEnumeration )) { }
147template<
typename OneIfc >
149 css::container::XIndexAccess,
150 css::container::XEnumerationAccess >
153typedef std::vector< css::uno::Reference< OneIfc > >
XNamedVec;
159 typename XNamedVec::iterator
mIt;
171 return css::uno::Any( *
mIt++ );
172 throw css::container::NoSuchElementException();
184 virtual css::uno::Any SAL_CALL
getByName(
const OUString& aName )
override
187 throw css::container::NoSuchElementException();
192 css::uno::Sequence< OUString > sNames(
mXNamedVec.size() );
193 OUString* pString = sNames.getArray();
194 typename XNamedVec::iterator it =
mXNamedVec.begin();
195 typename XNamedVec::iterator it_end =
mXNamedVec.end();
197 for ( ; it != it_end; ++it, ++pString )
199 css::uno::Reference< css::container::XNamed > xName( *it, css::uno::UNO_QUERY_THROW );
200 *pString = xName->getName();
207 typename XNamedVec::iterator it_end =
mXNamedVec.end();
210 css::uno::Reference< css::container::XNamed > xName( *
cachePos, css::uno::UNO_QUERY_THROW );
211 if (
aName == xName->getName() )
222 throw css::lang::IndexOutOfBoundsException();
228 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
createEnumeration( )
override
235template<
typename... Ifc >
247 if ( !m_xNameAccess.is() )
248 throw css::uno::RuntimeException(
"ScVbaCollectionBase string index access not supported by this object" );
252 const css::uno::Sequence< OUString > sElementNames = m_xNameAccess->getElementNames();
253 for(
const OUString& rName : sElementNames )
255 if( rName.equalsIgnoreAsciiCase( sIndex ) )
257 return createCollectionObject( m_xNameAccess->getByName( rName ) );
261 return createCollectionObject( m_xNameAccess->getByName( sIndex ) );
268 if ( !m_xIndexAccess.is() )
269 throw css::uno::RuntimeException(
"ScVbaCollectionBase numeric index access not supported by this object" );
272 throw css::lang::IndexOutOfBoundsException(
273 "index is 0 or negative" );
276 return createCollectionObject( m_xIndexAccess->getByIndex(
nIndex - 1 ) );
281 css::uno::Reference< css::container::XNameAccess > xNameAccess( xIndexAccess, css::uno::UNO_QUERY_THROW );
282 m_xIndexAccess = xIndexAccess;
283 m_xNameAccess = xNameAccess;
287 ScVbaCollectionBase(
const css::uno::Reference< ov::XHelperInterface >& xParent,
const css::uno::Reference< css::uno::XComponentContext >& xContext, css::uno::Reference< css::container::XIndexAccess > xIndexAccess,
bool bIgnoreCase =
false ) :
BaseColBase( xParent, xContext ), m_xIndexAccess(
std::move( xIndexAccess )), mbIgnoreCase( bIgnoreCase ) { m_xNameAccess.set(m_xIndexAccess, css::uno::UNO_QUERY); }
292 return m_xIndexAccess->getCount();
295 virtual css::uno::Any SAL_CALL
Item(
const css::uno::Any& Index1,
const css::uno::Any& )
override
297 OUString aStringSheet;
298 if (Index1.getValueTypeClass() == css::uno::TypeClass_DOUBLE)
304 aStringSheet = OUString::number(fIndex);
306 else if (Index1.getValueTypeClass() != css::uno::TypeClass_STRING)
309 if ( !( Index1 >>=
nIndex ) )
311 throw css::lang::IndexOutOfBoundsException(
"Couldn't convert index to Int32" );
314 return getItemByIntIndex(
nIndex );
317 Index1 >>= aStringSheet;
319 return getItemByStringIndex( aStringSheet );
328 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
createEnumeration()
override = 0;
335 return ( m_xIndexAccess->getCount() > 0 );
347 ScVbaCollectionBaseImpl(
const css::uno::Reference< ov::XHelperInterface > & xParent,
const css::uno::Reference< css::uno::XComponentContext >& xContext,
const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess ) :
CollImplBase( xParent, xContext, xIndexAccess){}
351template <
typename... Ifc >
358 CollTestImplHelper(
const css::uno::Reference< ov::XHelperInterface >& xParent,
const css::uno::Reference< css::uno::XComponentContext >& xContext,
const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess,
bool bIgnoreCase =
false ) :
ImplBase( xParent, xContext, xIndexAccess, bIgnoreCase ) {}
Reference< XComponentContext > m_xContext
ScVbaCollectionBase< ::cppu::WeakImplHelper< Ifc... > > ImplBase
CollTestImplHelper(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::container::XIndexAccess > &xIndexAccess, bool bIgnoreCase=false)
virtual sal_Bool SAL_CALL hasMoreElements() override
css::uno::Reference< css::container::XEnumeration > m_xEnumeration
css::uno::WeakReference< ov::XHelperInterface > m_xParent
css::uno::Reference< css::uno::XComponentContext > m_xContext
EnumerationHelperImpl(const css::uno::Reference< ov::XHelperInterface > &xParent, css::uno::Reference< css::uno::XComponentContext > xContext, css::uno::Reference< css::container::XEnumeration > xEnumeration)
ScVbaCollectionBaseImpl(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::container::XIndexAccess > &xIndexAccess)
css::uno::Reference< css::container::XNameAccess > m_xNameAccess
OUString SAL_CALL getDefaultMethodName() override
ScVbaCollectionBase(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, css::uno::Reference< css::container::XIndexAccess > xIndexAccess, bool bIgnoreCase=false)
virtual sal_Bool SAL_CALL hasElements() override
void UpdateCollectionIndex(const css::uno::Reference< css::container::XIndexAccess > &xIndexAccess)
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource)=0
virtual css::uno::Any SAL_CALL Item(const css::uno::Any &Index1, const css::uno::Any &) override
virtual css::uno::Any getItemByIntIndex(const sal_Int32 nIndex)
InheritedHelperInterfaceImpl< Ifc... > BaseColBase
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
virtual ::sal_Int32 SAL_CALL getCount() override
virtual css::uno::Any getItemByStringIndex(const OUString &sIndex)
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override=0
virtual css::uno::Type SAL_CALL getElementType() override=0
A wrapper that holds a com.sun.star.container.XEnumeration or a com.sun.star.container....
virtual sal_Bool SAL_CALL hasMoreElements() override
SimpleEnumerationBase(const css::uno::Reference< css::container::XIndexAccess > &rxIndexAccess)
css::uno::Reference< css::container::XEnumeration > mxEnumeration
virtual css::uno::Any createCollectionObject(const css::uno::Any &rSource)=0
Derived classes implement creation of a VBA implementation object from the passed container element.
virtual css::uno::Any SAL_CALL nextElement() override
A wrapper that holds a com.sun.star.container.XIndexAccess and provides a com.sun....
SimpleIndexAccessToEnumeration(css::uno::Reference< css::container::XIndexAccess > xIndexAccess)
virtual sal_Bool SAL_CALL hasMoreElements() override
virtual css::uno::Any SAL_CALL nextElement() override
css::uno::Reference< css::container::XIndexAccess > mxIndexAccess
virtual css::uno::Any SAL_CALL nextElement() override
XNamedEnumerationHelper(XNamedVec sMap)
virtual sal_Bool SAL_CALL hasMoreElements() override
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual css::uno::Type SAL_CALL getElementType() override
std::vector< css::uno::Reference< OneIfc > > XNamedVec
virtual css::uno::Any SAL_CALL getByIndex(::sal_Int32 Index) override
virtual ::sal_Int32 SAL_CALL getCount() override
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
virtual sal_Bool SAL_CALL hasElements() override
XNamedObjectCollectionHelper(XNamedVec sMap)
XNamedVec::iterator cachePos
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
css::uno::Type const & get()
enumrange< T >::Iterator begin(enumrange< T >)
::cppu::WeakImplHelper< css::container::XEnumeration > EnumerationHelper_BASE
ScVbaCollectionBase< ::cppu::WeakImplHelper< ov::XCollection > > CollImplBase
#define VBAHELPER_DLLPUBLIC