bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / com / sun / star / uno / Sequence.h
blobc6cb36cc71ff6f523712d527655685e0d0f3489a
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_H
20 #define INCLUDED_COM_SUN_STAR_UNO_SEQUENCE_H
22 #include "typelib/typedescription.h"
23 #include "uno/sequence2.h"
24 #include "com/sun/star/uno/Type.h"
25 #include "rtl/alloc.h"
27 #include <new>
29 #if defined LIBO_INTERNAL_ONLY
30 #include <initializer_list>
31 #endif
33 namespace rtl
35 class ByteSequence;
38 namespace com
40 namespace sun
42 namespace star
44 namespace uno
47 /** Template C++ class representing an IDL sequence. Template argument is the
48 sequence element type. C++ Sequences are reference counted and shared,
49 so the sequence keeps a handle to its data. To keep value semantics,
50 copies are only generated if the sequence is to be modified (new handle).
52 @tparam E element type of sequence
54 template< class E >
55 class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI Sequence
57 /** sequence handle
59 uno_Sequence * _pSequence;
61 public:
62 /// @cond INTERNAL
64 // these are here to force memory de/allocation to sal lib.
65 static void * SAL_CALL operator new ( ::size_t nSize )
66 { return ::rtl_allocateMemory( nSize ); }
67 static void SAL_CALL operator delete ( void * pMem )
68 { ::rtl_freeMemory( pMem ); }
69 static void * SAL_CALL operator new ( ::size_t, void * pMem )
70 { return pMem; }
71 static void SAL_CALL operator delete ( void *, void * )
74 /** Static pointer to typelib type of sequence.
75 Don't use directly, call getCppuType().
77 static typelib_TypeDescriptionReference * s_pType;
79 /// @endcond
81 /** typedefs the element type of the sequence
83 typedef E ElementType;
85 /** Default constructor: Creates an empty sequence.
87 inline Sequence();
89 /** Copy constructor: Creates a copy of given sequence.
91 @param rSeq another sequence of same type
93 inline Sequence( const Sequence & rSeq );
95 /** Constructor: Takes over ownership of given sequence.
97 @param pSequence a sequence
98 @param dummy SAL_NO_ACQUIRE to force obvious distinction to other
99 constructors
101 inline Sequence( uno_Sequence * pSequence, __sal_NoAcquire dummy );
103 /** Constructor: Creates a copy of given elements.
105 @param pElements an array of elements
106 @param len length of array
108 inline Sequence( const E * pElements, sal_Int32 len );
110 /** Constructor: Creates a default constructed sequence of given length.
112 @param len initial sequence length
114 inline explicit Sequence( sal_Int32 len );
116 #if defined LIBO_INTERNAL_ONLY
117 /** Create a sequence with the given elements.
119 @param init an initializer_list
121 @since LibreOffice 5.0
123 inline Sequence(std::initializer_list<E> init);
124 #endif
126 /** Destructor: Releases sequence handle. Last handle will destruct
127 elements and free memory.
129 inline ~Sequence();
131 /** Assignment operator: Acquires given sequence handle and releases
132 previously set handle.
134 @param rSeq another sequence of same type
135 @return this sequence
137 inline Sequence & SAL_CALL operator = ( const Sequence & rSeq );
139 /** Gets length of the sequence.
141 @return length of sequence
143 sal_Int32 SAL_CALL getLength() const
144 { return _pSequence->nElements; }
146 /** Tests whether the sequence has elements, i.e. elements count is
147 greater than zero.
149 @return true, if elements count is greater than zero
151 bool SAL_CALL hasElements() const
152 { return (_pSequence->nElements > 0); }
154 /** Gets a pointer to elements array for reading.
155 If the sequence has a length of 0, then the returned pointer is
156 undefined.
158 @return pointer to elements array
160 const E * SAL_CALL getConstArray() const
161 { return reinterpret_cast< const E * >( _pSequence->elements ); }
163 /** Gets a pointer to elements array for reading and writing.
164 In general if the sequence has a handle acquired by other sequences
165 (reference count > 1), then a new sequence is created copy constructing
166 all elements to keep value semantics!
167 If the sequence has a length of 0, then the returned pointer is
168 undefined.
170 @return pointer to elements array
172 inline E * SAL_CALL getArray();
174 /** This function allows to use Sequence in standard algorightms, like std::find
175 and others.
177 @since LibreOffice 4.2
179 inline E * begin();
181 /** This function allows to use Sequence in standard algorightms, like std::find
182 and others.
184 @since LibreOffice 4.2
186 inline E const * begin() const;
188 /** This function allows to use Sequence in standard algorightms, like std::find
189 and others.
191 @since LibreOffice 4.2
193 inline E * end();
195 /** This function allows to use Sequence in standard algorightms, like std::find
196 and others.
198 @since LibreOffice 4.2
200 inline E const * end() const;
202 /** Non-const index operator: Obtains a reference to element indexed at
203 given position.
204 The implementation does not check for array bounds!
205 In general if the sequence has a handle acquired by other sequences
206 (reference count > 1), then a new sequence is created copy constructing
207 all elements to keep value semantics!
209 @param nIndex index
210 @return non-const C++ reference to element
212 inline E & SAL_CALL operator [] ( sal_Int32 nIndex );
214 /** Const index operator: Obtains a reference to element indexed at
215 given position. The implementation does not check for array bounds!
217 @param nIndex index
218 @return const C++ reference to element
220 inline const E & SAL_CALL operator [] ( sal_Int32 nIndex ) const;
222 /** Equality operator: Compares two sequences.
224 @param rSeq another sequence of same type (right side)
225 @return true if both sequences are equal, false otherwise
227 inline bool SAL_CALL operator == ( const Sequence & rSeq ) const;
229 /** Unequality operator: Compares two sequences.
231 @param rSeq another sequence of same type (right side)
232 @return false if both sequences are equal, true otherwise
234 inline bool SAL_CALL operator != ( const Sequence & rSeq ) const;
236 /** Reallocates sequence to new length.
237 If the new length is smaller than the former, then upper elements will
238 be destructed (and their memory freed). If the new length is greater
239 than the former, then upper (new) elements are default constructed.
240 If the sequence has a handle acquired by other sequences
241 (reference count > 1), then the remaining elements are copy constructed
242 to a new sequence handle to keep value semantics!
244 @param nSize new size of sequence
246 inline void SAL_CALL realloc( sal_Int32 nSize );
248 /** Provides UNacquired sequence handle.
250 @return UNacquired sequence handle
252 uno_Sequence * SAL_CALL get() const
253 { return _pSequence; }
256 // Find uses of illegal Sequence<bool> (instead of Sequence<sal_Bool>) during
257 // compilation:
258 template<> class Sequence<bool> {
259 Sequence(Sequence<bool> const &) SAL_DELETED_FUNCTION;
262 /** Creates a UNO byte sequence from a SAL byte sequence.
264 @param rByteSequence a byte sequence
265 @return a UNO byte sequence
267 inline ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL toUnoSequence(
268 const ::rtl::ByteSequence & rByteSequence );
275 /** Gets the meta type of IDL sequence.
277 There are cases (involving templates) where uses of getCppuType are known to
278 not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead.
280 The dummy parameter is just a typed pointer for function signature.
282 @tparam E element type of sequence
283 @return type of IDL sequence
285 @deprecated
286 Use cppu::UnoType instead.
288 template< class E > SAL_DEPRECATED("use cppu::UnoType")
289 inline const ::com::sun::star::uno::Type &
290 SAL_CALL getCppuType( const ::com::sun::star::uno::Sequence< E > * );
292 /** Gets the meta type of IDL sequence.
293 This function has been introduced, because one cannot get the (templated)
294 cppu type out of C++ array types.
296 @attention
297 the given element type must be the same as the template argument type!
298 @tparam E element type of sequence
299 @param rElementType element type of sequence
300 @return type of IDL sequence
302 @deprecated
303 Use cppu::UnoType instead.
305 template< class E > SAL_DEPRECATED("use cppu::UnoType")
306 inline const ::com::sun::star::uno::Type &
307 SAL_CALL getCppuSequenceType( const ::com::sun::star::uno::Type & rElementType );
309 /** Gets the meta type of IDL sequence< char >.
310 This function has been introduced due to ambiguities with unsigned short.
312 The dummy parameter is just a typed pointer for function signature.
314 @return type of IDL sequence< char >
316 @deprecated
317 Use cppu::UnoType instead.
319 SAL_DEPRECATED("use cppu::UnoType")
320 inline const ::com::sun::star::uno::Type &
321 SAL_CALL getCharSequenceCppuType();
323 #endif
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */