Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/io/source/stm/streamhelper.hxx
Line
Count
Source
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
20
#pragma once
21
22
#include <com/sun/star/uno/Sequence.hxx>
23
24
#include <assert.h>
25
26
using namespace com::sun::star::uno;
27
28
namespace io_stm
29
{
30
31
class MemRingBuffer
32
{
33
public:
34
    MemRingBuffer();
35
    virtual ~MemRingBuffer();
36
37
    /***
38
    * overwrites data at given position. Size is automatically extended, when
39
    * data is written beyond end.
40
    ***/
41
    /// @throws css::io::BufferSizeExceededException
42
    void    writeAt( sal_Int32 nPos, const Sequence<sal_Int8> &);
43
    /// @throws css::io::BufferSizeExceededException
44
    void    readAt( sal_Int32 nPos, Sequence<sal_Int8> & , sal_Int32 nBytesToRead ) const;
45
    sal_Int32   getSize() const noexcept;
46
    /// @throws css::io::BufferSizeExceededException
47
    void    forgetFromStart(sal_Int32 nBytesToForget);
48
49
private:
50
    /// @throws css::io::BufferSizeExceededException
51
    void resizeBuffer(sal_Int32 nMinSize);
52
0
    void checkInvariants() const {
53
0
        assert( m_nBufferLen >= 0 );
54
0
        assert( m_nOccupiedBuffer >= 0 );
55
0
        assert( m_nOccupiedBuffer <= m_nBufferLen );
56
0
        assert( m_nStart >= 0 );
57
0
        assert( 0 == m_nStart || m_nStart < m_nBufferLen );
58
0
        (void) this; // avoid loplugin:staticmethods
59
0
    }
60
61
    sal_Int8    *m_p;
62
    sal_Int32   m_nBufferLen;
63
    sal_Int32   m_nStart;
64
    sal_Int32   m_nOccupiedBuffer;
65
};
66
67
68
class MemFIFO :
69
    private MemRingBuffer
70
{
71
public:
72
    /// @throws css::io::BufferSizeExceededException
73
    void          write( const Sequence<sal_Int8> &);
74
    /// @throws css::io::BufferSizeExceededException
75
    void          read( Sequence<sal_Int8> & , sal_Int32 nBytesToRead );
76
    /// @throws css::io::BufferSizeExceededException
77
    void          skip( sal_Int32 nBytesToSkip );
78
    sal_Int32     getSize() const noexcept
79
0
                  { return MemRingBuffer::getSize(); }
80
81
};
82
83
}
84
85
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */