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