LibreOffice
LibreOffice 6.4 SDK C/C++ API Reference
Sequence.h
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 INCLUDED_COM_SUN_STAR_UNO_SEQUENCE_H
20 #define INCLUDED_COM_SUN_STAR_UNO_SEQUENCE_H
21 
23 #include "uno/sequence2.h"
24 #include "com/sun/star/uno/Type.h"
25 #include "rtl/alloc.h"
26 
27 #include <new>
28 
29 #if defined LIBO_INTERNAL_ONLY
30 #include <cassert>
31 #include <initializer_list>
32 #endif
33 
34 namespace rtl
35 {
36 class ByteSequence;
37 }
38 
39 namespace com
40 {
41 namespace sun
42 {
43 namespace star
44 {
45 namespace uno
46 {
47 
55 template< class E >
56 class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI Sequence
57 {
60  uno_Sequence * _pSequence;
61 
62 public:
64 
65  // these are here to force memory de/allocation to sal lib.
66  static void * SAL_CALL operator new ( ::size_t nSize )
67  { return ::rtl_allocateMemory( nSize ); }
68  static void SAL_CALL operator delete ( void * pMem )
69  { ::rtl_freeMemory( pMem ); }
70  static void * SAL_CALL operator new ( ::size_t, void * pMem )
71  { return pMem; }
72  static void SAL_CALL operator delete ( void *, void * )
73  {}
74 
78  static typelib_TypeDescriptionReference * s_pType;
79 
81 
84  typedef E ElementType;
85 
88  inline Sequence();
89 
94  inline Sequence( const Sequence & rSeq );
95 
102  inline Sequence( uno_Sequence * pSequence, __sal_NoAcquire dummy );
103 
109  inline Sequence( const E * pElements, sal_Int32 len );
110 
115  inline explicit Sequence( sal_Int32 len );
116 
117 #if defined LIBO_INTERNAL_ONLY
118 
124  inline Sequence(std::initializer_list<E> init);
125 #endif
126 
130  inline ~Sequence();
131 
138  inline Sequence & SAL_CALL operator = ( const Sequence & rSeq );
139 
144  sal_Int32 SAL_CALL getLength() const
145  { return _pSequence->nElements; }
146 
152  bool SAL_CALL hasElements() const
153  { return (_pSequence->nElements > 0); }
154 
155 #if defined LIBO_INTERNAL_ONLY
156 
160  sal_uInt32 size() const
161  { assert(getLength() >= 0); return static_cast<sal_uInt32>(getLength()); }
162 #endif
163 
170  const E * SAL_CALL getConstArray() const
171  { return reinterpret_cast< const E * >( _pSequence->elements ); }
172 
182  inline E * SAL_CALL getArray();
183 
189  inline E * begin();
190 
196  inline E const * begin() const;
197 
203  inline E * end();
204 
210  inline E const * end() const;
211 
222  inline E & SAL_CALL operator [] ( sal_Int32 nIndex );
223 
230  inline const E & SAL_CALL operator [] ( sal_Int32 nIndex ) const;
231 
237  inline bool SAL_CALL operator == ( const Sequence & rSeq ) const;
238 
244  inline bool SAL_CALL operator != ( const Sequence & rSeq ) const;
245 
256  inline void SAL_CALL realloc( sal_Int32 nSize );
257 
262  uno_Sequence * SAL_CALL get() const
263  { return _pSequence; }
264 };
265 
266 // Find uses of illegal Sequence<bool> (instead of Sequence<sal_Bool>) during
267 // compilation:
268 template<> class Sequence<bool> {
270 };
271 
277 inline ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL toUnoSequence(
278  const ::rtl::ByteSequence & rByteSequence );
279 
280 }
281 }
282 }
283 }
284 
298 template< class E > SAL_DEPRECATED("use cppu::UnoType")
299 inline const ::com::sun::star::uno::Type &
300 SAL_CALL getCppuType( const ::com::sun::star::uno::Sequence< E > * );
301 
315 template< class E > SAL_DEPRECATED("use cppu::UnoType")
316 inline const ::com::sun::star::uno::Type &
317 SAL_CALL getCppuSequenceType( const ::com::sun::star::uno::Type & rElementType );
318 
329 SAL_DEPRECATED("use cppu::UnoType")
330 inline const ::com::sun::star::uno::Type &
331 SAL_CALL getCharSequenceCppuType();
332 
333 #endif
334 
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
com::sun::star::uno::toUnoSequence
inline ::com::sun::star::uno::Sequence< sal_Int8 > toUnoSequence(const ::rtl::ByteSequence &rByteSequence)
Creates a UNO byte sequence from a SAL byte sequence.
Definition: Sequence.hxx:211
sequence2.h
cppu
Definition: Enterable.hxx:27
com::sun::star::uno::Sequence
Template C++ class representing an IDL sequence.
Definition: Sequence.h:57
com::sun::star::uno::Sequence::Sequence
Sequence()
Default constructor: Creates an empty sequence.
Definition: Sequence.hxx:53
getCppuType
const ::com::sun::star::uno::Type & getCppuType(const ::com::sun::star::uno::Sequence< E > *)
Gets the meta type of IDL sequence.
SAL_WARN_UNUSED
#define SAL_WARN_UNUSED
Annotate classes where a compiler should warn if an instance is unused.
Definition: types.h:578
rtl_freeMemory
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
com::sun::star::uno::operator!=
bool operator!=(const Any &rAny, const C &value)
Template inequality operator: compares set value of left side any to right side value.
Definition: Any.hxx:664
rtl
Definition: bootstrap.hxx:30
com::sun::star::uno::Sequence::hasElements
bool hasElements() const
Tests whether the sequence has elements, i.e.
Definition: Sequence.h:152
getCharSequenceCppuType
const ::com::sun::star::uno::Type & getCharSequenceCppuType()
Gets the meta type of IDL sequence< char >.
Definition: Sequence.hxx:355
__sal_NoAcquire
__sal_NoAcquire
Definition: types.h:371
com
Definition: types.h:377
Type.h
SAL_DEPRECATED
#define SAL_DEPRECATED(message)
Use as follows: SAL_DEPRECATED("Don't use, it's evil.") void doit(int nPara);.
Definition: types.h:465
com::sun::star::uno::Sequence::get
uno_Sequence * get() const
Provides UNacquired sequence handle.
Definition: Sequence.h:262
com::sun::star::uno::Sequence< bool >
Definition: Sequence.h:268
rtl_allocateMemory
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
_sal_Sequence
This is the binary specification of a SAL sequence.
Definition: types.h:322
SAL_DELETED_FUNCTION
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:396
com::sun::star::uno::Sequence::getConstArray
const E * getConstArray() const
Gets a pointer to elements array for reading.
Definition: Sequence.h:170
typelib_TypeDescriptionReference
struct SAL_DLLPUBLIC_RTTI _typelib_TypeDescriptionReference typelib_TypeDescriptionReference
Holds a weak reference to a type description.
com::sun::star::uno::Sequence::ElementType
E ElementType
typedefs the element type of the sequence
Definition: Sequence.h:84
alloc.h
getCppuSequenceType
const ::com::sun::star::uno::Type & getCppuSequenceType(const ::com::sun::star::uno::Type &rElementType)
Gets the meta type of IDL sequence.
Definition: Sequence.hxx:341
com::sun::star::uno::Sequence::getLength
sal_Int32 getLength() const
Gets length of the sequence.
Definition: Sequence.h:144
typedescription.h
com::sun::star::uno::operator==
bool operator==(const Any &rAny, const C &value)
Template equality operator: compares set value of left side any to right side value.
Definition: Any.hxx:653