LibreOffice
LibreOffice 4.1 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 _COM_SUN_STAR_UNO_SEQUENCE_H_
20 #define _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 #if ! defined EXCEPTIONS_OFF
28 #include <new>
29 #endif
30 
31 
32 namespace rtl
33 {
34 class ByteSequence;
35 }
36 
37 namespace com
38 {
39 namespace sun
40 {
41 namespace star
42 {
43 namespace uno
44 {
45 
53 template< class E >
54 class Sequence
55 {
58  uno_Sequence * _pSequence;
59 
60 public:
62 
63  // these are here to force memory de/allocation to sal lib.
64  inline static void * SAL_CALL operator new ( ::size_t nSize )
65  SAL_THROW(())
66  { return ::rtl_allocateMemory( nSize ); }
67  inline static void SAL_CALL operator delete ( void * pMem )
68  SAL_THROW(())
69  { ::rtl_freeMemory( pMem ); }
70  inline static void * SAL_CALL operator new ( ::size_t, void * pMem )
71  SAL_THROW(())
72  { return pMem; }
73  inline static void SAL_CALL operator delete ( void *, void * )
74  SAL_THROW(())
75  {}
76 
80  static typelib_TypeDescriptionReference * s_pType;
81 
83 
86  typedef E ElementType;
87 
90  inline Sequence() SAL_THROW(());
91 
96  inline Sequence( const Sequence< E > & rSeq ) SAL_THROW(());
97 
104  inline Sequence( uno_Sequence * pSequence, __sal_NoAcquire dummy )
105  SAL_THROW(());
106 
112  inline Sequence( const E * pElements, sal_Int32 len );
113 
118  inline explicit Sequence( sal_Int32 len );
119 
123  inline ~Sequence() SAL_THROW(());
124 
131  inline Sequence< E > & SAL_CALL operator = ( const Sequence< E > & rSeq )
132  SAL_THROW(());
133 
138  inline sal_Int32 SAL_CALL getLength() const SAL_THROW(())
139  { return _pSequence->nElements; }
140 
146  inline sal_Bool SAL_CALL hasElements() const SAL_THROW(())
147  { return (_pSequence->nElements > 0); }
148 
155  inline const E * SAL_CALL getConstArray() const SAL_THROW(())
156  { return reinterpret_cast< const E * >( _pSequence->elements ); }
157 
167  inline E * SAL_CALL getArray();
168 
179  inline E & SAL_CALL operator [] ( sal_Int32 nIndex );
180 
187  inline const E & SAL_CALL operator [] ( sal_Int32 nIndex ) const
188  SAL_THROW(());
189 
195  inline sal_Bool SAL_CALL operator == ( const Sequence< E > & rSeq ) const
196  SAL_THROW(());
197 
203  inline sal_Bool SAL_CALL operator != ( const Sequence< E > & rSeq ) const
204  SAL_THROW(());
205 
216  inline void SAL_CALL realloc( sal_Int32 nSize );
217 
222  inline uno_Sequence * SAL_CALL get() const SAL_THROW(())
223  { return _pSequence; }
224 };
225 
231 inline ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL toUnoSequence(
232  const ::rtl::ByteSequence & rByteSequence ) SAL_THROW(());
233 
234 }
235 }
236 }
237 }
238 
249 template< class E >
250 inline const ::com::sun::star::uno::Type &
251 SAL_CALL getCppuType( const ::com::sun::star::uno::Sequence< E > * )
252  SAL_THROW(());
253 
265 template< class E >
266 inline const ::com::sun::star::uno::Type &
267 SAL_CALL getCppuSequenceType( const ::com::sun::star::uno::Type & rElementType )
268  SAL_THROW(());
269 
277 inline const ::com::sun::star::uno::Type &
278 SAL_CALL getCharSequenceCppuType() SAL_THROW(());
279 
280 #endif
281 
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
E ElementType
typedefs the element type of the sequence
Definition: Sequence.h:86
char elements[1]
elements array
Definition: types.h:333
sal_Bool operator==(const Sequence< E > &rSeq) const
Equality operator: Compares two sequences.
Definition: Sequence.hxx:129
const ::com::sun::star::uno::Type & getCppuSequenceType(const ::com::sun::star::uno::Type &rElementType)
Gets the meta type of IDL sequence.
Definition: Sequence.hxx:269
const ::com::sun::star::uno::Type & getCharSequenceCppuType()
Gets the meta type of IDL sequence&lt; char &gt;.
Definition: Sequence.hxx:288
Sequence()
Default constructor: Creates an empty sequence.
Definition: Sequence.hxx:49
E * getArray()
Gets a pointer to elements array for reading and writing.
Definition: Sequence.hxx:152
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:203
unsigned char sal_Bool
Definition: types.h:37
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
__sal_NoAcquire
Definition: types.h:370
This is the binary specification of a SAL sequence.
Definition: types.h:323
const ::com::sun::star::uno::Type & getCppuType(SAL_UNUSED_PARAMETER const ::com::sun::star::uno::Any *)
Gets the meta type of IDL type any.
Definition: Any.h:369
Template C++ class representing an IDL sequence.
Definition: unotype.hxx:33
void realloc(sal_Int32 nSize)
Reallocates sequence to new length.
Definition: Sequence.hxx:187
sal_Int32 nElements
element count
Definition: types.h:330
E & operator[](sal_Int32 nIndex)
Non-const index operator: Obtains a reference to element indexed at given position.
Definition: Sequence.hxx:170
Holds a weak reference to a type description.
Definition: typedescription.h:40
#define SAL_THROW(exc)
Definition of function throw clause macros.
Definition: types.h:356
const E * getConstArray() const
Gets a pointer to elements array for reading.
Definition: Sequence.h:155
sal_Bool hasElements() const
Tests whether the sequence has elements, i.e.
Definition: Sequence.h:146
sal_Int32 getLength() const
Gets length of the sequence.
Definition: Sequence.h:138
sal_Bool operator!=(const Sequence< E > &rSeq) const
Unequality operator: Compares two sequences.
Definition: Sequence.hxx:144