loplugin:constmethod in package
[LibreOffice.git] / package / source / zipapi / MemoryByteGrabber.hxx
blob9f52204ead672338cc073b71c940c34a90f4cea8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
19 #ifndef INCLUDED_PACKAGE_SOURCE_ZIPAPI_MEMORYBYTEGRABBER_HXX
20 #define INCLUDED_PACKAGE_SOURCE_ZIPAPI_MEMORYBYTEGRABBER_HXX
22 #include <com/sun/star/io/XInputStream.hpp>
23 #include <com/sun/star/io/XSeekable.hpp>
24 #include <string.h>
26 class MemoryByteGrabber final
28 const sal_Int8 *mpBuffer;
29 sal_Int32 mnCurrent, mnEnd;
30 public:
31 MemoryByteGrabber ( const css::uno::Sequence < sal_Int8 > & rBuffer )
32 : mpBuffer ( rBuffer.getConstArray() )
33 , mnCurrent ( 0 )
34 , mnEnd ( rBuffer.getLength() )
37 MemoryByteGrabber(css::uno::Sequence<sal_Int8> &&) = delete;
39 const sal_Int8 * getCurrentPos () const { return mpBuffer + mnCurrent; }
41 sal_Int32 remainingSize() const { return mnEnd - mnCurrent; }
43 // XInputStream chained
45 /// @throws css::io::NotConnectedException
46 /// @throws css::io::BufferSizeExceededException
47 /// @throws css::io::IOException
48 /// @throws css::uno::RuntimeException
49 void skipBytes( sal_Int32 nBytesToSkip )
51 mnCurrent += nBytesToSkip;
54 // XSeekable chained...
55 sal_Int16 ReadInt16()
57 if (mnCurrent + 2 > mnEnd )
58 return 0;
59 sal_Int16 nInt16 = mpBuffer[mnCurrent++] & 0xFF;
60 nInt16 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 8;
61 return nInt16;
63 sal_Int32 ReadInt32()
65 if (mnCurrent + 4 > mnEnd )
66 return 0;
68 sal_Int32 nInt32 = mpBuffer[mnCurrent++] & 0xFF;
69 nInt32 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 8;
70 nInt32 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 16;
71 nInt32 |= ( mpBuffer[mnCurrent++] & 0xFF ) << 24;
72 return nInt32;
75 sal_uInt32 ReadUInt32()
77 if (mnCurrent + 4 > mnEnd )
78 return 0;
80 sal_uInt32 nInt32 = mpBuffer [mnCurrent++] & 0xFF;
81 nInt32 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 8;
82 nInt32 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 16;
83 nInt32 |= ( mpBuffer [mnCurrent++] & 0xFF ) << 24;
84 return nInt32;
88 #endif
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */