1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <osl/thread.h>
24 const static sal_uInt32 UP_LIMIT
=0xFFFFFF00L
;
26 // The SbiBuffer will be expanded in increments of at least 16 Bytes.
27 // This is necessary, because many classes emanate from a buffer length
30 SbiBuffer::SbiBuffer( SbiParser
* p
, short n
)
33 n
= ( (n
+ 15 ) / 16 ) * 16;
42 SbiBuffer::~SbiBuffer()
47 // Reach out the buffer
48 // This lead to the deletion of the buffer!
50 char* SbiBuffer::GetBuffer()
58 // Test, if the buffer can contain n Bytes.
59 // In case of doubt it will be enlarged
61 bool SbiBuffer::Check( sal_Int32 n
)
67 if( nOff
+ n
> nSize
)
80 if( ( nSize
+ nn
) > UP_LIMIT
)
86 p
= new char [nSize
+ nn
];
90 pParser
->Error( SbERR_PROG_TOO_LARGE
);
92 delete[] pBuf
; pBuf
= NULL
;
97 if( nSize
) memcpy( p
, pBuf
, nSize
);
107 // Patch of a Location
109 void SbiBuffer::Patch( sal_uInt32 off
, sal_uInt32 val
)
111 if( ( off
+ sizeof( sal_uInt32
) ) < nOff
)
113 sal_uInt16 val1
= static_cast<sal_uInt16
>( val
& 0xFFFF );
114 sal_uInt16 val2
= static_cast<sal_uInt16
>( val
>> 16 );
115 sal_uInt8
* p
= reinterpret_cast<sal_uInt8
*>(pBuf
) + off
;
116 *p
++ = (char) ( val1
& 0xFF );
117 *p
++ = (char) ( val1
>> 8 );
118 *p
++ = (char) ( val2
& 0xFF );
119 *p
= (char) ( val2
>> 8 );
123 // Forward References upon label und procedures
124 // establish a linkage. The beginning of the linkage is at the passed parameter,
125 // the end of the linkage is 0.
127 void SbiBuffer::Chain( sal_uInt32 off
)
133 sal_uInt32 val1
= (nOff
& 0xFFFF);
134 sal_uInt32 val2
= (nOff
>> 16);
137 ip
= reinterpret_cast<sal_uInt8
*>(pBuf
) + i
;
138 sal_uInt8
* pTmp
= ip
;
139 i
= *pTmp
++; i
|= *pTmp
++ << 8; i
|= *pTmp
++ << 16; i
|= *pTmp
++ << 24;
143 pParser
->Error( SbERR_INTERNAL_ERROR
, "BACKCHAIN" );
146 *ip
++ = (char) ( val1
& 0xFF );
147 *ip
++ = (char) ( val1
>> 8 );
148 *ip
++ = (char) ( val2
& 0xFF );
149 *ip
= (char) ( val2
>> 8 );
154 bool SbiBuffer::operator +=( sal_Int8 n
)
168 bool SbiBuffer::operator +=( sal_uInt8 n
)
182 bool SbiBuffer::operator +=( sal_Int16 n
)
186 *pCur
++ = (char) ( n
& 0xFF );
187 *pCur
++ = (char) ( n
>> 8 );
197 bool SbiBuffer::operator +=( sal_uInt16 n
)
201 *pCur
++ = (char) ( n
& 0xFF );
202 *pCur
++ = (char) ( n
>> 8 );
212 bool SbiBuffer::operator +=( sal_uInt32 n
)
216 sal_uInt16 n1
= static_cast<sal_uInt16
>( n
& 0xFFFF );
217 sal_uInt16 n2
= static_cast<sal_uInt16
>( n
>> 16 );
218 operator +=(n1
) && operator +=(n2
);
227 bool SbiBuffer::operator +=( sal_Int32 n
)
229 return operator +=( (sal_uInt32
) n
);
233 bool SbiBuffer::operator +=( const OUString
& n
)
235 sal_uInt32 len
= n
.getLength() + 1;
238 OString
aByteStr(OUStringToOString(n
, osl_getThreadTextEncoding()));
239 memcpy( pCur
, aByteStr
.getStr(), len
);
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */