1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: streamhelper.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #define STREAMHELPER_HXX_HAD_NDEBUG
37 #if OSL_DEBUG_LEVEL == 0
42 #define Max( a, b ) (((a)>(b)) ? (a) : (b) )
43 #define Min( a, b ) (((a)<(b)) ? (a) : (b) )
47 class IFIFO_OutOfBoundsException
:
51 class IFIFO_OutOfMemoryException
:
60 virtual void write( const Sequence
<sal_Int8
> &) throw( IFIFO_OutOfMemoryException
,
61 IFIFO_OutOfBoundsException
)=0;
63 virtual void read( Sequence
<sal_Int8
> & , sal_Int32 nBytesToRead
)
64 throw( IFIFO_OutOfBoundsException
)=0;
65 virtual void skip( sal_Int32 nBytesToSkip
)
66 throw( IFIFO_OutOfBoundsException
)=0;
67 virtual sal_Int32
getSize() const throw( ) =0;
68 virtual void shrink() throw() = 0;
74 class IRingBuffer_OutOfBoundsException
:
78 class IRingBuffer_OutOfMemoryException
:
86 * overwrites data at given position. Size is automatically extended, when
87 * data is written beyond end.
91 virtual void writeAt( sal_Int32 nPos
, const Sequence
<sal_Int8
> &)
92 throw( IRingBuffer_OutOfMemoryException
,
93 IRingBuffer_OutOfBoundsException
)=0;
94 virtual void readAt( sal_Int32 nPos
, Sequence
<sal_Int8
> & , sal_Int32 nBytesToRead
) const
95 throw( IRingBuffer_OutOfBoundsException
)=0;
96 virtual sal_Int32
getSize() const throw( ) =0;
97 virtual void forgetFromStart( sal_Int32 nBytesToForget
) throw(IRingBuffer_OutOfBoundsException
)=0;
98 virtual void forgetFromEnd( sal_Int32 nBytesToForget
) throw(IRingBuffer_OutOfBoundsException
)=0;
99 virtual void shrink() throw() = 0;
100 virtual ~IRingBuffer() {};
104 class MemRingBuffer
:
109 virtual ~MemRingBuffer();
111 virtual void writeAt( sal_Int32 nPos
, const Sequence
<sal_Int8
> &)
112 throw( IRingBuffer_OutOfMemoryException
,
113 IRingBuffer_OutOfBoundsException
);
114 virtual void readAt( sal_Int32 nPos
, Sequence
<sal_Int8
> & , sal_Int32 nBytesToRead
) const
115 throw( IRingBuffer_OutOfBoundsException
);
116 virtual sal_Int32
getSize() const throw( );
117 virtual void forgetFromStart( sal_Int32 nBytesToForget
) throw(IRingBuffer_OutOfBoundsException
);
118 virtual void forgetFromEnd( sal_Int32 nBytesToForget
) throw(IRingBuffer_OutOfBoundsException
);
120 virtual void shrink() throw();
124 void resizeBuffer( sal_Int32 nMinSize
) throw( IRingBuffer_OutOfMemoryException
);
125 inline void checkInvariants()
127 assert( m_nBufferLen
>= 0 );
128 assert( m_nOccupiedBuffer
>= 0 );
129 assert( m_nOccupiedBuffer
<= m_nBufferLen
);
130 assert( m_nStart
>= 0 );
131 assert( 0 == m_nStart
|| m_nStart
< m_nBufferLen
);
135 sal_Int32 m_nBufferLen
;
137 sal_Int32 m_nOccupiedBuffer
;
143 private MemRingBuffer
146 virtual void write( const Sequence
<sal_Int8
> &) throw( IFIFO_OutOfMemoryException
,
147 IFIFO_OutOfBoundsException
);
148 virtual void read( Sequence
<sal_Int8
> & , sal_Int32 nBytesToRead
)
149 throw( IFIFO_OutOfBoundsException
);
150 virtual void skip( sal_Int32 nBytesToSkip
) throw( IFIFO_OutOfBoundsException
);
151 virtual sal_Int32
getSize() const throw( )
152 { return MemRingBuffer::getSize(); }
153 virtual void shrink() throw()
154 { MemRingBuffer::shrink(); }
158 // Restore NDEBUG state
159 #ifdef STREAMHELPER_HXX_HAD_NDEBUG