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