My Project
UDK 3.2.7 C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Sequence.hxx
Go to the documentation of this file.
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"
26 #include "uno/data.h"
28 #include "cppu/unotype.hxx"
29 
30 namespace com
31 {
32 namespace sun
33 {
34 namespace star
35 {
36 namespace uno
37 {
38 
40 template< class E >
43 
44 //______________________________________________________________________________
45 template< class E >
47 {
48  const Type & rType = ::cppu::getTypeFavourUnsigned( this );
50  &_pSequence, rType.getTypeLibType(),
52  // no bad_alloc, because empty sequence is statically allocated in cppu
53 }
54 
55 //______________________________________________________________________________
56 template< class E >
58 {
59  osl_atomic_increment( &rSeq._pSequence->nRefCount );
60  _pSequence = rSeq._pSequence;
61 }
62 
63 //______________________________________________________________________________
64 template< class E >
66  uno_Sequence * pSequence, __sal_NoAcquire ) SAL_THROW(())
67  : _pSequence( pSequence )
68 {
69 }
70 
71 //______________________________________________________________________________
72 template< class E >
73 inline Sequence< E >::Sequence( const E * pElements, sal_Int32 len )
74 {
75  const Type & rType = ::cppu::getTypeFavourUnsigned( this );
76 #if ! defined EXCEPTIONS_OFF
77  sal_Bool success =
78 #endif
80  &_pSequence, rType.getTypeLibType(),
81  const_cast< E * >( pElements ), len, (uno_AcquireFunc)cpp_acquire );
82 #if ! defined EXCEPTIONS_OFF
83  if (! success)
84  throw ::std::bad_alloc();
85 #endif
86 }
87 
88 //______________________________________________________________________________
89 template< class E >
90 inline Sequence< E >::Sequence( sal_Int32 len )
91 {
92  const Type & rType = ::cppu::getTypeFavourUnsigned( this );
93 #if ! defined EXCEPTIONS_OFF
94  sal_Bool success =
95 #endif
97  &_pSequence, rType.getTypeLibType(),
98  0, len, (uno_AcquireFunc)cpp_acquire );
99 #if ! defined EXCEPTIONS_OFF
100  if (! success)
101  throw ::std::bad_alloc();
102 #endif
103 }
104 
105 //______________________________________________________________________________
106 template< class E >
108 {
109  const Type & rType = ::cppu::getTypeFavourUnsigned( this );
111  this, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release );
112 }
113 
114 //______________________________________________________________________________
115 template< class E >
117 {
118  const Type & rType = ::cppu::getTypeFavourUnsigned( this );
120  &_pSequence, rSeq._pSequence, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release );
121  return *this;
122 }
123 
124 //______________________________________________________________________________
125 template< class E >
127  SAL_THROW(())
128 {
129  if (_pSequence == rSeq._pSequence)
130  return sal_True;
131  const Type & rType = ::cppu::getTypeFavourUnsigned( this );
133  const_cast< Sequence< E > * >( this ), rType.getTypeLibType(),
134  const_cast< Sequence< E > * >( &rSeq ), rType.getTypeLibType(),
137 }
138 
139 //______________________________________________________________________________
140 template< class E >
142  SAL_THROW(())
143 {
144  return (! operator == ( rSeq ));
145 }
146 
147 //______________________________________________________________________________
148 template< class E >
150 {
151  const Type & rType = ::cppu::getTypeFavourUnsigned( this );
152 #if ! defined EXCEPTIONS_OFF
153  sal_Bool success =
154 #endif
156  &_pSequence, rType.getTypeLibType(),
158 #if ! defined EXCEPTIONS_OFF
159  if (! success)
160  throw ::std::bad_alloc();
161 #endif
162  return reinterpret_cast< E * >( _pSequence->elements );
163 }
164 
165 //______________________________________________________________________________
166 template< class E >
167 inline E & Sequence< E >::operator [] ( sal_Int32 nIndex )
168 {
169  OSL_ENSURE(
170  nIndex >= 0 && nIndex < getLength(),
171  "### illegal index of sequence!" );
172  return getArray()[ nIndex ];
173 }
174 
175 //______________________________________________________________________________
176 template< class E >
177 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  return reinterpret_cast< const E * >( _pSequence->elements )[ nIndex ];
184 }
185 
186 //______________________________________________________________________________
187 template< class E >
188 inline void Sequence< E >::realloc( sal_Int32 nSize )
189 {
190  const Type & rType = ::cppu::getTypeFavourUnsigned( this );
191 #if !defined EXCEPTIONS_OFF
192  sal_Bool success =
193 #endif
195  &_pSequence, rType.getTypeLibType(), nSize,
197 #if !defined EXCEPTIONS_OFF
198  if (!success)
199  throw ::std::bad_alloc();
200 #endif
201 }
202 
203 //------------------------------------------------------------------------------
204 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  * 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 &
220  SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *)
221 {
226  static_cast<
227  typename ::com::sun::star::uno::Sequence< T >::ElementType * >(
228  0)).
229  getTypeLibType()));
230  }
233 }
234 
235 template< typename T > inline ::com::sun::star::uno::Type const &
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  if (td == 0) {
244  &td,
246  static_cast<
247  typename ::com::sun::star::uno::Sequence< T >::ElementType * >(
248  0)).
249  getTypeLibType()));
250  }
252 }
253 
254 }
255 
256 // generic sequence template
257 template< class E >
258 inline const ::com::sun::star::uno::Type &
259 SAL_CALL getCppuType(
260  SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Sequence< E > * )
261  SAL_THROW(())
262 {
264  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 {
274  {
277  rElementType.getTypeLibType() );
278  }
279  return * reinterpret_cast< const ::com::sun::star::uno::Type * >(
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 &
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();
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: */