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 2244441 : inline Sequence< E >::Sequence() SAL_THROW(())
47 : {
48 2244441 : const Type & rType = ::cppu::getTypeFavourUnsigned( this );
49 : ::uno_type_sequence_construct(
50 : &_pSequence, rType.getTypeLibType(),
51 2244441 : 0, 0, (uno_AcquireFunc)cpp_acquire );
52 : // no bad_alloc, because empty sequence is statically allocated in cppu
53 2244441 : }
54 :
55 : //______________________________________________________________________________
56 : template< class E >
57 796304 : inline Sequence< E >::Sequence( const Sequence< E > & rSeq ) SAL_THROW(())
58 : {
59 796304 : osl_atomic_increment( &rSeq._pSequence->nRefCount );
60 796304 : _pSequence = rSeq._pSequence;
61 796304 : }
62 :
63 : //______________________________________________________________________________
64 : template< class E >
65 1125 : inline Sequence< E >::Sequence(
66 : uno_Sequence * pSequence, __sal_NoAcquire ) SAL_THROW(())
67 1125 : : _pSequence( pSequence )
68 : {
69 1125 : }
70 :
71 : //______________________________________________________________________________
72 : template< class E >
73 324345 : inline Sequence< E >::Sequence( const E * pElements, sal_Int32 len )
74 : {
75 324345 : 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 324345 : const_cast< E * >( pElements ), len, (uno_AcquireFunc)cpp_acquire );
82 : #if ! defined EXCEPTIONS_OFF
83 324345 : if (! success)
84 0 : throw ::std::bad_alloc();
85 : #endif
86 324345 : }
87 :
88 : //______________________________________________________________________________
89 : template< class E >
90 936309 : inline Sequence< E >::Sequence( sal_Int32 len )
91 : {
92 936309 : 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 936309 : 0, len, (uno_AcquireFunc)cpp_acquire );
99 : #if ! defined EXCEPTIONS_OFF
100 936309 : if (! success)
101 0 : throw ::std::bad_alloc();
102 : #endif
103 936309 : }
104 :
105 : //______________________________________________________________________________
106 : template< class E >
107 4231035 : inline Sequence< E >::~Sequence() SAL_THROW(())
108 : {
109 4231035 : const Type & rType = ::cppu::getTypeFavourUnsigned( this );
110 4231035 : ::uno_type_destructData(
111 : this, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release );
112 4231035 : }
113 :
114 : //______________________________________________________________________________
115 : template< class E >
116 535737 : inline Sequence< E > & Sequence< E >::operator = ( const Sequence< E > & rSeq ) SAL_THROW(())
117 : {
118 535737 : const Type & rType = ::cppu::getTypeFavourUnsigned( this );
119 535737 : ::uno_type_sequence_assign(
120 : &_pSequence, rSeq._pSequence, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release );
121 535737 : return *this;
122 : }
123 :
124 : //______________________________________________________________________________
125 : template< class E >
126 40642 : inline sal_Bool Sequence< E >::operator == ( const Sequence< E > & rSeq ) const
127 : SAL_THROW(())
128 : {
129 40642 : if (_pSequence == rSeq._pSequence)
130 5594 : return sal_True;
131 35048 : 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 35048 : (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 11060006 : inline E * Sequence< E >::getArray()
150 : {
151 11060006 : 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 11060006 : (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
158 : #if ! defined EXCEPTIONS_OFF
159 11060006 : if (! success)
160 0 : throw ::std::bad_alloc();
161 : #endif
162 11060006 : return reinterpret_cast< E * >( _pSequence->elements );
163 : }
164 :
165 : //______________________________________________________________________________
166 : template< class E >
167 9892365 : inline E & Sequence< E >::operator [] ( sal_Int32 nIndex )
168 : {
169 : OSL_ENSURE(
170 : nIndex >= 0 && nIndex < getLength(),
171 : "### illegal index of sequence!" );
172 9892365 : return getArray()[ nIndex ];
173 : }
174 :
175 : //______________________________________________________________________________
176 : template< class E >
177 1164248 : 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 1164248 : return reinterpret_cast< const E * >( _pSequence->elements )[ nIndex ];
184 : }
185 :
186 : //______________________________________________________________________________
187 : template< class E >
188 1089744 : inline void Sequence< E >::realloc( sal_Int32 nSize )
189 : {
190 1089744 : 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 1089744 : (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
197 : #if !defined EXCEPTIONS_OFF
198 1089744 : if (!success)
199 0 : throw ::std::bad_alloc();
200 : #endif
201 1089744 : }
202 :
203 : //------------------------------------------------------------------------------
204 91712 : 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 91712 : * 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 21014234 : getTypeFavourUnsigned(
220 : SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *)
221 : {
222 21014234 : if (::com::sun::star::uno::Sequence< T >::s_pType == 0) {
223 14285 : ::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 21014234 : &::com::sun::star::uno::Sequence< T >::s_pType);
233 : }
234 :
235 : template< typename T > inline ::com::sun::star::uno::Type const &
236 90 : 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 90 : if (td == 0) {
243 72 : ::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 90 : 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 64873 : SAL_CALL getCppuType(
260 : SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Sequence< E > * )
261 : SAL_THROW(())
262 : {
263 : return ::cppu::getTypeFavourUnsigned(
264 64873 : 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: */
|