xref: /trunk/main/sal/inc/rtl/byteseq.hxx (revision 565d668c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _RTL_BYTESEQ_HXX_
24 #define _RTL_BYTESEQ_HXX_
25 
26 #include <osl/interlck.h>
27 #include <rtl/byteseq.h>
28 #include <rtl/alloc.h>
29 #include <rtl/memory.h>
30 
31 #if ! defined EXCEPTIONS_OFF
32 #include <new>
33 #endif
34 
35 
36 namespace rtl
37 {
38 
39 //__________________________________________________________________________________________________
ByteSequence()40 inline ByteSequence::ByteSequence() SAL_THROW( () )
41 	: _pSequence( 0 )
42 {
43 	::rtl_byte_sequence_construct( &_pSequence, 0 );
44 }
45 //__________________________________________________________________________________________________
ByteSequence(const ByteSequence & rSeq)46 inline ByteSequence::ByteSequence( const ByteSequence & rSeq ) SAL_THROW( () )
47     : _pSequence( 0 )
48 {
49 	::rtl_byte_sequence_assign( &_pSequence, rSeq._pSequence );
50 }
51 //__________________________________________________________________________________________________
ByteSequence(sal_Sequence * pSequence)52 inline ByteSequence::ByteSequence( sal_Sequence *pSequence) SAL_THROW( () )
53     : _pSequence( pSequence )
54 {
55 	::rtl_byte_sequence_acquire( pSequence );
56 }
57 //__________________________________________________________________________________________________
ByteSequence(const sal_Int8 * pElements,sal_Int32 len)58 inline ByteSequence::ByteSequence( const sal_Int8 * pElements, sal_Int32 len )
59 	: _pSequence( 0 )
60 {
61 	::rtl_byte_sequence_constructFromArray( &_pSequence, pElements, len );
62 #if ! defined EXCEPTIONS_OFF
63     if (_pSequence == 0)
64         throw ::std::bad_alloc();
65 #endif
66 }
67 //__________________________________________________________________________________________________
ByteSequence(sal_Int32 len,enum __ByteSequence_NoDefault)68 inline ByteSequence::ByteSequence( sal_Int32 len, enum __ByteSequence_NoDefault )
69 	: _pSequence( 0 )
70 {
71 	::rtl_byte_sequence_constructNoDefault( &_pSequence, len );
72 #if ! defined EXCEPTIONS_OFF
73     if (_pSequence == 0)
74         throw ::std::bad_alloc();
75 #endif
76 }
77 //__________________________________________________________________________________________________
ByteSequence(sal_Sequence * pSequence,enum __ByteSequence_NoAcquire)78 inline ByteSequence::ByteSequence( sal_Sequence *pSequence, enum __ByteSequence_NoAcquire ) SAL_THROW( () )
79 	: _pSequence( pSequence )
80 {
81 }
82 //__________________________________________________________________________________________________
ByteSequence(sal_Int32 len)83 inline ByteSequence::ByteSequence( sal_Int32 len )
84 	: _pSequence( 0 )
85 {
86 	::rtl_byte_sequence_construct( &_pSequence, len );
87 #if ! defined EXCEPTIONS_OFF
88     if (_pSequence == 0)
89         throw ::std::bad_alloc();
90 #endif
91 }
92 //__________________________________________________________________________________________________
~ByteSequence()93 inline ByteSequence::~ByteSequence() SAL_THROW( () )
94 {
95 	::rtl_byte_sequence_release( _pSequence );
96 }
97 //__________________________________________________________________________________________________
operator =(const ByteSequence & rSeq)98 inline ByteSequence & ByteSequence::operator = ( const ByteSequence & rSeq ) SAL_THROW( () )
99 {
100 	::rtl_byte_sequence_assign( &_pSequence, rSeq._pSequence );
101 	return *this;
102 }
103 //__________________________________________________________________________________________________
operator ==(const ByteSequence & rSeq) const104 inline sal_Bool ByteSequence::operator == ( const ByteSequence & rSeq ) const SAL_THROW( () )
105 {
106     return ::rtl_byte_sequence_equals( _pSequence, rSeq._pSequence );
107 }
108 //__________________________________________________________________________________________________
getArray()109 inline sal_Int8 * ByteSequence::getArray()
110 {
111 	::rtl_byte_sequence_reference2One( &_pSequence );
112 #if ! defined EXCEPTIONS_OFF
113     if (_pSequence == 0)
114         throw ::std::bad_alloc();
115 #endif
116 	return (sal_Int8 *)_pSequence->elements;
117 }
118 //__________________________________________________________________________________________________
realloc(sal_Int32 nSize)119 inline void ByteSequence::realloc( sal_Int32 nSize )
120 {
121 	::rtl_byte_sequence_realloc( &_pSequence, nSize );
122 #if ! defined EXCEPTIONS_OFF
123     if (_pSequence == 0)
124         throw ::std::bad_alloc();
125 #endif
126 }
127 //__________________________________________________________________________________________________
operator [](sal_Int32 nIndex)128 inline sal_Int8 & ByteSequence::operator [] ( sal_Int32 nIndex )
129 {
130 	return getArray()[ nIndex ];
131 }
132 //__________________________________________________________________________________________________
operator !=(const ByteSequence & rSeq) const133 inline sal_Bool ByteSequence::operator != ( const ByteSequence & rSeq ) const SAL_THROW( () )
134 {
135 	return (! operator == ( rSeq ));
136 }
137 
138 }
139 #endif
140