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 : #ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_
20 : #define _COM_SUN_STAR_UNO_SEQUENCE_HXX_
21 :
22 : #include "osl/diagnose.h"
23 : #include "osl/interlck.h"
24 : #include "com/sun/star/uno/Sequence.h"
25 : #include "typelib/typedescription.h"
26 : #include "uno/data.h"
27 : #include "com/sun/star/uno/genfunc.hxx"
28 : #include "cppu/unotype.hxx"
29 :
30 : namespace com
31 : {
32 : namespace sun
33 : {
34 : namespace star
35 : {
36 : namespace uno
37 : {
38 :
39 : /// @cond INTERNAL
40 : template< class E >
41 : typelib_TypeDescriptionReference * Sequence< E >::s_pType = 0;
42 : /// @endcond
43 :
44 : //______________________________________________________________________________
45 : template< class E >
46 980907 : inline Sequence< E >::Sequence() SAL_THROW(())
47 : {
48 980907 : const Type & rType = ::cppu::getTypeFavourUnsigned( this );
49 : ::uno_type_sequence_construct(
50 : &_pSequence, rType.getTypeLibType(),
51 980907 : 0, 0, (uno_AcquireFunc)cpp_acquire );
52 : // no bad_alloc, because empty sequence is statically allocated in cppu
53 980907 : }
54 :
55 : //______________________________________________________________________________
56 : template< class E >
57 292761 : inline Sequence< E >::Sequence( const Sequence< E > & rSeq ) SAL_THROW(())
58 : {
59 292761 : osl_atomic_increment( &rSeq._pSequence->nRefCount );
60 292761 : _pSequence = rSeq._pSequence;
61 292761 : }
62 :
63 : //______________________________________________________________________________
64 : template< class E >
65 379 : inline Sequence< E >::Sequence(
66 : uno_Sequence * pSequence, __sal_NoAcquire ) SAL_THROW(())
67 379 : : _pSequence( pSequence )
68 : {
69 379 : }
70 :
71 : //______________________________________________________________________________
72 : template< class E >
73 160554 : inline Sequence< E >::Sequence( const E * pElements, sal_Int32 len )
74 : {
75 160554 : const Type & rType = ::cppu::getTypeFavourUnsigned( this );
76 : #if ! defined EXCEPTIONS_OFF
77 : sal_Bool success =
78 : #endif
79 : ::uno_type_sequence_construct(
80 : &_pSequence, rType.getTypeLibType(),
81 160554 : const_cast< E * >( pElements ), len, (uno_AcquireFunc)cpp_acquire );
82 : #if ! defined EXCEPTIONS_OFF
83 160554 : if (! success)
84 0 : throw ::std::bad_alloc();
85 : #endif
86 160554 : }
87 :
88 : //______________________________________________________________________________
89 : template< class E >
90 364046 : inline Sequence< E >::Sequence( sal_Int32 len )
91 : {
92 364046 : const Type & rType = ::cppu::getTypeFavourUnsigned( this );
93 : #if ! defined EXCEPTIONS_OFF
94 : sal_Bool success =
95 : #endif
96 : ::uno_type_sequence_construct(
97 : &_pSequence, rType.getTypeLibType(),
98 364046 : 0, len, (uno_AcquireFunc)cpp_acquire );
99 : #if ! defined EXCEPTIONS_OFF
100 364046 : if (! success)
101 0 : throw ::std::bad_alloc();
102 : #endif
103 364046 : }
104 :
105 : //______________________________________________________________________________
106 : template< class E >
107 1771644 : inline Sequence< E >::~Sequence() SAL_THROW(())
108 : {
109 1771644 : const Type & rType = ::cppu::getTypeFavourUnsigned( this );
110 1771644 : ::uno_type_destructData(
111 : this, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release );
112 1771644 : }
113 :
114 : //______________________________________________________________________________
115 : template< class E >
116 228697 : inline Sequence< E > & Sequence< E >::operator = ( const Sequence< E > & rSeq ) SAL_THROW(())
117 : {
118 228697 : const Type & rType = ::cppu::getTypeFavourUnsigned( this );
119 228697 : ::uno_type_sequence_assign(
120 : &_pSequence, rSeq._pSequence, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release );
121 228697 : return *this;
122 : }
123 :
124 : //______________________________________________________________________________
125 : template< class E >
126 19559 : inline sal_Bool Sequence< E >::operator == ( const Sequence< E > & rSeq ) const
127 : SAL_THROW(())
128 : {
129 19559 : if (_pSequence == rSeq._pSequence)
130 2053 : return sal_True;
131 17506 : const Type & rType = ::cppu::getTypeFavourUnsigned( this );
132 : return ::uno_type_equalData(
133 : const_cast< Sequence< E > * >( this ), rType.getTypeLibType(),
134 : const_cast< Sequence< E > * >( &rSeq ), rType.getTypeLibType(),
135 : (uno_QueryInterfaceFunc)cpp_queryInterface,
136 17506 : (uno_ReleaseFunc)cpp_release );
137 : }
138 :
139 : //______________________________________________________________________________
140 : template< class E >
141 0 : inline sal_Bool Sequence< E >::operator != ( const Sequence< E > & rSeq ) const
142 : SAL_THROW(())
143 : {
144 0 : return (! operator == ( rSeq ));
145 : }
146 :
147 : //______________________________________________________________________________
148 : template< class E >
149 4662232 : inline E * Sequence< E >::getArray()
150 : {
151 4662232 : const Type & rType = ::cppu::getTypeFavourUnsigned( this );
152 : #if ! defined EXCEPTIONS_OFF
153 : sal_Bool success =
154 : #endif
155 : ::uno_type_sequence_reference2One(
156 : &_pSequence, rType.getTypeLibType(),
157 4662232 : (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
158 : #if ! defined EXCEPTIONS_OFF
159 4662232 : if (! success)
160 0 : throw ::std::bad_alloc();
161 : #endif
162 4662232 : return reinterpret_cast< E * >( _pSequence->elements );
163 : }
164 :
165 : //______________________________________________________________________________
166 : template< class E >
167 4205077 : inline E & Sequence< E >::operator [] ( sal_Int32 nIndex )
168 : {
169 : OSL_ENSURE(
170 : nIndex >= 0 && nIndex < getLength(),
171 : "### illegal index of sequence!" );
172 4205077 : return getArray()[ nIndex ];
173 : }
174 :
175 : //______________________________________________________________________________
176 : template< class E >
177 765273 : inline const E & Sequence< E >::operator [] ( sal_Int32 nIndex ) const
178 : SAL_THROW(())
179 : {
180 : OSL_ENSURE(
181 : nIndex >= 0 && nIndex < getLength(),
182 : "### illegal index of sequence!" );
183 765273 : return reinterpret_cast< const E * >( _pSequence->elements )[ nIndex ];
184 : }
185 :
186 : //______________________________________________________________________________
187 : template< class E >
188 548553 : inline void Sequence< E >::realloc( sal_Int32 nSize )
189 : {
190 548553 : const Type & rType = ::cppu::getTypeFavourUnsigned( this );
191 : #if !defined EXCEPTIONS_OFF
192 : sal_Bool success =
193 : #endif
194 : ::uno_type_sequence_realloc(
195 : &_pSequence, rType.getTypeLibType(), nSize,
196 548553 : (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
197 : #if !defined EXCEPTIONS_OFF
198 548553 : if (!success)
199 0 : throw ::std::bad_alloc();
200 : #endif
201 548553 : }
202 :
203 : //------------------------------------------------------------------------------
204 45804 : inline ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL toUnoSequence(
205 : const ::rtl::ByteSequence & rByteSequence ) SAL_THROW(())
206 : {
207 : return ::com::sun::star::uno::Sequence< sal_Int8 >(
208 45804 : * reinterpret_cast< const ::com::sun::star::uno::Sequence< sal_Int8 > * >( &rByteSequence ) );
209 : }
210 :
211 : }
212 : }
213 : }
214 : }
215 :
216 : namespace cppu {
217 :
218 : template< typename T > inline ::com::sun::star::uno::Type const &
219 8944992 : getTypeFavourUnsigned(
220 : SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *)
221 : {
222 8944992 : if (::com::sun::star::uno::Sequence< T >::s_pType == 0) {
223 5622 : ::typelib_static_sequence_type_init(
224 : &::com::sun::star::uno::Sequence< T >::s_pType,
225 : (::cppu::getTypeFavourUnsigned(
226 : static_cast<
227 : typename ::com::sun::star::uno::Sequence< T >::ElementType * >(
228 : 0)).
229 : getTypeLibType()));
230 : }
231 : return detail::getTypeFromTypeDescriptionReference(
232 8944992 : &::com::sun::star::uno::Sequence< T >::s_pType);
233 : }
234 :
235 : template< typename T > inline ::com::sun::star::uno::Type const &
236 45 : getTypeFavourChar(
237 : SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *)
238 : {
239 : //TODO On certain platforms with weak memory models, the following code can
240 : // result in some threads observing that td points to garbage:
241 : static typelib_TypeDescriptionReference * td = 0;
242 45 : if (td == 0) {
243 36 : ::typelib_static_sequence_type_init(
244 : &td,
245 : (::cppu::getTypeFavourChar(
246 : static_cast<
247 : typename ::com::sun::star::uno::Sequence< T >::ElementType * >(
248 : 0)).
249 : getTypeLibType()));
250 : }
251 45 : return detail::getTypeFromTypeDescriptionReference(&td);
252 : }
253 :
254 : }
255 :
256 : // generic sequence template
257 : template< class E >
258 : inline const ::com::sun::star::uno::Type &
259 29387 : SAL_CALL getCppuType(
260 : SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Sequence< E > * )
261 : SAL_THROW(())
262 : {
263 : return ::cppu::getTypeFavourUnsigned(
264 29387 : static_cast< ::com::sun::star::uno::Sequence< E > * >(0));
265 : }
266 :
267 : // generic sequence template for given element type (e.g. C++ arrays)
268 : template< class E >
269 : inline const ::com::sun::star::uno::Type &
270 : SAL_CALL getCppuSequenceType( const ::com::sun::star::uno::Type & rElementType )
271 : SAL_THROW(())
272 : {
273 : if (! ::com::sun::star::uno::Sequence< E >::s_pType)
274 : {
275 : ::typelib_static_sequence_type_init(
276 : & ::com::sun::star::uno::Sequence< E >::s_pType,
277 : rElementType.getTypeLibType() );
278 : }
279 : return * reinterpret_cast< const ::com::sun::star::uno::Type * >(
280 : & ::com::sun::star::uno::Sequence< E >::s_pType );
281 : }
282 :
283 : #if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))
284 : static typelib_TypeDescriptionReference * s_pType_com_sun_star_uno_Sequence_Char = 0;
285 : #endif
286 :
287 : // char sequence
288 : inline const ::com::sun::star::uno::Type &
289 : SAL_CALL getCharSequenceCppuType() SAL_THROW(())
290 : {
291 : #if !( defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))
292 : static typelib_TypeDescriptionReference * s_pType_com_sun_star_uno_Sequence_Char = 0;
293 : #endif
294 : if (! s_pType_com_sun_star_uno_Sequence_Char)
295 : {
296 : const ::com::sun::star::uno::Type & rElementType = ::getCharCppuType();
297 : ::typelib_static_sequence_type_init(
298 : & s_pType_com_sun_star_uno_Sequence_Char,
299 : rElementType.getTypeLibType() );
300 : }
301 : return * reinterpret_cast< const ::com::sun::star::uno::Type * >(
302 : & s_pType_com_sun_star_uno_Sequence_Char );
303 : }
304 :
305 : #endif
306 :
307 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|