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 #ifndef INCLUDED_IO_SOURCE_STM_STREAMHELPER_HXX
21 #define INCLUDED_IO_SOURCE_STM_STREAMHELPER_HXX
25 #define STREAMHELPER_HXX_HAD_NDEBUG
29 #if OSL_DEBUG_LEVEL == 0
34 #define Max( a, b ) (((a)>(b)) ? (a) : (b) )
35 #define Min( a, b ) (((a)<(b)) ? (a) : (b) )
39 class I_FIFO_OutOfBoundsException
:
43 class I_FIFO_OutOfMemoryException
:
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;
66 class IRingBuffer_OutOfBoundsException
:
70 class IRingBuffer_OutOfMemoryException
:
78 * overwrites data at given position. Size is automatically extended, when
79 * data is written beyond end.
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() {};
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
;
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
);
127 sal_Int32 m_nBufferLen
;
129 sal_Int32 m_nOccupiedBuffer
;
135 private MemRingBuffer
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
159 #endif // INCLUDED_IO_SOURCE_STM_STREAMHELPER_HXX
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */