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