bump product version to 5.0.4.1
[LibreOffice.git] / io / source / stm / streamhelper.hxx
blob56b7412e0d8947cd873d658ff71ab4eaf2b1c75c
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 .
20 #ifndef INCLUDED_IO_SOURCE_STM_STREAMHELPER_HXX
21 #define INCLUDED_IO_SOURCE_STM_STREAMHELPER_HXX
23 // Save NDEBUG state
24 #ifdef NDEBUG
25 #define STREAMHELPER_HXX_HAD_NDEBUG
26 #undef NDEBUG
27 #endif
29 #if OSL_DEBUG_LEVEL == 0
30 #define NDEBUG
31 #endif
32 #include <assert.h>
34 #define Max( a, b ) (((a)>(b)) ? (a) : (b) )
35 #define Min( a, b ) (((a)<(b)) ? (a) : (b) )
37 namespace io_stm {
39 class I_FIFO_OutOfBoundsException :
40 public Exception
41 {};
43 class I_FIFO_OutOfMemoryException :
44 public Exception
45 {};
47 class I_FIFO
49 public:
52 virtual void write( const Sequence<sal_Int8> &) throw( I_FIFO_OutOfMemoryException,
53 I_FIFO_OutOfBoundsException )=0;
55 virtual void read( Sequence<sal_Int8> & , sal_Int32 nBytesToRead )
56 throw( I_FIFO_OutOfBoundsException )=0;
57 virtual void skip( sal_Int32 nBytesToSkip )
58 throw( I_FIFO_OutOfBoundsException )=0;
59 virtual sal_Int32 getSize() const throw( ) =0;
60 virtual void shrink() throw() = 0;
62 virtual ~I_FIFO() {};
66 class IRingBuffer_OutOfBoundsException :
67 public Exception
68 {};
70 class IRingBuffer_OutOfMemoryException :
71 public Exception
72 {};
74 class IRingBuffer
76 public:
77 /***
78 * overwrites data at given position. Size is automatically extended, when
79 * data is written beyond end.
81 ***/
83 virtual void writeAt( sal_Int32 nPos, const Sequence<sal_Int8> &)
84 throw( IRingBuffer_OutOfMemoryException,
85 IRingBuffer_OutOfBoundsException )=0;
86 virtual void readAt( sal_Int32 nPos, Sequence<sal_Int8> & , sal_Int32 nBytesToRead ) const
87 throw( IRingBuffer_OutOfBoundsException )=0;
88 virtual sal_Int32 getSize() const throw( ) =0;
89 virtual void forgetFromStart( sal_Int32 nBytesToForget ) throw(IRingBuffer_OutOfBoundsException)=0;
90 virtual void forgetFromEnd( sal_Int32 nBytesToForget ) throw(IRingBuffer_OutOfBoundsException)=0;
91 virtual void shrink() throw() = 0;
92 virtual ~IRingBuffer() {};
96 class MemRingBuffer :
97 public IRingBuffer
99 public:
100 MemRingBuffer();
101 virtual ~MemRingBuffer();
103 virtual void writeAt( sal_Int32 nPos, const Sequence<sal_Int8> &)
104 throw( IRingBuffer_OutOfMemoryException,
105 IRingBuffer_OutOfBoundsException ) SAL_OVERRIDE;
106 virtual void readAt( sal_Int32 nPos, Sequence<sal_Int8> & , sal_Int32 nBytesToRead ) const
107 throw( IRingBuffer_OutOfBoundsException ) SAL_OVERRIDE;
108 virtual sal_Int32 getSize() const throw( ) SAL_OVERRIDE;
109 virtual void forgetFromStart( sal_Int32 nBytesToForget ) throw(IRingBuffer_OutOfBoundsException) SAL_OVERRIDE;
110 virtual void forgetFromEnd( sal_Int32 nBytesToForget ) throw(IRingBuffer_OutOfBoundsException) SAL_OVERRIDE;
112 virtual void shrink() throw() SAL_OVERRIDE;
114 private:
116 void resizeBuffer( sal_Int32 nMinSize ) throw( IRingBuffer_OutOfMemoryException );
117 inline void checkInvariants()
119 assert( m_nBufferLen >= 0 );
120 assert( m_nOccupiedBuffer >= 0 );
121 assert( m_nOccupiedBuffer <= m_nBufferLen );
122 assert( m_nStart >= 0 );
123 assert( 0 == m_nStart || m_nStart < m_nBufferLen );
126 sal_Int8 *m_p;
127 sal_Int32 m_nBufferLen;
128 sal_Int32 m_nStart;
129 sal_Int32 m_nOccupiedBuffer;
133 class MemFIFO :
134 public I_FIFO,
135 private MemRingBuffer
137 public:
138 virtual void write( const Sequence<sal_Int8> &) throw( I_FIFO_OutOfMemoryException,
139 I_FIFO_OutOfBoundsException ) SAL_OVERRIDE;
140 virtual void read( Sequence<sal_Int8> & , sal_Int32 nBytesToRead )
141 throw( I_FIFO_OutOfBoundsException ) SAL_OVERRIDE;
142 virtual void skip( sal_Int32 nBytesToSkip ) throw( I_FIFO_OutOfBoundsException ) SAL_OVERRIDE;
143 virtual sal_Int32 getSize() const throw( ) SAL_OVERRIDE
144 { return MemRingBuffer::getSize(); }
145 virtual void shrink() throw() SAL_OVERRIDE
146 { MemRingBuffer::shrink(); }
150 // Restore NDEBUG state
151 #ifdef STREAMHELPER_HXX_HAD_NDEBUG
152 #define NDEBUG
153 #else
154 #undef NDEBUG
155 #endif
159 #endif // INCLUDED_IO_SOURCE_STM_STREAMHELPER_HXX
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */