LibreOffice
LibreOffice 24.2 SDK C/C++ API Reference
byteseq.hxx
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 
20 /*
21  * This file is part of LibreOffice published API.
22  */
23 #ifndef INCLUDED_RTL_BYTESEQ_HXX
24 #define INCLUDED_RTL_BYTESEQ_HXX
25 
26 #include "rtl/byteseq.h"
27 
28 #include <cstddef>
29 #include <new>
30 
31 namespace rtl
32 {
33 
34 
36  : _pSequence( NULL )
37 {
38  ::rtl_byte_sequence_construct( &_pSequence, 0 );
39 }
40 
42  : _pSequence( NULL )
43 {
44  ::rtl_byte_sequence_assign( &_pSequence, rSeq._pSequence );
45 }
46 
47 #if defined LIBO_INTERNAL_ONLY
48 inline ByteSequence::ByteSequence( ByteSequence && rSeq ) noexcept
49  : _pSequence(rSeq._pSequence)
50 {
51  rSeq._pSequence = nullptr;
52 }
53 #endif
54 
56  : _pSequence( pSequence )
57 {
58  ::rtl_byte_sequence_acquire( pSequence );
59 }
60 
61 inline ByteSequence::ByteSequence( const sal_Int8 * pElements, sal_Int32 len )
62  : _pSequence( NULL )
63 {
64  ::rtl_byte_sequence_constructFromArray( &_pSequence, pElements, len );
65  if (_pSequence == NULL)
66  throw ::std::bad_alloc();
67 }
68 
70  : _pSequence( NULL )
71 {
72  ::rtl_byte_sequence_constructNoDefault( &_pSequence, len );
73  if (_pSequence == NULL)
74  throw ::std::bad_alloc();
75 }
76 
78  : _pSequence( pSequence )
79 {
80 }
81 
82 inline ByteSequence::ByteSequence( sal_Int32 len )
83  : _pSequence( NULL )
84 {
85  ::rtl_byte_sequence_construct( &_pSequence, len );
86  if (_pSequence == NULL)
87  throw ::std::bad_alloc();
88 }
89 
91 {
92  ::rtl_byte_sequence_release( _pSequence );
93 }
94 
96 {
97  ::rtl_byte_sequence_assign( &_pSequence, rSeq._pSequence );
98  return *this;
99 }
100 
101 #if defined LIBO_INTERNAL_ONLY
102 inline ByteSequence & ByteSequence::operator = ( ByteSequence && rSeq ) noexcept
103 {
104  ::rtl_byte_sequence_release(_pSequence);
105  _pSequence = rSeq._pSequence;
106  rSeq._pSequence = nullptr;
107  return *this;
108 }
109 #endif
110 
111 inline bool ByteSequence::operator == ( const ByteSequence & rSeq ) const
112 {
113  return ::rtl_byte_sequence_equals( _pSequence, rSeq._pSequence );
114 }
115 
117 {
118  ::rtl_byte_sequence_reference2One( &_pSequence );
119  if (_pSequence == NULL)
120  throw ::std::bad_alloc();
121  return reinterpret_cast<sal_Int8 *>(_pSequence->elements);
122 }
123 
124 inline void ByteSequence::realloc( sal_Int32 nSize )
125 {
126  ::rtl_byte_sequence_realloc( &_pSequence, nSize );
127  if (_pSequence == NULL)
128  throw ::std::bad_alloc();
129 }
130 
131 inline sal_Int8 & ByteSequence::operator [] ( sal_Int32 nIndex )
132 {
133  return getArray()[ nIndex ];
134 }
135 
136 inline bool ByteSequence::operator != ( const ByteSequence & rSeq ) const
137 {
138  return (! operator == ( rSeq ));
139 }
140 
141 }
142 #endif
143 
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC void rtl_byte_sequence_acquire(sal_Sequence *pSequence) SAL_THROW_EXTERN_C()
Acquires the byte sequence.
__ByteSequence_NoAcquire
Definition: byteseq.h:151
signed char sal_Int8
Definition: types.h:43
This is the binary specification of a SAL sequence.
Definition: types.h:303
bool operator==(const ByteSequence &rSeq) const
Equality operator: Compares two sequences.
Definition: byteseq.hxx:111
sal_Int8 * getArray()
Gets a pointer to elements array for READING AND WRITING.
Definition: byteseq.hxx:116
char elements[1]
elements array
Definition: types.h:313
SAL_DLLPUBLIC void rtl_byte_sequence_constructFromArray(sal_Sequence **ppSequence, const sal_Int8 *pData, sal_Int32 nLength) SAL_THROW_EXTERN_C()
Constructs a byte sequence with length nLength and copies nLength bytes from pData.
bool operator!=(const ByteSequence &rSeq) const
Unequality operator: Compares two sequences.
Definition: byteseq.hxx:136
SAL_DLLPUBLIC void rtl_byte_sequence_construct(sal_Sequence **ppSequence, sal_Int32 nLength) SAL_THROW_EXTERN_C()
Constructs a bytes sequence with length nLength.
void realloc(sal_Int32 nSize)
Reallocates sequence to new length.
Definition: byteseq.hxx:124
C++ class representing a SAL byte sequence.
Definition: byteseq.h:169
__ByteSequence_NoDefault
Definition: byteseq.h:144
SAL_DLLPUBLIC sal_Bool rtl_byte_sequence_equals(sal_Sequence *pSequence1, sal_Sequence *pSequence2) SAL_THROW_EXTERN_C()
Compares two byte sequences.
Definition: bootstrap.hxx:33
SAL_DLLPUBLIC void rtl_byte_sequence_reference2One(sal_Sequence **ppSequence) SAL_THROW_EXTERN_C()
Assures that the reference count of the given byte sequence is one.
SAL_DLLPUBLIC void rtl_byte_sequence_realloc(sal_Sequence **ppSequence, sal_Int32 nSize) SAL_THROW_EXTERN_C()
Reallocates length of byte sequence.
ByteSequence()
Default constructor: Creates an empty sequence.
Definition: byteseq.hxx:35
SAL_DLLPUBLIC void rtl_byte_sequence_constructNoDefault(sal_Sequence **ppSequence, sal_Int32 nLength) SAL_THROW_EXTERN_C()
Constructs a bytes sequence with length nLength.
SAL_DLLPUBLIC void rtl_byte_sequence_assign(sal_Sequence **ppSequence, sal_Sequence *pSequence) SAL_THROW_EXTERN_C()
Assigns the byte sequence pSequence to *ppSequence.
sal_Int8 & operator[](sal_Int32 nIndex)
Non-const index operator: Obtains a reference to byte indexed at given position.
Definition: byteseq.hxx:131
ByteSequence & operator=(const ByteSequence &rSeq)
Assignment operator: Acquires given sequence handle and releases a previously set handle...
Definition: byteseq.hxx:95
SAL_DLLPUBLIC void rtl_byte_sequence_release(sal_Sequence *pSequence) SAL_THROW_EXTERN_C()
Releases the byte sequence.
~ByteSequence()
Destructor: Releases sequence handle.
Definition: byteseq.hxx:90