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: stgstrms.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 ************************************************************************/
34 #ifndef _TOOLS_STREAM_HXX
35 #include <tools/stream.hxx>
43 // The FAT class performs FAT operations on an underlying storage stream.
44 // This stream is either the physical FAT stream (bPhys == TRUE ) or a normal
45 // storage stream, which then holds the FAT for small data allocations.
49 StgStrm
& rStrm
; // underlying stream
50 INT32 nMaxPage
; // highest page allocated so far
51 short nPageSize
; // physical page size
52 short nEntries
; // FAT entries per page
53 short nOffset
; // current offset within page
54 INT32 nLimit
; // search limit recommendation
55 BOOL bPhys
; // TRUE: physical FAT
56 StgPage
* GetPhysPage( INT32 nPage
);
57 BOOL
MakeChain( INT32 nStart
, INT32 nPages
);
58 BOOL
InitNew( INT32 nPage1
);
60 StgFAT( StgStrm
& rStrm
, BOOL bMark
);
61 INT32
FindBlock( INT32
& nPages
);
62 INT32
GetNextPage( INT32 nPg
);
63 INT32
AllocPages( INT32 nStart
, INT32 nPages
);
64 BOOL
FreePages( INT32 nStart
, BOOL bAll
);
65 INT32
GetMaxPage() { return nMaxPage
; }
66 void SetLimit( INT32 n
) { nLimit
= n
; }
69 // The base stream class provides basic functionality for seeking
70 // and accessing the data on a physical basis. It uses the built-in
71 // FAT class for the page allocations.
73 class StgStrm
{ // base class for all streams
75 StgIo
& rIo
; // I/O system
76 StgFAT
* pFat
; // FAT stream for allocations
77 StgDirEntry
* pEntry
; // dir entry (for ownership)
78 INT32 nStart
; // 1st data page
79 INT32 nSize
; // stream size in bytes
80 INT32 nPos
; // current byte position
81 INT32 nPage
; // current logical page
82 short nOffset
; // offset into current page
83 short nPageSize
; // logical page size
84 BOOL
Copy( INT32 nFrom
, INT32 nBytes
);
88 StgIo
& GetIo() { return rIo
; }
89 INT32
GetPos() { return nPos
; }
90 INT32
GetStart() { return nStart
; }
91 INT32
GetSize() { return nSize
; }
92 INT32
GetPage() { return nPage
; }
93 short GetPageSize() { return nPageSize
; }
95 short GetOffset() { return nOffset
;}
96 void SetEntry( StgDirEntry
& );
97 virtual BOOL
SetSize( INT32
);
98 virtual BOOL
Pos2Page( INT32 nBytePos
);
99 virtual INT32
Read( void*, INT32
) { return 0; }
100 virtual INT32
Write( const void*, INT32
) { return 0; }
101 virtual StgPage
* GetPhysPage( INT32 nBytePos
, BOOL bForce
= FALSE
);
102 virtual BOOL
IsSmallStrm() { return FALSE
; }
105 // The FAT stream class provides physical access to the master FAT.
106 // Since this access is implemented as a StgStrm, we can use the
109 class StgFATStrm
: public StgStrm
{ // the master FAT stream
110 virtual BOOL
Pos2Page( INT32 nBytePos
);
111 BOOL
SetPage( short, INT32
);
113 StgFATStrm( StgIo
& );
114 virtual ~StgFATStrm() {}
115 using StgStrm::GetPage
;
116 INT32
GetPage( short, BOOL
, USHORT
*pnMasterAlloc
= 0);
117 virtual BOOL
SetSize( INT32
);
118 virtual StgPage
* GetPhysPage( INT32 nBytePos
, BOOL bForce
= FALSE
);
121 // The stream has a size increment which normally is 1, but which can be
122 // set to any value is you want the size to be incremented by certain values.
124 class StgDataStrm
: public StgStrm
// a physical data stream
126 short nIncr
; // size adjust increment
127 void Init( INT32 nBgn
, INT32 nLen
);
129 StgDataStrm( StgIo
&, INT32 nBgn
, INT32 nLen
=-1 );
130 StgDataStrm( StgIo
&, StgDirEntry
* );
131 void* GetPtr( INT32 nPos
, BOOL bForce
, BOOL bDirty
);
132 void SetIncrement( short n
) { nIncr
= n
; }
133 virtual BOOL
SetSize( INT32
);
134 virtual INT32
Read( void*, INT32
);
135 virtual INT32
Write( const void*, INT32
);
138 // The small stream class provides access to streams with a size < 4096 bytes.
139 // This stream is a StgStream containing small pages. The FAT for this stream
140 // is also a StgStream. The start of the FAT is in the header at DataRootPage,
141 // the stream itself is pointed to by the root entry (it holds start & size).
143 class StgSmallStrm
: public StgStrm
// a logical data stream
145 StgStrm
* pData
; // the data stream
146 void Init( INT32 nBgn
, INT32 nLen
);
148 StgSmallStrm( StgIo
&, INT32 nBgn
, INT32 nLen
);
149 StgSmallStrm( StgIo
&, StgDirEntry
* );
150 virtual INT32
Read( void*, INT32
);
151 virtual INT32
Write( const void*, INT32
);
152 virtual BOOL
IsSmallStrm() { return TRUE
; }
155 class StgTmpStrm
: public SvMemoryStream
159 using SvMemoryStream::GetData
;
160 virtual ULONG
GetData( void* pData
, ULONG nSize
);
161 virtual ULONG
PutData( const void* pData
, ULONG nSize
);
162 virtual ULONG
SeekPos( ULONG nPos
);
163 virtual void FlushData();
166 StgTmpStrm( ULONG
=16 );
168 BOOL
Copy( StgTmpStrm
& );
169 void SetSize( ULONG
);
170 using SvMemoryStream::GetSize
;