bump product version to 4.2.0.1
[LibreOffice.git] / include / com / sun / star / uno / Sequence.hxx
blob7f0a78df56ce03081115142b2e9b6c625b6f86b1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_COM_SUN_STAR_UNO_SEQUENCE_HXX
20 #define INCLUDED_COM_SUN_STAR_UNO_SEQUENCE_HXX
22 #include <sal/config.h>
24 #include <cassert>
26 #include <osl/interlck.h>
27 #include <com/sun/star/uno/Sequence.h>
28 #include <typelib/typedescription.h>
29 #include <uno/data.h>
30 #include <com/sun/star/uno/genfunc.hxx>
31 #include <cppu/unotype.hxx>
33 namespace com
35 namespace sun
37 namespace star
39 namespace uno
42 /// @cond INTERNAL
43 template< class E >
44 typelib_TypeDescriptionReference * Sequence< E >::s_pType = 0;
45 /// @endcond
47 template< class E >
48 inline Sequence< E >::Sequence() SAL_THROW(())
50 const Type & rType = ::cppu::getTypeFavourUnsigned( this );
51 ::uno_type_sequence_construct(
52 &_pSequence, rType.getTypeLibType(),
53 0, 0, (uno_AcquireFunc)cpp_acquire );
54 // no bad_alloc, because empty sequence is statically allocated in cppu
57 template< class E >
58 inline Sequence< E >::Sequence( const Sequence< E > & rSeq ) SAL_THROW(())
60 osl_atomic_increment( &rSeq._pSequence->nRefCount );
61 _pSequence = rSeq._pSequence;
64 template< class E >
65 inline Sequence< E >::Sequence(
66 uno_Sequence * pSequence, __sal_NoAcquire ) SAL_THROW(())
67 : _pSequence( pSequence )
71 template< class E >
72 inline Sequence< E >::Sequence( const E * pElements, sal_Int32 len )
74 const Type & rType = ::cppu::getTypeFavourUnsigned( this );
75 sal_Bool success =
76 ::uno_type_sequence_construct(
77 &_pSequence, rType.getTypeLibType(),
78 const_cast< E * >( pElements ), len, (uno_AcquireFunc)cpp_acquire );
79 if (! success)
80 throw ::std::bad_alloc();
83 template< class E >
84 inline Sequence< E >::Sequence( sal_Int32 len )
86 const Type & rType = ::cppu::getTypeFavourUnsigned( this );
87 sal_Bool success =
88 ::uno_type_sequence_construct(
89 &_pSequence, rType.getTypeLibType(),
90 0, len, (uno_AcquireFunc)cpp_acquire );
91 if (! success)
92 throw ::std::bad_alloc();
95 template< class E >
96 inline Sequence< E >::~Sequence() SAL_THROW(())
98 const Type & rType = ::cppu::getTypeFavourUnsigned( this );
99 ::uno_type_destructData(
100 this, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release );
103 template< class E >
104 inline Sequence< E > & Sequence< E >::operator = ( const Sequence< E > & rSeq ) SAL_THROW(())
106 const Type & rType = ::cppu::getTypeFavourUnsigned( this );
107 ::uno_type_sequence_assign(
108 &_pSequence, rSeq._pSequence, rType.getTypeLibType(), (uno_ReleaseFunc)cpp_release );
109 return *this;
112 template< class E >
113 inline sal_Bool Sequence< E >::operator == ( const Sequence< E > & rSeq ) const
114 SAL_THROW(())
116 if (_pSequence == rSeq._pSequence)
117 return sal_True;
118 const Type & rType = ::cppu::getTypeFavourUnsigned( this );
119 return ::uno_type_equalData(
120 const_cast< Sequence< E > * >( this ), rType.getTypeLibType(),
121 const_cast< Sequence< E > * >( &rSeq ), rType.getTypeLibType(),
122 (uno_QueryInterfaceFunc)cpp_queryInterface,
123 (uno_ReleaseFunc)cpp_release );
126 template< class E >
127 inline sal_Bool Sequence< E >::operator != ( const Sequence< E > & rSeq ) const
128 SAL_THROW(())
130 return (! operator == ( rSeq ));
133 template< class E >
134 inline E * Sequence< E >::getArray()
136 const Type & rType = ::cppu::getTypeFavourUnsigned( this );
137 sal_Bool success =
138 ::uno_type_sequence_reference2One(
139 &_pSequence, rType.getTypeLibType(),
140 (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
141 if (! success)
142 throw ::std::bad_alloc();
143 return reinterpret_cast< E * >( _pSequence->elements );
146 template<class E> E * Sequence<E>::begin() { return getArray(); }
148 template<class E> E const * Sequence<E>::begin() const
149 { return getConstArray(); }
151 template<class E> E * Sequence<E>::end() { return begin() + getLength(); }
153 template<class E> E const * Sequence<E>::end() const
154 { return begin() + getLength(); }
156 template< class E >
157 inline E & Sequence< E >::operator [] ( sal_Int32 nIndex )
159 assert( nIndex >= 0 && nIndex < getLength() );
160 return getArray()[ nIndex ];
163 template< class E >
164 inline const E & Sequence< E >::operator [] ( sal_Int32 nIndex ) const
165 SAL_THROW(())
167 assert( nIndex >= 0 && nIndex < getLength() );
168 return reinterpret_cast< const E * >( _pSequence->elements )[ nIndex ];
171 template< class E >
172 inline void Sequence< E >::realloc( sal_Int32 nSize )
174 const Type & rType = ::cppu::getTypeFavourUnsigned( this );
175 sal_Bool success =
176 ::uno_type_sequence_realloc(
177 &_pSequence, rType.getTypeLibType(), nSize,
178 (uno_AcquireFunc)cpp_acquire, (uno_ReleaseFunc)cpp_release );
179 if (!success)
180 throw ::std::bad_alloc();
183 inline ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL toUnoSequence(
184 const ::rtl::ByteSequence & rByteSequence ) SAL_THROW(())
186 return ::com::sun::star::uno::Sequence< sal_Int8 >(
187 * reinterpret_cast< const ::com::sun::star::uno::Sequence< sal_Int8 > * >( &rByteSequence ) );
195 namespace cppu {
197 template< typename T > inline ::com::sun::star::uno::Type const &
198 getTypeFavourUnsigned(
199 SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *)
201 if (::com::sun::star::uno::Sequence< T >::s_pType == 0) {
202 ::typelib_static_sequence_type_init(
203 &::com::sun::star::uno::Sequence< T >::s_pType,
204 (::cppu::getTypeFavourUnsigned(
205 static_cast<
206 typename ::com::sun::star::uno::Sequence< T >::ElementType * >(
207 0)).
208 getTypeLibType()));
210 return detail::getTypeFromTypeDescriptionReference(
211 &::com::sun::star::uno::Sequence< T >::s_pType);
214 template< typename T > inline ::com::sun::star::uno::Type const &
215 getTypeFavourChar(
216 SAL_UNUSED_PARAMETER ::com::sun::star::uno::Sequence< T > const *)
218 //TODO On certain platforms with weak memory models, the following code can
219 // result in some threads observing that td points to garbage:
220 static typelib_TypeDescriptionReference * td = 0;
221 if (td == 0) {
222 ::typelib_static_sequence_type_init(
223 &td,
224 (::cppu::getTypeFavourChar(
225 static_cast<
226 typename ::com::sun::star::uno::Sequence< T >::ElementType * >(
227 0)).
228 getTypeLibType()));
230 return detail::getTypeFromTypeDescriptionReference(&td);
235 // generic sequence template
236 template< class E >
237 inline const ::com::sun::star::uno::Type &
238 SAL_CALL getCppuType(
239 SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Sequence< E > * )
240 SAL_THROW(())
242 return ::cppu::getTypeFavourUnsigned(
243 static_cast< ::com::sun::star::uno::Sequence< E > * >(0));
246 // generic sequence template for given element type (e.g. C++ arrays)
247 template< class E >
248 inline const ::com::sun::star::uno::Type &
249 SAL_CALL getCppuSequenceType( const ::com::sun::star::uno::Type & rElementType )
250 SAL_THROW(())
252 if (! ::com::sun::star::uno::Sequence< E >::s_pType)
254 ::typelib_static_sequence_type_init(
255 & ::com::sun::star::uno::Sequence< E >::s_pType,
256 rElementType.getTypeLibType() );
258 return * reinterpret_cast< const ::com::sun::star::uno::Type * >(
259 & ::com::sun::star::uno::Sequence< E >::s_pType );
262 #if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))
263 static typelib_TypeDescriptionReference * s_pType_com_sun_star_uno_Sequence_Char = 0;
264 #endif
266 // char sequence
267 inline const ::com::sun::star::uno::Type &
268 SAL_CALL getCharSequenceCppuType() SAL_THROW(())
270 #if !( defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500))
271 static typelib_TypeDescriptionReference * s_pType_com_sun_star_uno_Sequence_Char = 0;
272 #endif
273 if (! s_pType_com_sun_star_uno_Sequence_Char)
275 const ::com::sun::star::uno::Type & rElementType = ::getCharCppuType();
276 ::typelib_static_sequence_type_init(
277 & s_pType_com_sun_star_uno_Sequence_Char,
278 rElementType.getTypeLibType() );
280 return * reinterpret_cast< const ::com::sun::star::uno::Type * >(
281 & s_pType_com_sun_star_uno_Sequence_Char );
284 #endif
286 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */