1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: crarray.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_stoc.hxx"
33 #include <typelib/typedescription.h>
43 //__________________________________________________________________________________________________
44 Any
ArrayIdlClassImpl::queryInterface( const Type
& rType
)
45 throw(::com::sun::star::uno::RuntimeException
)
47 Any
aRet( ::cppu::queryInterface( rType
, static_cast< XIdlArray
* >( this ) ) );
48 return (aRet
.hasValue() ? aRet
: IdlClassImpl::queryInterface( rType
));
50 //__________________________________________________________________________________________________
51 void ArrayIdlClassImpl::acquire() throw()
53 IdlClassImpl::acquire();
55 //__________________________________________________________________________________________________
56 void ArrayIdlClassImpl::release() throw()
58 IdlClassImpl::release();
62 //__________________________________________________________________________________________________
63 Sequence
< Type
> ArrayIdlClassImpl::getTypes()
64 throw (::com::sun::star::uno::RuntimeException
)
66 static OTypeCollection
* s_pTypes
= 0;
69 MutexGuard
aGuard( getMutexAccess() );
72 static OTypeCollection
s_aTypes(
73 ::getCppuType( (const Reference
< XIdlArray
> *)0 ),
74 IdlClassImpl::getTypes() );
78 return s_pTypes
->getTypes();
80 //__________________________________________________________________________________________________
81 Sequence
< sal_Int8
> ArrayIdlClassImpl::getImplementationId()
82 throw (::com::sun::star::uno::RuntimeException
)
84 static OImplementationId
* s_pId
= 0;
87 MutexGuard
aGuard( getMutexAccess() );
90 static OImplementationId s_aId
;
94 return s_pId
->getImplementationId();
98 //__________________________________________________________________________________________________
99 void ArrayIdlClassImpl::realloc( Any
& rArray
, sal_Int32 nLen
)
100 throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
)
102 TypeClass eTC
= rArray
.getValueTypeClass();
103 if (eTC
!= TypeClass_SEQUENCE
&& eTC
!= TypeClass_ARRAY
)
105 throw IllegalArgumentException(
106 OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ),
107 (XWeak
*)(OWeakObject
*)this, 0 );
111 throw IllegalArgumentException(
112 OUString( RTL_CONSTASCII_USTRINGPARAM("illegal length given!") ),
113 (XWeak
*)(OWeakObject
*)this, 1 );
116 uno_Sequence
** ppSeq
= (uno_Sequence
**)rArray
.getValue();
117 uno_sequence_realloc( ppSeq
, (typelib_TypeDescription
*)getTypeDescr(),
119 reinterpret_cast< uno_AcquireFunc
>(cpp_acquire
),
120 reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
121 rArray
.pData
= ppSeq
;
123 //__________________________________________________________________________________________________
124 sal_Int32
ArrayIdlClassImpl::getLen( const Any
& rArray
)
125 throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::uno::RuntimeException
)
127 TypeClass eTC
= rArray
.getValueTypeClass();
128 if (eTC
!= TypeClass_SEQUENCE
&& eTC
!= TypeClass_ARRAY
)
130 throw IllegalArgumentException(
131 OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ),
132 (XWeak
*)(OWeakObject
*)this, 0 );
135 return (*(uno_Sequence
**)rArray
.getValue())->nElements
;
137 //__________________________________________________________________________________________________
138 Any
ArrayIdlClassImpl::get( const Any
& rArray
, sal_Int32 nIndex
)
139 throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::lang::ArrayIndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
)
141 TypeClass eTC
= rArray
.getValueTypeClass();
142 if (eTC
!= TypeClass_SEQUENCE
&& eTC
!= TypeClass_ARRAY
)
144 throw IllegalArgumentException(
145 OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ),
146 (XWeak
*)(OWeakObject
*)this, 0 );
149 uno_Sequence
* pSeq
= *(uno_Sequence
**)rArray
.getValue();
150 if (pSeq
->nElements
<= nIndex
)
152 throw ArrayIndexOutOfBoundsException(
153 OUString( RTL_CONSTASCII_USTRINGPARAM("illegal index given!") ),
154 (XWeak
*)(OWeakObject
*)this );
158 typelib_TypeDescription
* pElemTypeDescr
= 0;
159 TYPELIB_DANGER_GET( &pElemTypeDescr
, getTypeDescr()->pType
);
160 uno_any_destruct( &aRet
, reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
161 uno_any_construct( &aRet
, &pSeq
->elements
[nIndex
* pElemTypeDescr
->nSize
],
163 reinterpret_cast< uno_AcquireFunc
>(cpp_acquire
) );
164 TYPELIB_DANGER_RELEASE( pElemTypeDescr
);
168 //__________________________________________________________________________________________________
169 void ArrayIdlClassImpl::set( Any
& rArray
, sal_Int32 nIndex
, const Any
& rNewValue
)
170 throw(::com::sun::star::lang::IllegalArgumentException
, ::com::sun::star::lang::ArrayIndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
)
172 TypeClass eTC
= rArray
.getValueTypeClass();
173 if (eTC
!= TypeClass_SEQUENCE
&& eTC
!= TypeClass_ARRAY
)
175 throw IllegalArgumentException(
176 OUString( RTL_CONSTASCII_USTRINGPARAM("no sequence given!") ),
177 (XWeak
*)(OWeakObject
*)this, 0 );
180 uno_Sequence
* pSeq
= *(uno_Sequence
**)rArray
.getValue();
181 if (pSeq
->nElements
<= nIndex
)
183 throw ArrayIndexOutOfBoundsException(
184 OUString( RTL_CONSTASCII_USTRINGPARAM("illegal index given!") ),
185 (XWeak
*)(OWeakObject
*)this );
188 uno_Sequence
** ppSeq
= (uno_Sequence
**)rArray
.getValue();
189 uno_sequence_reference2One(
190 ppSeq
, (typelib_TypeDescription
*)getTypeDescr(),
191 reinterpret_cast< uno_AcquireFunc
>(cpp_acquire
),
192 reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
193 rArray
.pData
= ppSeq
;
196 typelib_TypeDescription
* pElemTypeDescr
= 0;
197 TYPELIB_DANGER_GET( &pElemTypeDescr
, getTypeDescr()->pType
);
199 if (! coerce_assign( &pSeq
->elements
[nIndex
* pElemTypeDescr
->nSize
],
200 pElemTypeDescr
, rNewValue
, getReflection() ))
202 TYPELIB_DANGER_RELEASE( pElemTypeDescr
);
203 throw IllegalArgumentException(
204 OUString( RTL_CONSTASCII_USTRINGPARAM("sequence element is not assignable by given value!") ),
205 (XWeak
*)(OWeakObject
*)this, 2 );
207 TYPELIB_DANGER_RELEASE( pElemTypeDescr
);
211 //__________________________________________________________________________________________________
212 sal_Bool
ArrayIdlClassImpl::isAssignableFrom( const Reference
< XIdlClass
> & xType
)
213 throw(::com::sun::star::uno::RuntimeException
)
215 return (xType
.is() &&
217 (xType
->getTypeClass() == getTypeClass() && // must be sequence|array
218 getComponentType()->isAssignableFrom( xType
->getComponentType() ))));
220 //__________________________________________________________________________________________________
221 Reference
< XIdlClass
> ArrayIdlClassImpl::getComponentType()
222 throw(::com::sun::star::uno::RuntimeException
)
224 return getReflection()->forType( getTypeDescr()->pType
);
226 //__________________________________________________________________________________________________
227 Reference
< XIdlArray
> ArrayIdlClassImpl::getArray()
228 throw(::com::sun::star::uno::RuntimeException
)