1bbfc4cc7SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3bbfc4cc7SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4bbfc4cc7SAndrew Rist * or more contributor license agreements. See the NOTICE file 5bbfc4cc7SAndrew Rist * distributed with this work for additional information 6bbfc4cc7SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7bbfc4cc7SAndrew Rist * to you under the Apache License, Version 2.0 (the 8bbfc4cc7SAndrew Rist * "License"); you may not use this file except in compliance 9bbfc4cc7SAndrew Rist * with the License. You may obtain a copy of the License at 10bbfc4cc7SAndrew Rist * 11bbfc4cc7SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12bbfc4cc7SAndrew Rist * 13bbfc4cc7SAndrew Rist * Unless required by applicable law or agreed to in writing, 14bbfc4cc7SAndrew Rist * software distributed under the License is distributed on an 15bbfc4cc7SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16bbfc4cc7SAndrew Rist * KIND, either express or implied. See the License for the 17bbfc4cc7SAndrew Rist * specific language governing permissions and limitations 18bbfc4cc7SAndrew Rist * under the License. 19bbfc4cc7SAndrew Rist * 20bbfc4cc7SAndrew Rist *************************************************************/ 21bbfc4cc7SAndrew Rist 22bbfc4cc7SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _STGSTRMS_HXX 25cdf0e10cSrcweir #define _STGSTRMS_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifndef _TOOLS_STREAM_HXX 28cdf0e10cSrcweir #include <tools/stream.hxx> 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir 31cdf0e10cSrcweir class StgIo; 32cdf0e10cSrcweir class StgStrm; 33cdf0e10cSrcweir class StgPage; 34cdf0e10cSrcweir class StgDirEntry; 35cdf0e10cSrcweir 36cdf0e10cSrcweir // The FAT class performs FAT operations on an underlying storage stream. 37cdf0e10cSrcweir // This stream is either the physical FAT stream (bPhys == sal_True ) or a normal 38cdf0e10cSrcweir // storage stream, which then holds the FAT for small data allocations. 39cdf0e10cSrcweir 40cdf0e10cSrcweir class StgFAT 41cdf0e10cSrcweir { // FAT allocator 42cdf0e10cSrcweir StgStrm& rStrm; // underlying stream 43cdf0e10cSrcweir sal_Int32 nMaxPage; // highest page allocated so far 44cdf0e10cSrcweir short nPageSize; // physical page size 45cdf0e10cSrcweir short nEntries; // FAT entries per page 46cdf0e10cSrcweir short nOffset; // current offset within page 47cdf0e10cSrcweir sal_Int32 nLimit; // search limit recommendation 48cdf0e10cSrcweir sal_Bool bPhys; // sal_True: physical FAT 49cdf0e10cSrcweir StgPage* GetPhysPage( sal_Int32 nPage ); 50cdf0e10cSrcweir sal_Bool MakeChain( sal_Int32 nStart, sal_Int32 nPages ); 51cdf0e10cSrcweir sal_Bool InitNew( sal_Int32 nPage1 ); 52cdf0e10cSrcweir public: 53cdf0e10cSrcweir StgFAT( StgStrm& rStrm, sal_Bool bMark ); 54cdf0e10cSrcweir sal_Int32 FindBlock( sal_Int32& nPages ); 55cdf0e10cSrcweir sal_Int32 GetNextPage( sal_Int32 nPg ); 56cdf0e10cSrcweir sal_Int32 AllocPages( sal_Int32 nStart, sal_Int32 nPages ); 57cdf0e10cSrcweir sal_Bool FreePages( sal_Int32 nStart, sal_Bool bAll ); GetMaxPage()58cdf0e10cSrcweir sal_Int32 GetMaxPage() { return nMaxPage; } SetLimit(sal_Int32 n)59cdf0e10cSrcweir void SetLimit( sal_Int32 n ) { nLimit = n; } 60cdf0e10cSrcweir }; 61cdf0e10cSrcweir 62cdf0e10cSrcweir // The base stream class provides basic functionality for seeking 63cdf0e10cSrcweir // and accessing the data on a physical basis. It uses the built-in 64cdf0e10cSrcweir // FAT class for the page allocations. 65cdf0e10cSrcweir 66cdf0e10cSrcweir class StgStrm { // base class for all streams 67cdf0e10cSrcweir protected: 68cdf0e10cSrcweir StgIo& rIo; // I/O system 69cdf0e10cSrcweir StgFAT* pFat; // FAT stream for allocations 70cdf0e10cSrcweir StgDirEntry* pEntry; // dir entry (for ownership) 71cdf0e10cSrcweir sal_Int32 nStart; // 1st data page 72cdf0e10cSrcweir sal_Int32 nSize; // stream size in bytes 73cdf0e10cSrcweir sal_Int32 nPos; // current byte position 74cdf0e10cSrcweir sal_Int32 nPage; // current logical page 75cdf0e10cSrcweir short nOffset; // offset into current page 76cdf0e10cSrcweir short nPageSize; // logical page size 77cdf0e10cSrcweir sal_Bool Copy( sal_Int32 nFrom, sal_Int32 nBytes ); 78cdf0e10cSrcweir StgStrm( StgIo& ); 79cdf0e10cSrcweir public: 80cdf0e10cSrcweir virtual ~StgStrm(); GetIo()81cdf0e10cSrcweir StgIo& GetIo() { return rIo; } GetPos()82cdf0e10cSrcweir sal_Int32 GetPos() { return nPos; } GetStart()83cdf0e10cSrcweir sal_Int32 GetStart() { return nStart; } GetSize()84cdf0e10cSrcweir sal_Int32 GetSize() { return nSize; } GetPage()85cdf0e10cSrcweir sal_Int32 GetPage() { return nPage; } GetPageSize()86cdf0e10cSrcweir short GetPageSize() { return nPageSize; } 87cdf0e10cSrcweir sal_Int32 GetPages(); GetOffset()88cdf0e10cSrcweir short GetOffset() { return nOffset;} 89cdf0e10cSrcweir void SetEntry( StgDirEntry& ); 90cdf0e10cSrcweir virtual sal_Bool SetSize( sal_Int32 ); 91cdf0e10cSrcweir virtual sal_Bool Pos2Page( sal_Int32 nBytePos ); Read(void *,sal_Int32)92cdf0e10cSrcweir virtual sal_Int32 Read( void*, sal_Int32 ) { return 0; } Write(const void *,sal_Int32)93cdf0e10cSrcweir virtual sal_Int32 Write( const void*, sal_Int32 ) { return 0; } 94cdf0e10cSrcweir virtual StgPage* GetPhysPage( sal_Int32 nBytePos, sal_Bool bForce = sal_False ); IsSmallStrm()95cdf0e10cSrcweir virtual sal_Bool IsSmallStrm() { return sal_False; } 96cdf0e10cSrcweir }; 97cdf0e10cSrcweir 98cdf0e10cSrcweir // The FAT stream class provides physical access to the master FAT. 99cdf0e10cSrcweir // Since this access is implemented as a StgStrm, we can use the 100cdf0e10cSrcweir // FAT allocator. 101cdf0e10cSrcweir 102cdf0e10cSrcweir class StgFATStrm : public StgStrm { // the master FAT stream 103cdf0e10cSrcweir virtual sal_Bool Pos2Page( sal_Int32 nBytePos ); 104cdf0e10cSrcweir sal_Bool SetPage( short, sal_Int32 ); 105cdf0e10cSrcweir public: 106cdf0e10cSrcweir StgFATStrm( StgIo& ); ~StgFATStrm()107cdf0e10cSrcweir virtual ~StgFATStrm() {} 108cdf0e10cSrcweir using StgStrm::GetPage; 109cdf0e10cSrcweir sal_Int32 GetPage( short, sal_Bool, sal_uInt16 *pnMasterAlloc = 0); 110cdf0e10cSrcweir virtual sal_Bool SetSize( sal_Int32 ); 111cdf0e10cSrcweir virtual StgPage* GetPhysPage( sal_Int32 nBytePos, sal_Bool bForce = sal_False ); 112cdf0e10cSrcweir }; 113cdf0e10cSrcweir 114cdf0e10cSrcweir // The stream has a size increment which normally is 1, but which can be 115cdf0e10cSrcweir // set to any value is you want the size to be incremented by certain values. 116cdf0e10cSrcweir 117cdf0e10cSrcweir class StgDataStrm : public StgStrm // a physical data stream 118cdf0e10cSrcweir { 119cdf0e10cSrcweir short nIncr; // size adjust increment 120cdf0e10cSrcweir void Init( sal_Int32 nBgn, sal_Int32 nLen ); 121cdf0e10cSrcweir public: 122cdf0e10cSrcweir StgDataStrm( StgIo&, sal_Int32 nBgn, sal_Int32 nLen=-1 ); 123*297a844aSArmin Le Grand StgDataStrm( StgIo&, StgDirEntry& ); 124cdf0e10cSrcweir void* GetPtr( sal_Int32 nPos, sal_Bool bForce, sal_Bool bDirty ); SetIncrement(short n)125cdf0e10cSrcweir void SetIncrement( short n ) { nIncr = n ; } 126cdf0e10cSrcweir virtual sal_Bool SetSize( sal_Int32 ); 127cdf0e10cSrcweir virtual sal_Int32 Read( void*, sal_Int32 ); 128cdf0e10cSrcweir virtual sal_Int32 Write( const void*, sal_Int32 ); 129cdf0e10cSrcweir }; 130cdf0e10cSrcweir 131cdf0e10cSrcweir // The small stream class provides access to streams with a size < 4096 bytes. 132cdf0e10cSrcweir // This stream is a StgStream containing small pages. The FAT for this stream 133cdf0e10cSrcweir // is also a StgStream. The start of the FAT is in the header at DataRootPage, 134cdf0e10cSrcweir // the stream itself is pointed to by the root entry (it holds start & size). 135cdf0e10cSrcweir 136cdf0e10cSrcweir class StgSmallStrm : public StgStrm // a logical data stream 137cdf0e10cSrcweir { 138cdf0e10cSrcweir StgStrm* pData; // the data stream 139cdf0e10cSrcweir void Init( sal_Int32 nBgn, sal_Int32 nLen ); 140cdf0e10cSrcweir public: 141cdf0e10cSrcweir StgSmallStrm( StgIo&, sal_Int32 nBgn, sal_Int32 nLen ); 142*297a844aSArmin Le Grand StgSmallStrm( StgIo&, StgDirEntry& ); 143cdf0e10cSrcweir virtual sal_Int32 Read( void*, sal_Int32 ); 144cdf0e10cSrcweir virtual sal_Int32 Write( const void*, sal_Int32 ); IsSmallStrm()145cdf0e10cSrcweir virtual sal_Bool IsSmallStrm() { return sal_True; } 146cdf0e10cSrcweir }; 147cdf0e10cSrcweir 148cdf0e10cSrcweir class StgTmpStrm : public SvMemoryStream 149cdf0e10cSrcweir { 150cdf0e10cSrcweir String aName; 151cdf0e10cSrcweir SvFileStream* pStrm; 152cdf0e10cSrcweir using SvMemoryStream::GetData; 153cdf0e10cSrcweir virtual sal_uLong GetData( void* pData, sal_uLong nSize ); 154cdf0e10cSrcweir virtual sal_uLong PutData( const void* pData, sal_uLong nSize ); 155cdf0e10cSrcweir virtual sal_uLong SeekPos( sal_uLong nPos ); 156cdf0e10cSrcweir virtual void FlushData(); 157cdf0e10cSrcweir 158cdf0e10cSrcweir public: 159cdf0e10cSrcweir StgTmpStrm( sal_uLong=16 ); 160cdf0e10cSrcweir ~StgTmpStrm(); 161cdf0e10cSrcweir sal_Bool Copy( StgTmpStrm& ); 162cdf0e10cSrcweir void SetSize( sal_uLong ); 163cdf0e10cSrcweir sal_uLong GetSize() const; 164cdf0e10cSrcweir }; 165cdf0e10cSrcweir 166cdf0e10cSrcweir #endif 167