merge the formfield patch from ooo-build
[ooovba.git] / io / source / stm / streamhelper.hxx
blob5e3af2108eb5b4e37be28e7354eb874937ac2442
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: streamhelper.hxx,v $
10 * $Revision: 1.5 $
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 ************************************************************************/
31 // Save NDEBUG state
32 #ifdef NDEBUG
33 #define STREAMHELPER_HXX_HAD_NDEBUG
34 #undef NDEBUG
35 #endif
37 #if OSL_DEBUG_LEVEL == 0
38 #define NDEBUG
39 #endif
40 #include <assert.h>
42 #define Max( a, b ) (((a)>(b)) ? (a) : (b) )
43 #define Min( a, b ) (((a)<(b)) ? (a) : (b) )
45 namespace io_stm {
47 class IFIFO_OutOfBoundsException :
48 public Exception
49 {};
51 class IFIFO_OutOfMemoryException :
52 public Exception
53 {};
55 class IFIFO
57 public:
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;
70 virtual ~IFIFO() {};
74 class IRingBuffer_OutOfBoundsException :
75 public Exception
76 {};
78 class IRingBuffer_OutOfMemoryException :
79 public Exception
80 {};
82 class IRingBuffer
84 public:
85 /***
86 * overwrites data at given position. Size is automatically extended, when
87 * data is written beyond end.
89 ***/
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 :
105 public IRingBuffer
107 public:
108 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();
122 private:
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 );
134 sal_Int8 *m_p;
135 sal_Int32 m_nBufferLen;
136 sal_Int32 m_nStart;
137 sal_Int32 m_nOccupiedBuffer;
141 class MemFIFO :
142 public IFIFO,
143 private MemRingBuffer
145 public:
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
160 #define NDEBUG
161 #else
162 #undef NDEBUG
163 #endif