1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <typelib/typedescription.h>
22 #include <cppuhelper/queryinterface.hxx>
26 using namespace css::lang
;
27 using namespace css::reflection
;
28 using namespace css::uno
;
35 Any
ArrayIdlClassImpl::queryInterface( const Type
& rType
)
36 throw(css::uno::RuntimeException
, std::exception
)
38 Any
aRet( ::cppu::queryInterface( rType
, static_cast< XIdlArray
* >( this ) ) );
39 return (aRet
.hasValue() ? aRet
: IdlClassImpl::queryInterface( rType
));
42 void ArrayIdlClassImpl::acquire() throw()
44 IdlClassImpl::acquire();
47 void ArrayIdlClassImpl::release() throw()
49 IdlClassImpl::release();
54 Sequence
< Type
> ArrayIdlClassImpl::getTypes()
55 throw (css::uno::RuntimeException
, std::exception
)
57 static ::cppu::OTypeCollection
* s_pTypes
= 0;
60 ::osl::MutexGuard
aGuard( getMutexAccess() );
63 static ::cppu::OTypeCollection
s_aTypes(
64 cppu::UnoType
<XIdlArray
>::get(),
65 IdlClassImpl::getTypes() );
69 return s_pTypes
->getTypes();
72 Sequence
< sal_Int8
> ArrayIdlClassImpl::getImplementationId()
73 throw (css::uno::RuntimeException
, std::exception
)
75 return css::uno::Sequence
<sal_Int8
>();
80 void ArrayIdlClassImpl::realloc( Any
& rArray
, sal_Int32 nLen
)
81 throw(css::lang::IllegalArgumentException
, css::uno::RuntimeException
, std::exception
)
83 TypeClass eTC
= rArray
.getValueTypeClass();
84 if (eTC
!= TypeClass_SEQUENCE
)
86 throw IllegalArgumentException(
88 (XWeak
*)(OWeakObject
*)this, 0 );
92 throw IllegalArgumentException(
93 "illegal length given!",
94 (XWeak
*)(OWeakObject
*)this, 1 );
97 uno_Sequence
** ppSeq
= const_cast<uno_Sequence
**>(static_cast<uno_Sequence
* const *>(rArray
.getValue()));
98 uno_sequence_realloc( ppSeq
, &getTypeDescr()->aBase
,
100 reinterpret_cast< uno_AcquireFunc
>(cpp_acquire
),
101 reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
102 rArray
.pData
= ppSeq
;
105 sal_Int32
ArrayIdlClassImpl::getLen( const Any
& rArray
)
106 throw(css::lang::IllegalArgumentException
, css::uno::RuntimeException
, std::exception
)
108 TypeClass eTC
= rArray
.getValueTypeClass();
109 if (eTC
!= TypeClass_SEQUENCE
)
111 throw IllegalArgumentException(
112 "no sequence given!",
113 (XWeak
*)(OWeakObject
*)this, 0 );
116 return (*static_cast<uno_Sequence
* const *>(rArray
.getValue()))->nElements
;
119 Any
ArrayIdlClassImpl::get( const Any
& rArray
, sal_Int32 nIndex
)
120 throw(css::lang::IllegalArgumentException
, css::lang::ArrayIndexOutOfBoundsException
, css::uno::RuntimeException
, std::exception
)
122 TypeClass eTC
= rArray
.getValueTypeClass();
123 if (eTC
!= TypeClass_SEQUENCE
)
125 throw IllegalArgumentException(
126 "no sequence given!",
127 (XWeak
*)(OWeakObject
*)this, 0 );
130 uno_Sequence
* pSeq
= *static_cast<uno_Sequence
* const *>(rArray
.getValue());
131 if (pSeq
->nElements
<= nIndex
)
133 throw ArrayIndexOutOfBoundsException(
134 "illegal index given!",
135 (XWeak
*)(OWeakObject
*)this );
139 typelib_TypeDescription
* pElemTypeDescr
= 0;
140 TYPELIB_DANGER_GET( &pElemTypeDescr
, getTypeDescr()->pType
);
141 uno_any_destruct( &aRet
, reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
142 uno_any_construct( &aRet
, &pSeq
->elements
[nIndex
* pElemTypeDescr
->nSize
],
144 reinterpret_cast< uno_AcquireFunc
>(cpp_acquire
) );
145 TYPELIB_DANGER_RELEASE( pElemTypeDescr
);
150 void ArrayIdlClassImpl::set( Any
& rArray
, sal_Int32 nIndex
, const Any
& rNewValue
)
151 throw(css::lang::IllegalArgumentException
, css::lang::ArrayIndexOutOfBoundsException
, css::uno::RuntimeException
, std::exception
)
153 TypeClass eTC
= rArray
.getValueTypeClass();
154 if (eTC
!= TypeClass_SEQUENCE
)
156 throw IllegalArgumentException(
157 "no sequence given!",
158 (XWeak
*)(OWeakObject
*)this, 0 );
161 uno_Sequence
* pSeq
= *static_cast<uno_Sequence
* const *>(rArray
.getValue());
162 if (pSeq
->nElements
<= nIndex
)
164 throw ArrayIndexOutOfBoundsException(
165 "illegal index given!",
166 (XWeak
*)(OWeakObject
*)this );
169 uno_Sequence
** ppSeq
= const_cast<uno_Sequence
**>(static_cast<uno_Sequence
* const *>(rArray
.getValue()));
170 uno_sequence_reference2One(
171 ppSeq
, &getTypeDescr()->aBase
,
172 reinterpret_cast< uno_AcquireFunc
>(cpp_acquire
),
173 reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
174 rArray
.pData
= ppSeq
;
177 typelib_TypeDescription
* pElemTypeDescr
= 0;
178 TYPELIB_DANGER_GET( &pElemTypeDescr
, getTypeDescr()->pType
);
180 if (! coerce_assign( &pSeq
->elements
[nIndex
* pElemTypeDescr
->nSize
],
181 pElemTypeDescr
, rNewValue
, getReflection() ))
183 TYPELIB_DANGER_RELEASE( pElemTypeDescr
);
184 throw IllegalArgumentException(
185 "sequence element is not assignable by given value!",
186 (XWeak
*)(OWeakObject
*)this, 2 );
188 TYPELIB_DANGER_RELEASE( pElemTypeDescr
);
193 sal_Bool
ArrayIdlClassImpl::isAssignableFrom( const Reference
< XIdlClass
> & xType
)
194 throw(css::uno::RuntimeException
, std::exception
)
196 return (xType
.is() &&
198 (xType
->getTypeClass() == getTypeClass() && // must be sequence|array
199 getComponentType()->isAssignableFrom( xType
->getComponentType() ))));
202 Reference
< XIdlClass
> ArrayIdlClassImpl::getComponentType()
203 throw(css::uno::RuntimeException
, std::exception
)
205 return getReflection()->forType( getTypeDescr()->pType
);
208 Reference
< XIdlArray
> ArrayIdlClassImpl::getArray()
209 throw(css::uno::RuntimeException
, std::exception
)
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */