Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <typelib/typedescription.h>
21 : #include <uno/data.h>
22 : #include <cppuhelper/queryinterface.hxx>
23 :
24 : #include "base.hxx"
25 :
26 : using namespace css::lang;
27 : using namespace css::reflection;
28 : using namespace css::uno;
29 :
30 : namespace stoc_corefl
31 : {
32 :
33 : // XInterface
34 :
35 0 : Any ArrayIdlClassImpl::queryInterface( const Type & rType )
36 : throw(css::uno::RuntimeException, std::exception)
37 : {
38 0 : Any aRet( ::cppu::queryInterface( rType, static_cast< XIdlArray * >( this ) ) );
39 0 : return (aRet.hasValue() ? aRet : IdlClassImpl::queryInterface( rType ));
40 : }
41 :
42 19802 : void ArrayIdlClassImpl::acquire() throw()
43 : {
44 19802 : IdlClassImpl::acquire();
45 19802 : }
46 :
47 19460 : void ArrayIdlClassImpl::release() throw()
48 : {
49 19460 : IdlClassImpl::release();
50 19460 : }
51 :
52 : // XTypeProvider
53 :
54 0 : Sequence< Type > ArrayIdlClassImpl::getTypes()
55 : throw (css::uno::RuntimeException, std::exception)
56 : {
57 : static ::cppu::OTypeCollection * s_pTypes = 0;
58 0 : if (! s_pTypes)
59 : {
60 0 : ::osl::MutexGuard aGuard( getMutexAccess() );
61 0 : if (! s_pTypes)
62 : {
63 : static ::cppu::OTypeCollection s_aTypes(
64 0 : cppu::UnoType<XIdlArray>::get(),
65 0 : IdlClassImpl::getTypes() );
66 0 : s_pTypes = &s_aTypes;
67 0 : }
68 : }
69 0 : return s_pTypes->getTypes();
70 : }
71 :
72 0 : Sequence< sal_Int8 > ArrayIdlClassImpl::getImplementationId()
73 : throw (css::uno::RuntimeException, std::exception)
74 : {
75 0 : return css::uno::Sequence<sal_Int8>();
76 : }
77 :
78 : // XIdlArray
79 :
80 45 : void ArrayIdlClassImpl::realloc( Any & rArray, sal_Int32 nLen )
81 : throw(css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
82 : {
83 45 : TypeClass eTC = rArray.getValueTypeClass();
84 45 : if (eTC != TypeClass_SEQUENCE)
85 : {
86 : throw IllegalArgumentException(
87 : "no sequence given!",
88 0 : static_cast<XWeak *>(static_cast<OWeakObject *>(this)), 0 );
89 : }
90 45 : if (nLen < 0)
91 : {
92 : throw IllegalArgumentException(
93 : "illegal length given!",
94 0 : static_cast<XWeak *>(static_cast<OWeakObject *>(this)), 1 );
95 : }
96 :
97 45 : uno_Sequence ** ppSeq = const_cast<uno_Sequence **>(static_cast<uno_Sequence * const *>(rArray.getValue()));
98 45 : uno_sequence_realloc( ppSeq, &getTypeDescr()->aBase,
99 : nLen,
100 : reinterpret_cast< uno_AcquireFunc >(cpp_acquire),
101 45 : reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
102 45 : rArray.pData = ppSeq;
103 45 : }
104 :
105 152 : sal_Int32 ArrayIdlClassImpl::getLen( const Any & rArray )
106 : throw(css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception)
107 : {
108 152 : TypeClass eTC = rArray.getValueTypeClass();
109 152 : if (eTC != TypeClass_SEQUENCE)
110 : {
111 : throw IllegalArgumentException(
112 : "no sequence given!",
113 0 : static_cast<XWeak *>(static_cast<OWeakObject *>(this)), 0 );
114 : }
115 :
116 152 : return (*static_cast<uno_Sequence * const *>(rArray.getValue()))->nElements;
117 : }
118 :
119 3541 : Any ArrayIdlClassImpl::get( const Any & rArray, sal_Int32 nIndex )
120 : throw(css::lang::IllegalArgumentException, css::lang::ArrayIndexOutOfBoundsException, css::uno::RuntimeException, std::exception)
121 : {
122 3541 : TypeClass eTC = rArray.getValueTypeClass();
123 3541 : if (eTC != TypeClass_SEQUENCE)
124 : {
125 : throw IllegalArgumentException(
126 : "no sequence given!",
127 0 : static_cast<XWeak *>(static_cast<OWeakObject *>(this)), 0 );
128 : }
129 :
130 3541 : uno_Sequence * pSeq = *static_cast<uno_Sequence * const *>(rArray.getValue());
131 3541 : if (pSeq->nElements <= nIndex)
132 : {
133 : throw ArrayIndexOutOfBoundsException(
134 : "illegal index given!",
135 0 : static_cast<XWeak *>(static_cast<OWeakObject *>(this)) );
136 : }
137 :
138 3541 : Any aRet;
139 3541 : typelib_TypeDescription * pElemTypeDescr = 0;
140 3541 : TYPELIB_DANGER_GET( &pElemTypeDescr, getTypeDescr()->pType );
141 3541 : uno_any_destruct( &aRet, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
142 3541 : uno_any_construct( &aRet, &pSeq->elements[nIndex * pElemTypeDescr->nSize],
143 : pElemTypeDescr,
144 7082 : reinterpret_cast< uno_AcquireFunc >(cpp_acquire) );
145 3541 : TYPELIB_DANGER_RELEASE( pElemTypeDescr );
146 3541 : return aRet;
147 : }
148 :
149 :
150 81 : void ArrayIdlClassImpl::set( Any & rArray, sal_Int32 nIndex, const Any & rNewValue )
151 : throw(css::lang::IllegalArgumentException, css::lang::ArrayIndexOutOfBoundsException, css::uno::RuntimeException, std::exception)
152 : {
153 81 : TypeClass eTC = rArray.getValueTypeClass();
154 81 : if (eTC != TypeClass_SEQUENCE)
155 : {
156 : throw IllegalArgumentException(
157 : "no sequence given!",
158 0 : static_cast<XWeak *>(static_cast<OWeakObject *>(this)), 0 );
159 : }
160 :
161 81 : uno_Sequence * pSeq = *static_cast<uno_Sequence * const *>(rArray.getValue());
162 81 : if (pSeq->nElements <= nIndex)
163 : {
164 : throw ArrayIndexOutOfBoundsException(
165 : "illegal index given!",
166 0 : static_cast<XWeak *>(static_cast<OWeakObject *>(this)) );
167 : }
168 :
169 81 : uno_Sequence ** ppSeq = const_cast<uno_Sequence **>(static_cast<uno_Sequence * const *>(rArray.getValue()));
170 : uno_sequence_reference2One(
171 81 : ppSeq, &getTypeDescr()->aBase,
172 : reinterpret_cast< uno_AcquireFunc >(cpp_acquire),
173 81 : reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
174 81 : rArray.pData = ppSeq;
175 81 : pSeq = *ppSeq;
176 :
177 81 : typelib_TypeDescription * pElemTypeDescr = 0;
178 81 : TYPELIB_DANGER_GET( &pElemTypeDescr, getTypeDescr()->pType );
179 :
180 162 : if (! coerce_assign( &pSeq->elements[nIndex * pElemTypeDescr->nSize],
181 162 : pElemTypeDescr, rNewValue, getReflection() ))
182 : {
183 0 : TYPELIB_DANGER_RELEASE( pElemTypeDescr );
184 : throw IllegalArgumentException(
185 : "sequence element is not assignable by given value!",
186 0 : static_cast<XWeak *>(static_cast<OWeakObject *>(this)), 2 );
187 : }
188 81 : TYPELIB_DANGER_RELEASE( pElemTypeDescr );
189 81 : }
190 :
191 : // ArrayIdlClassImpl
192 :
193 24 : sal_Bool ArrayIdlClassImpl::isAssignableFrom( const Reference< XIdlClass > & xType )
194 : throw(css::uno::RuntimeException, std::exception)
195 : {
196 48 : return (xType.is() &&
197 48 : (equals( xType ) ||
198 84 : (xType->getTypeClass() == getTypeClass() && // must be sequence|array
199 84 : getComponentType()->isAssignableFrom( xType->getComponentType() ))));
200 : }
201 :
202 40 : Reference< XIdlClass > ArrayIdlClassImpl::getComponentType()
203 : throw(css::uno::RuntimeException, std::exception)
204 : {
205 40 : return getReflection()->forType( getTypeDescr()->pType );
206 : }
207 :
208 197 : Reference< XIdlArray > ArrayIdlClassImpl::getArray()
209 : throw(css::uno::RuntimeException, std::exception)
210 : {
211 197 : return this;
212 : }
213 :
214 : }
215 :
216 :
217 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|