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
)
37 Any
aRet( ::cppu::queryInterface( rType
, static_cast< XIdlArray
* >( this ) ) );
38 return (aRet
.hasValue() ? aRet
: IdlClassImpl::queryInterface( rType
));
41 void ArrayIdlClassImpl::acquire() throw()
43 IdlClassImpl::acquire();
46 void ArrayIdlClassImpl::release() throw()
48 IdlClassImpl::release();
53 Sequence
< Type
> ArrayIdlClassImpl::getTypes()
55 static ::cppu::OTypeCollection
* s_pTypes
= nullptr;
58 ::osl::MutexGuard
aGuard( getMutexAccess() );
61 static ::cppu::OTypeCollection
s_aTypes(
62 cppu::UnoType
<XIdlArray
>::get(),
63 IdlClassImpl::getTypes() );
67 return s_pTypes
->getTypes();
70 Sequence
< sal_Int8
> ArrayIdlClassImpl::getImplementationId()
72 return css::uno::Sequence
<sal_Int8
>();
77 void ArrayIdlClassImpl::realloc( Any
& rArray
, sal_Int32 nLen
)
79 TypeClass eTC
= rArray
.getValueTypeClass();
80 if (eTC
!= TypeClass_SEQUENCE
)
82 throw IllegalArgumentException(
83 "expected sequence, but found " + rArray
.getValueType().getTypeName(),
84 static_cast<XWeak
*>(static_cast<OWeakObject
*>(this)), 0 );
88 throw IllegalArgumentException(
89 "negative length given!",
90 static_cast<XWeak
*>(static_cast<OWeakObject
*>(this)), 1 );
93 uno_Sequence
** ppSeq
= const_cast<uno_Sequence
**>(static_cast<uno_Sequence
* const *>(rArray
.getValue()));
94 uno_sequence_realloc( ppSeq
, &getTypeDescr()->aBase
,
96 reinterpret_cast< uno_AcquireFunc
>(cpp_acquire
),
97 reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
101 sal_Int32
ArrayIdlClassImpl::getLen( const Any
& rArray
)
103 TypeClass eTC
= rArray
.getValueTypeClass();
104 if (eTC
!= TypeClass_SEQUENCE
)
106 throw IllegalArgumentException(
107 "expected sequence, but found " + rArray
.getValueType().getTypeName(),
108 static_cast<XWeak
*>(static_cast<OWeakObject
*>(this)), 0 );
111 return (*static_cast<uno_Sequence
* const *>(rArray
.getValue()))->nElements
;
114 Any
ArrayIdlClassImpl::get( const Any
& rArray
, sal_Int32 nIndex
)
116 TypeClass eTC
= rArray
.getValueTypeClass();
117 if (eTC
!= TypeClass_SEQUENCE
)
119 throw IllegalArgumentException(
120 "expected sequence, but found " + rArray
.getValueType().getTypeName(),
121 static_cast<XWeak
*>(static_cast<OWeakObject
*>(this)), 0 );
124 uno_Sequence
* pSeq
= *static_cast<uno_Sequence
* const *>(rArray
.getValue());
125 if (pSeq
->nElements
<= nIndex
)
127 throw ArrayIndexOutOfBoundsException(
128 "illegal index given, index " + OUString::number(nIndex
) + " is < " + OUString::number(pSeq
->nElements
),
129 static_cast<XWeak
*>(static_cast<OWeakObject
*>(this)) );
133 typelib_TypeDescription
* pElemTypeDescr
= nullptr;
134 TYPELIB_DANGER_GET( &pElemTypeDescr
, getTypeDescr()->pType
);
135 uno_any_destruct( &aRet
, reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
136 uno_any_construct( &aRet
, &pSeq
->elements
[nIndex
* pElemTypeDescr
->nSize
],
138 reinterpret_cast< uno_AcquireFunc
>(cpp_acquire
) );
139 TYPELIB_DANGER_RELEASE( pElemTypeDescr
);
144 void ArrayIdlClassImpl::set( Any
& rArray
, sal_Int32 nIndex
, const Any
& rNewValue
)
146 TypeClass eTC
= rArray
.getValueTypeClass();
147 if (eTC
!= TypeClass_SEQUENCE
)
149 throw IllegalArgumentException(
150 "expected sequence, but found " + rArray
.getValueType().getTypeName(),
151 static_cast<XWeak
*>(static_cast<OWeakObject
*>(this)), 0 );
154 uno_Sequence
* pSeq
= *static_cast<uno_Sequence
* const *>(rArray
.getValue());
155 if (pSeq
->nElements
<= nIndex
)
157 throw ArrayIndexOutOfBoundsException(
158 "illegal index given, index " + OUString::number(nIndex
) + " is < " + OUString::number(pSeq
->nElements
),
159 static_cast<XWeak
*>(static_cast<OWeakObject
*>(this)) );
162 uno_Sequence
** ppSeq
= const_cast<uno_Sequence
**>(static_cast<uno_Sequence
* const *>(rArray
.getValue()));
163 uno_sequence_reference2One(
164 ppSeq
, &getTypeDescr()->aBase
,
165 reinterpret_cast< uno_AcquireFunc
>(cpp_acquire
),
166 reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
167 rArray
.pData
= ppSeq
;
170 typelib_TypeDescription
* pElemTypeDescr
= nullptr;
171 TYPELIB_DANGER_GET( &pElemTypeDescr
, getTypeDescr()->pType
);
173 if (! coerce_assign( &pSeq
->elements
[nIndex
* pElemTypeDescr
->nSize
],
174 pElemTypeDescr
, rNewValue
, getReflection() ))
176 TYPELIB_DANGER_RELEASE( pElemTypeDescr
);
177 throw IllegalArgumentException(
178 "sequence element is not assignable by given value!",
179 static_cast<XWeak
*>(static_cast<OWeakObject
*>(this)), 2 );
181 TYPELIB_DANGER_RELEASE( pElemTypeDescr
);
186 sal_Bool
ArrayIdlClassImpl::isAssignableFrom( const Reference
< XIdlClass
> & xType
)
188 return (xType
.is() &&
190 (xType
->getTypeClass() == getTypeClass() && // must be sequence|array
191 getComponentType()->isAssignableFrom( xType
->getComponentType() ))));
194 Reference
< XIdlClass
> ArrayIdlClassImpl::getComponentType()
196 return getReflection()->forType( getTypeDescr()->pType
);
199 Reference
< XIdlArray
> ArrayIdlClassImpl::getArray()
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */