LibreOffice Module package (master) 1
MemoryByteGrabber.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 INCLUDED_PACKAGE_SOURCE_ZIPAPI_MEMORYBYTEGRABBER_HXX
20#define INCLUDED_PACKAGE_SOURCE_ZIPAPI_MEMORYBYTEGRABBER_HXX
21
22#include <com/sun/star/uno/Sequence.h>
23
25{
27 sal_Int32 mnCurrent, mnEnd;
28public:
29 MemoryByteGrabber ( const css::uno::Sequence < sal_Int8 > & rBuffer )
30 : mpBuffer ( rBuffer.getConstArray() )
31 , mnCurrent ( 0 )
32 , mnEnd ( rBuffer.getLength() )
33 {
34 }
35 MemoryByteGrabber(css::uno::Sequence<sal_Int8> &&) = delete;
36
37 const sal_Int8 * getCurrentPos () const { return mpBuffer + mnCurrent; }
38
39 sal_Int32 remainingSize() const { return mnEnd - mnCurrent; }
40
41 // XInputStream chained
42
47 void skipBytes( sal_Int32 nBytesToSkip )
48 {
49 mnCurrent += nBytesToSkip;
50 }
51
52 // XSeekable chained...
53 sal_Int16 ReadInt16()
54 {
55 if (mnCurrent + 2 > mnEnd )
56 return 0;
57 sal_Int16 nInt16 = mpBuffer[mnCurrent++] & 0xFF;
58 nInt16 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 8;
59 return nInt16;
60 }
61
62 sal_Int16 ReadUInt16()
63 {
64 if (mnCurrent + 2 > mnEnd )
65 return 0;
66 sal_uInt16 nInt16 = mpBuffer[mnCurrent++] & 0xFF;
67 nInt16 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 8;
68 return nInt16;
69 }
70
71 sal_Int32 ReadInt32()
72 {
73 if (mnCurrent + 4 > mnEnd )
74 return 0;
75
76 sal_Int32 nInt32 = mpBuffer[mnCurrent++] & 0xFF;
77 nInt32 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 8;
78 nInt32 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 16;
79 nInt32 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 24;
80 return nInt32;
81 }
82
83 sal_uInt32 ReadUInt32()
84 {
85 if (mnCurrent + 4 > mnEnd )
86 return 0;
87
88 sal_uInt32 nInt32 = mpBuffer [mnCurrent++] & 0xFF;
89 nInt32 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 8;
90 nInt32 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 16;
91 nInt32 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 24;
92 return nInt32;
93 }
94
95 sal_uInt64 ReadUInt64()
96 {
97 if (mnCurrent + 8 > mnEnd)
98 return 0;
99
100 sal_uInt64 nInt64 = mpBuffer[mnCurrent++] & 0xFF;
101 nInt64 |= static_cast<sal_Int64>(mpBuffer[mnCurrent++] & 0xFF) << 8;
102 nInt64 |= static_cast<sal_Int64>(mpBuffer[mnCurrent++] & 0xFF) << 16;
103 nInt64 |= static_cast<sal_Int64>(mpBuffer[mnCurrent++] & 0xFF) << 24;
104 nInt64 |= static_cast<sal_Int64>(mpBuffer[mnCurrent++] & 0xFF) << 32;
105 nInt64 |= static_cast<sal_Int64>(mpBuffer[mnCurrent++] & 0xFF) << 40;
106 nInt64 |= static_cast<sal_Int64>(mpBuffer[mnCurrent++] & 0xFF) << 48;
107 nInt64 |= static_cast<sal_Int64>(mpBuffer[mnCurrent++] & 0xFF) << 56;
108 return nInt64;
109 }
110};
111
112#endif
113
114/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 remainingSize() const
const sal_Int8 * mpBuffer
MemoryByteGrabber(const css::uno::Sequence< sal_Int8 > &rBuffer)
MemoryByteGrabber(css::uno::Sequence< sal_Int8 > &&)=delete
const sal_Int8 * getCurrentPos() const
void skipBytes(sal_Int32 nBytesToSkip)
double getLength(const B2DPolygon &rCandidate)
signed char sal_Int8