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