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  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org. If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 #ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_
29 #define _COM_SUN_STAR_UNO_SEQUENCE_HXX_
30 
31 #include "osl/diagnose.h"
32 #include "osl/interlck.h"
35 #include "uno/data.h"
37 #include "cppu/unotype.hxx"
38 
39 namespace com
40 {
41 namespace sun
42 {
43 namespace star
44 {
45 namespace uno
46 {
47 
49 template< class E >
50 typelib_TypeDescriptionReference * Sequence< E >::s_pType = 0;
52 
53 //______________________________________________________________________________
54 template< class E >
56 {
57  const Type & rType = ::cppu::getTypeFavourUnsigned( this );
59  &_pSequence, rType.getTypeLibType(),
61  // no bad_alloc, because empty sequence is statically allocated in cppu
62 }
63 
64 //______________________________________________________________________________
65 template< class E >
67 {
68  ::osl_incrementInterlockedCount( &rSeq._pSequence->nRefCount );
69  _pSequence = rSeq._pSequence;
70 }
71 
72 //______________________________________________________________________________
73 template< class E >
75  uno_Sequence * pSequence, __sal_NoAcquire ) SAL_THROW(())
76  : _pSequence( pSequence )
77 {
78 }
79 
80 //______________________________________________________________________________
81 template< class E >
82 inline Sequence< E >::Sequence( const E * pElements, sal_Int32 len )
83 {
84  const Type & rType = ::cppu::getTypeFavourUnsigned( this );
85 #if ! defined EXCEPTIONS_OFF
86  sal_Bool success =
87 #endif
89  &_pSequence, rType.getTypeLibType(),
90  const_cast< E * >( pElements ), len, (uno_AcquireFunc)cpp_acquire );
91 #if ! defined EXCEPTIONS_OFF
92  if (! success)
93  throw ::std::bad_alloc();
94 #endif
95 }
96 
97 //______________________________________________________________________________
98 template< class E >
99 inline Sequence< E >::Sequence( sal_Int32 len )
100 {
101  const Type & rType = ::cppu::getTypeFavourUnsigned( this );
102 #if ! defined EXCEPTIONS_OFF
103  sal_Bool success =
104 #endif
106  &_pSequence, rType.getTypeLibType(),
107  0, len, (uno_AcquireFunc)cpp_acquire );
108 #if ! defined EXCEPTIONS_OFF
109  if (! success)
110  throw ::std::bad_alloc();
111 #endif
112 }
113 
114 //______________________________________________________________________________
115 template< class E >
117 {
118  const Type & rType = ::cppu::getTypeFavourUnsigned( this );
120  this, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release );
121 }
122 
123 //______________________________________________________________________________
124 template< class E >
126 {
127  const Type & rType = ::cppu::getTypeFavourUnsigned( this );
129  &_pSequence, rSeq._pSequence, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release );
130  return *this;
131 }
132 
133 //______________________________________________________________________________
134 template< class E >
136  SAL_THROW(())
137 {
138  if (_pSequence == rSeq._pSequence)
139  return sal_True;
140  const Type & rType = ::cppu::getTypeFavourUnsigned( this );
142  const_cast< Sequence< E > * >( this ), rType.getTypeLibType(),
143  const_cast< Sequence< E > * >( &rSeq ), rType.getTypeLibType(),
146 }
147 
148 //______________________________________________________________________________
149 template< class E >
151  SAL_THROW(())
152 {
153  return (! operator == ( rSeq ));
154 }
155 
156 //______________________________________________________________________________
157 template< class E >
159 {
160  const Type & rType = ::cppu::getTypeFavourUnsigned( this );
161 #if ! defined EXCEPTIONS_OFF
162  sal_Bool success =
163 #endif
165  &_pSequence, rType.getTypeLibType(),
167 #if ! defined EXCEPTIONS_OFF
168  if (! success)
169  throw ::std::bad_alloc();
170 #endif
171  return reinterpret_cast< E * >( _pSequence->elements );
172 }
173 
174 //______________________________________________________________________________
175 template< class E >
176 inline E & Sequence< E >::operator [] ( sal_Int32 nIndex )
177 {
178  OSL_ENSURE(
179  nIndex >= 0 && nIndex < getLength(),
180  "### illegal index of sequence!" );
181  return getArray()[ nIndex ];
182 }
183 
184 //______________________________________________________________________________
185 template< class E >
186 inline const E & Sequence< E >::operator [] ( sal_Int32 nIndex ) const
187  SAL_THROW(())
188 {
189  OSL_ENSURE(
190  nIndex >= 0 && nIndex < getLength(),
191  "### illegal index of sequence!" );
192  return reinterpret_cast< const E * >( _pSequence->elements )[ nIndex ];
193 }
194 
195 //______________________________________________________________________________
196 template< class E >
197 inline void Sequence< E >::realloc( sal_Int32 nSize )
198 {
199  const Type & rType = ::cppu::getTypeFavourUnsigned( this );
200 #if !defined EXCEPTIONS_OFF
201  sal_Bool success =
202 #endif
204  &_pSequence, rType.getTypeLibType(), nSize,
206 #if !defined EXCEPTIONS_OFF
207  if (!success)
208  throw ::std::bad_alloc();
209 #endif
210 }
211 
212 //------------------------------------------------------------------------------
213 inline ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL toUnoSequence(
214  const ::rtl::ByteSequence & rByteSequence ) SAL_THROW(())
215 {
216  return ::com::sun::star::uno::Sequence< sal_Int8 >(
217  * reinterpret_cast< const ::com::sun::star::uno::Sequence< sal_Int8 > * >( &rByteSequence ) );
218 }
219 
220 }
221 }
222 }
223 }
224 
225 namespace cppu {
226 
227 template< typename T > inline ::com::sun::star::uno::Type const &
229  SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *)
230 {
235  static_cast<
236  typename ::com::sun::star::uno::Sequence< T >::ElementType * >(
237  0)).
238  getTypeLibType()));
239  }
242 }
243 
244 template< typename T > inline ::com::sun::star::uno::Type const &
246  SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *)
247 {
248  //TODO On certain platforms with weak memory models, the following code can
249  // result in some threads observing that td points to garbage:
250  static typelib_TypeDescriptionReference * td = 0;
251  if (td == 0) {
253  &td,
255  static_cast<
256  typename ::com::sun::star::uno::Sequence< T >::ElementType * >(
257  0)).
258  getTypeLibType()));
259  }
261 }
262 
263 }
264 
265 // generic sequence template
266 template< class E >
267 inline const ::com::sun::star::uno::Type &
268 SAL_CALL getCppuType(
269  SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Sequence< E > * )
270  SAL_THROW(())
271 {
273  static_cast< ::com::sun::star::uno::Sequence< E > * >(0));
274 }
275 
276 // generic sequence template for given element type (e.g. C++ arrays)
277 template< class E >
278 inline const ::com::sun::star::uno::Type &
279 SAL_CALL getCppuSequenceType( const ::com::sun::star::uno::Type & rElementType )
280  SAL_THROW(())
281 {
283  {
286  rElementType.getTypeLibType() );
287  }
288  return * reinterpret_cast< const ::com::sun::star::uno::Type * >(
290 }
291 
292 #if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))
293 static typelib_TypeDescriptionReference * s_pType_com_sun_star_uno_Sequence_Char = 0;
294 #endif
295 
296 // char sequence
297 inline const ::com::sun::star::uno::Type &
299 {
300 #if !( defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))
301  static typelib_TypeDescriptionReference * s_pType_com_sun_star_uno_Sequence_Char = 0;
302 #endif
303  if (! s_pType_com_sun_star_uno_Sequence_Char)
304  {
305  const ::com::sun::star::uno::Type & rElementType = ::getCharCppuType();
307  & s_pType_com_sun_star_uno_Sequence_Char,
308  rElementType.getTypeLibType() );
309  }
310  return * reinterpret_cast< const ::com::sun::star::uno::Type * >(
311  & s_pType_com_sun_star_uno_Sequence_Char );
312 }
313 
314 #endif
315 
316 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */