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>
23 #include <cppuhelper/typeprovider.hxx>
27 using namespace css::lang
;
28 using namespace css::reflection
;
29 using namespace css::uno
;
36 void ArrayIdlClassImpl::realloc( Any
& rArray
, sal_Int32 nLen
)
38 TypeClass eTC
= rArray
.getValueTypeClass();
39 if (eTC
!= TypeClass_SEQUENCE
)
41 throw IllegalArgumentException(
42 "expected sequence, but found " + rArray
.getValueTypeName(),
47 throw IllegalArgumentException(
48 u
"negative length given!"_ustr
,
52 uno_Sequence
** ppSeq
= const_cast<uno_Sequence
**>(static_cast<uno_Sequence
* const *>(rArray
.getValue()));
53 uno_sequence_realloc( ppSeq
, &getTypeDescr()->aBase
,
55 reinterpret_cast< uno_AcquireFunc
>(cpp_acquire
),
56 reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
60 sal_Int32
ArrayIdlClassImpl::getLen( const Any
& rArray
)
62 TypeClass eTC
= rArray
.getValueTypeClass();
63 if (eTC
!= TypeClass_SEQUENCE
)
65 throw IllegalArgumentException(
66 "expected sequence, but found " + rArray
.getValueTypeName(),
70 return (*static_cast<uno_Sequence
* const *>(rArray
.getValue()))->nElements
;
73 Any
ArrayIdlClassImpl::get( const Any
& rArray
, sal_Int32 nIndex
)
75 TypeClass eTC
= rArray
.getValueTypeClass();
76 if (eTC
!= TypeClass_SEQUENCE
)
78 throw IllegalArgumentException(
79 "expected sequence, but found " + rArray
.getValueTypeName(),
83 uno_Sequence
* pSeq
= *static_cast<uno_Sequence
* const *>(rArray
.getValue());
84 if (pSeq
->nElements
<= nIndex
)
86 throw ArrayIndexOutOfBoundsException(
87 "illegal index given, index " + OUString::number(nIndex
) + " is < " + OUString::number(pSeq
->nElements
),
92 typelib_TypeDescription
* pElemTypeDescr
= nullptr;
93 TYPELIB_DANGER_GET( &pElemTypeDescr
, getTypeDescr()->pType
);
94 uno_any_destruct( &aRet
, reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
95 uno_any_construct( &aRet
, &pSeq
->elements
[nIndex
* pElemTypeDescr
->nSize
],
97 reinterpret_cast< uno_AcquireFunc
>(cpp_acquire
) );
98 TYPELIB_DANGER_RELEASE( pElemTypeDescr
);
103 void ArrayIdlClassImpl::set( Any
& rArray
, sal_Int32 nIndex
, const Any
& rNewValue
)
105 TypeClass eTC
= rArray
.getValueTypeClass();
106 if (eTC
!= TypeClass_SEQUENCE
)
108 throw IllegalArgumentException(
109 "expected sequence, but found " + rArray
.getValueTypeName(),
113 uno_Sequence
* pSeq
= *static_cast<uno_Sequence
* const *>(rArray
.getValue());
114 if (pSeq
->nElements
<= nIndex
)
116 throw ArrayIndexOutOfBoundsException(
117 "illegal index given, index " + OUString::number(nIndex
) + " is < " + OUString::number(pSeq
->nElements
),
121 uno_Sequence
** ppSeq
= const_cast<uno_Sequence
**>(static_cast<uno_Sequence
* const *>(rArray
.getValue()));
122 uno_sequence_reference2One(
123 ppSeq
, &getTypeDescr()->aBase
,
124 reinterpret_cast< uno_AcquireFunc
>(cpp_acquire
),
125 reinterpret_cast< uno_ReleaseFunc
>(cpp_release
) );
126 rArray
.pData
= ppSeq
;
129 typelib_TypeDescription
* pElemTypeDescr
= nullptr;
130 TYPELIB_DANGER_GET( &pElemTypeDescr
, getTypeDescr()->pType
);
132 if (! coerce_assign( &pSeq
->elements
[nIndex
* pElemTypeDescr
->nSize
],
133 pElemTypeDescr
, rNewValue
, getReflection() ))
135 TYPELIB_DANGER_RELEASE( pElemTypeDescr
);
136 throw IllegalArgumentException(
137 u
"sequence element is not assignable by given value!"_ustr
,
140 TYPELIB_DANGER_RELEASE( pElemTypeDescr
);
145 sal_Bool
ArrayIdlClassImpl::isAssignableFrom( const Reference
< XIdlClass
> & xType
)
147 return (xType
.is() &&
149 (xType
->getTypeClass() == getTypeClass() && // must be sequence|array
150 getComponentType()->isAssignableFrom( xType
->getComponentType() ))));
153 Reference
< XIdlClass
> ArrayIdlClassImpl::getComponentType()
155 return getReflection()->forType( getTypeDescr()->pType
);
158 Reference
< XIdlArray
> ArrayIdlClassImpl::getArray()
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */