xref: /aoo42x/main/sal/inc/rtl/byteseq.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _RTL_BYTESEQ_HXX_
28 #define _RTL_BYTESEQ_HXX_
29 
30 #include <osl/interlck.h>
31 #include <rtl/byteseq.h>
32 #include <rtl/alloc.h>
33 #include <rtl/memory.h>
34 
35 #if ! defined EXCEPTIONS_OFF
36 #include <new>
37 #endif
38 
39 
40 namespace rtl
41 {
42 
43 //__________________________________________________________________________________________________
44 inline ByteSequence::ByteSequence() SAL_THROW( () )
45 	: _pSequence( 0 )
46 {
47 	::rtl_byte_sequence_construct( &_pSequence, 0 );
48 }
49 //__________________________________________________________________________________________________
50 inline ByteSequence::ByteSequence( const ByteSequence & rSeq ) SAL_THROW( () )
51     : _pSequence( 0 )
52 {
53 	::rtl_byte_sequence_assign( &_pSequence, rSeq._pSequence );
54 }
55 //__________________________________________________________________________________________________
56 inline ByteSequence::ByteSequence( sal_Sequence *pSequence) SAL_THROW( () )
57     : _pSequence( pSequence )
58 {
59 	::rtl_byte_sequence_acquire( pSequence );
60 }
61 //__________________________________________________________________________________________________
62 inline ByteSequence::ByteSequence( const sal_Int8 * pElements, sal_Int32 len )
63 	: _pSequence( 0 )
64 {
65 	::rtl_byte_sequence_constructFromArray( &_pSequence, pElements, len );
66 #if ! defined EXCEPTIONS_OFF
67     if (_pSequence == 0)
68         throw ::std::bad_alloc();
69 #endif
70 }
71 //__________________________________________________________________________________________________
72 inline ByteSequence::ByteSequence( sal_Int32 len, enum __ByteSequence_NoDefault )
73 	: _pSequence( 0 )
74 {
75 	::rtl_byte_sequence_constructNoDefault( &_pSequence, len );
76 #if ! defined EXCEPTIONS_OFF
77     if (_pSequence == 0)
78         throw ::std::bad_alloc();
79 #endif
80 }
81 //__________________________________________________________________________________________________
82 inline ByteSequence::ByteSequence( sal_Sequence *pSequence, enum __ByteSequence_NoAcquire ) SAL_THROW( () )
83 	: _pSequence( pSequence )
84 {
85 }
86 //__________________________________________________________________________________________________
87 inline ByteSequence::ByteSequence( sal_Int32 len )
88 	: _pSequence( 0 )
89 {
90 	::rtl_byte_sequence_construct( &_pSequence, len );
91 #if ! defined EXCEPTIONS_OFF
92     if (_pSequence == 0)
93         throw ::std::bad_alloc();
94 #endif
95 }
96 //__________________________________________________________________________________________________
97 inline ByteSequence::~ByteSequence() SAL_THROW( () )
98 {
99 	::rtl_byte_sequence_release( _pSequence );
100 }
101 //__________________________________________________________________________________________________
102 inline ByteSequence & ByteSequence::operator = ( const ByteSequence & rSeq ) SAL_THROW( () )
103 {
104 	::rtl_byte_sequence_assign( &_pSequence, rSeq._pSequence );
105 	return *this;
106 }
107 //__________________________________________________________________________________________________
108 inline sal_Bool ByteSequence::operator == ( const ByteSequence & rSeq ) const SAL_THROW( () )
109 {
110     return ::rtl_byte_sequence_equals( _pSequence, rSeq._pSequence );
111 }
112 //__________________________________________________________________________________________________
113 inline sal_Int8 * ByteSequence::getArray()
114 {
115 	::rtl_byte_sequence_reference2One( &_pSequence );
116 #if ! defined EXCEPTIONS_OFF
117     if (_pSequence == 0)
118         throw ::std::bad_alloc();
119 #endif
120 	return (sal_Int8 *)_pSequence->elements;
121 }
122 //__________________________________________________________________________________________________
123 inline void ByteSequence::realloc( sal_Int32 nSize )
124 {
125 	::rtl_byte_sequence_realloc( &_pSequence, nSize );
126 #if ! defined EXCEPTIONS_OFF
127     if (_pSequence == 0)
128         throw ::std::bad_alloc();
129 #endif
130 }
131 //__________________________________________________________________________________________________
132 inline sal_Int8 & ByteSequence::operator [] ( sal_Int32 nIndex )
133 {
134 	return getArray()[ nIndex ];
135 }
136 //__________________________________________________________________________________________________
137 inline sal_Bool ByteSequence::operator != ( const ByteSequence & rSeq ) const SAL_THROW( () )
138 {
139 	return (! operator == ( rSeq ));
140 }
141 
142 }
143 #endif
144