bump product version to 4.2.0.1
[LibreOffice.git] / include / com / sun / star / uno / Sequence.h
blobfe5c16c0bbe77f084a58f1ce841143eb9c25101e
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 namespace rtl
31 class ByteSequence;
34 namespace com
36 namespace sun
38 namespace star
40 namespace uno
43 /** Template C++ class representing an IDL sequence. Template argument is the
44 sequence element type. C++ Sequences are reference counted and shared,
45 so the sequence keeps a handle to its data. To keep value semantics,
46 copies are only generated if the sequence is to be modified (new handle).
48 @tparam E element type of sequence
50 template< class E >
51 class SAL_WARN_UNUSED Sequence
53 /** sequence handle
55 uno_Sequence * _pSequence;
57 public:
58 /// @cond INTERNAL
60 // these are here to force memory de/allocation to sal lib.
61 inline static void * SAL_CALL operator new ( ::size_t nSize )
62 SAL_THROW(())
63 { return ::rtl_allocateMemory( nSize ); }
64 inline static void SAL_CALL operator delete ( void * pMem )
65 SAL_THROW(())
66 { ::rtl_freeMemory( pMem ); }
67 inline static void * SAL_CALL operator new ( ::size_t, void * pMem )
68 SAL_THROW(())
69 { return pMem; }
70 inline static void SAL_CALL operator delete ( void *, void * )
71 SAL_THROW(())
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() SAL_THROW(());
89 /** Copy constructor: Creates a copy of given sequence.
91 @param rSeq another sequence of same type
93 inline Sequence( const Sequence< E > & rSeq ) SAL_THROW(());
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 )
102 SAL_THROW(());
104 /** Constructor: Creates a copy of given elements.
106 @param pElements an array of elements
107 @param len length of array
109 inline Sequence( const E * pElements, sal_Int32 len );
111 /** Constructor: Creates a default constructed sequence of given length.
113 @param len initial sequence length
115 inline explicit Sequence( sal_Int32 len );
117 /** Destructor: Releases sequence handle. Last handle will destruct
118 elements and free memory.
120 inline ~Sequence() SAL_THROW(());
122 /** Assignment operator: Acquires given sequence handle and releases
123 previously set handle.
125 @param rSeq another sequence of same type
126 @return this sequence
128 inline Sequence< E > & SAL_CALL operator = ( const Sequence< E > & rSeq )
129 SAL_THROW(());
131 /** Gets length of the sequence.
133 @return length of sequence
135 inline sal_Int32 SAL_CALL getLength() const SAL_THROW(())
136 { return _pSequence->nElements; }
138 /** Tests whether the sequence has elements, i.e. elements count is
139 greater than zero.
141 @return true, if elements count is greater than zero
143 inline sal_Bool SAL_CALL hasElements() const SAL_THROW(())
144 { return (_pSequence->nElements > 0); }
146 /** Gets a pointer to elements array for reading.
147 If the sequence has a length of 0, then the returned pointer is
148 undefined.
150 @return pointer to elements array
152 inline const E * SAL_CALL getConstArray() const SAL_THROW(())
153 { return reinterpret_cast< const E * >( _pSequence->elements ); }
155 /** Gets a pointer to elements array for reading and writing.
156 In general if the sequence has a handle acquired by other sequences
157 (reference count > 1), then a new sequence is created copy constructing
158 all elements to keep value semantics!
159 If the sequence has a length of 0, then the returned pointer is
160 undefined.
162 @return pointer to elements array
164 inline E * SAL_CALL getArray();
166 /** This function allows to use Sequence in standard algorightms, like std::find
167 and others.
169 @since LibreOffice 4.2
171 inline E * begin();
173 /** This function allows to use Sequence in standard algorightms, like std::find
174 and others.
176 @since LibreOffice 4.2
178 inline E const * begin() const;
180 /** This function allows to use Sequence in standard algorightms, like std::find
181 and others.
183 @since LibreOffice 4.2
185 inline E * end();
187 /** This function allows to use Sequence in standard algorightms, like std::find
188 and others.
190 @since LibreOffice 4.2
192 inline E const * end() const;
194 /** Non-const index operator: Obtains a reference to element indexed at
195 given position.
196 The implementation does not check for array bounds!
197 In general if the sequence has a handle acquired by other sequences
198 (reference count > 1), then a new sequence is created copy constructing
199 all elements to keep value semantics!
201 @param nIndex index
202 @return non-const C++ reference to element
204 inline E & SAL_CALL operator [] ( sal_Int32 nIndex );
206 /** Const index operator: Obtains a reference to element indexed at
207 given position. The implementation does not check for array bounds!
209 @param nIndex index
210 @return const C++ reference to element
212 inline const E & SAL_CALL operator [] ( sal_Int32 nIndex ) const
213 SAL_THROW(());
215 /** Equality operator: Compares two sequences.
217 @param rSeq another sequence of same type (right side)
218 @return true if both sequences are equal, false otherwise
220 inline sal_Bool SAL_CALL operator == ( const Sequence< E > & rSeq ) const
221 SAL_THROW(());
223 /** Unequality operator: Compares two sequences.
225 @param rSeq another sequence of same type (right side)
226 @return false if both sequences are equal, true otherwise
228 inline sal_Bool SAL_CALL operator != ( const Sequence< E > & rSeq ) const
229 SAL_THROW(());
231 /** Reallocates sequence to new length.
232 If the new length is smaller than the former, then upper elements will
233 be destructed (and their memory freed). If the new length is greater
234 than the former, then upper (new) elements are default constructed.
235 If the sequence has a handle acquired by other sequences
236 (reference count > 1), then the remaining elements are copy constructed
237 to a new sequence handle to keep value semantics!
239 @param nSize new size of sequence
241 inline void SAL_CALL realloc( sal_Int32 nSize );
243 /** Provides UNacquired sequence handle.
245 @return UNacquired sequence handle
247 inline uno_Sequence * SAL_CALL get() const SAL_THROW(())
248 { return _pSequence; }
251 /** Creates a UNO byte sequence from a SAL byte sequence.
253 @param rByteSequence a byte sequence
254 @return a UNO byte sequence
256 inline ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL toUnoSequence(
257 const ::rtl::ByteSequence & rByteSequence ) SAL_THROW(());
264 /** Gets the meta type of IDL sequence.
266 There are cases (involving templates) where uses of getCppuType are known to
267 not compile. Use cppu::UnoType or cppu::getTypeFavourUnsigned instead.
269 The dummy parameter is just a typed pointer for function signature.
271 @tparam E element type of sequence
272 @return type of IDL sequence
274 template< class E >
275 inline const ::com::sun::star::uno::Type &
276 SAL_CALL getCppuType( const ::com::sun::star::uno::Sequence< E > * )
277 SAL_THROW(());
279 /** Gets the meta type of IDL sequence.
280 This function has been introduced, because one cannot get the (templated)
281 cppu type out of C++ array types. Array types have special
282 getCppuArrayTypeN() functions.
284 @attention
285 the given element type must be the same as the template argument type!
286 @tparam E element type of sequence
287 @param rElementType element type of sequence
288 @return type of IDL sequence
290 template< class E >
291 inline const ::com::sun::star::uno::Type &
292 SAL_CALL getCppuSequenceType( const ::com::sun::star::uno::Type & rElementType )
293 SAL_THROW(());
295 /** Gets the meta type of IDL sequence< char >.
296 This function has been introduced due to ambiguities with unsigned short.
298 The dummy parameter is just a typed pointer for function signature.
300 @return type of IDL sequence< char >
302 inline const ::com::sun::star::uno::Type &
303 SAL_CALL getCharSequenceCppuType() SAL_THROW(());
305 #endif
307 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */