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 _STGDIR_HXX 25cdf0e10cSrcweir #define _STGDIR_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "stgavl.hxx" 28cdf0e10cSrcweir #include "stgelem.hxx" 29cdf0e10cSrcweir #include "stgstrms.hxx" 30cdf0e10cSrcweir 31cdf0e10cSrcweir class StgIo; 32cdf0e10cSrcweir class StgEntry; 33cdf0e10cSrcweir class StgDirEntry; 34cdf0e10cSrcweir class StgDirStrm; 35cdf0e10cSrcweir 36cdf0e10cSrcweir class BaseStorageStream; 37cdf0e10cSrcweir class StgDirEntry : public StgAvlNode 38cdf0e10cSrcweir { 39cdf0e10cSrcweir friend class StgIterator; 40cdf0e10cSrcweir friend class StgDirStrm; 41cdf0e10cSrcweir StgEntry aSave; // original dir entry 42cdf0e10cSrcweir StgDirEntry* pUp; // parent directory 43cdf0e10cSrcweir StgDirEntry* pDown; // child directory for storages 44cdf0e10cSrcweir StgDirEntry** ppRoot; // root of TOC tree 45cdf0e10cSrcweir StgStrm* pStgStrm; // storage stream 46cdf0e10cSrcweir StgTmpStrm* pTmpStrm; // temporary stream 47cdf0e10cSrcweir StgTmpStrm* pCurStrm; // temp stream after commit 48cdf0e10cSrcweir sal_Int32 nEntry; // entry # in TOC stream (temp) 49cdf0e10cSrcweir sal_Int32 nPos; // current position 50cdf0e10cSrcweir sal_Bool bDirty; // dirty directory entry 51cdf0e10cSrcweir sal_Bool bCreated; // newly created entry 52cdf0e10cSrcweir sal_Bool bRemoved; // removed per Invalidate() 53cdf0e10cSrcweir sal_Bool bRenamed; // renamed 54cdf0e10cSrcweir void InitMembers(); // ctor helper 55cdf0e10cSrcweir virtual short Compare( const StgAvlNode* ) const; 56cdf0e10cSrcweir sal_Bool StoreStream( StgIo& ); // store the stream 57cdf0e10cSrcweir sal_Bool StoreStreams( StgIo& ); // store all streams 58cdf0e10cSrcweir void RevertAll(); // revert the whole tree 59cdf0e10cSrcweir sal_Bool Strm2Tmp(); // copy stgstream to temp file 60cdf0e10cSrcweir sal_Bool Tmp2Strm(); // copy temp file to stgstream 61cdf0e10cSrcweir public: 62cdf0e10cSrcweir StgEntry aEntry; // entry data 63cdf0e10cSrcweir sal_Int32 nRefCnt; // reference count 64cdf0e10cSrcweir StreamMode nMode; // open mode 65cdf0e10cSrcweir sal_Bool bTemp; // sal_True: delete on dir flush 66cdf0e10cSrcweir sal_Bool bDirect; // sal_True: direct mode 67cdf0e10cSrcweir sal_Bool bZombie; // sal_True: Removed From StgIo 68cdf0e10cSrcweir sal_Bool bInvalid; // sal_True: invalid entry 69297a844aSArmin Le Grand StgDirEntry( const void* pBuffer, sal_uInt32 nBufferLen, sal_Bool * pbOk ); 70cdf0e10cSrcweir StgDirEntry( const StgEntry& ); 71cdf0e10cSrcweir ~StgDirEntry(); 72cdf0e10cSrcweir 73cdf0e10cSrcweir void Invalidate( sal_Bool=sal_False ); // invalidate all open entries 74cdf0e10cSrcweir void Enum( sal_Int32& ); // enumerate entries for iteration 75cdf0e10cSrcweir void DelTemp( sal_Bool ); // delete temporary entries 76cdf0e10cSrcweir sal_Bool Store( StgDirStrm& ); // save entry into dir strm 77cdf0e10cSrcweir sal_Bool IsContained( StgDirEntry* ); // check if subentry 78cdf0e10cSrcweir SetDirty()79cdf0e10cSrcweir void SetDirty() { bDirty = sal_True; } 80cdf0e10cSrcweir sal_Bool IsDirty(); 81cdf0e10cSrcweir void ClearDirty(); 82cdf0e10cSrcweir 83cdf0e10cSrcweir sal_Bool Commit(); 84cdf0e10cSrcweir sal_Bool Revert(); 85cdf0e10cSrcweir 86cdf0e10cSrcweir void OpenStream( StgIo&, sal_Bool=sal_False ); // set up an approbiate stream 87cdf0e10cSrcweir void Close(); 88cdf0e10cSrcweir sal_Int32 GetSize(); 89cdf0e10cSrcweir sal_Bool SetSize( sal_Int32 ); 90cdf0e10cSrcweir sal_Int32 Seek( sal_Int32 ); Tell()91cdf0e10cSrcweir sal_Int32 Tell() { return nPos; } 92cdf0e10cSrcweir sal_Int32 Read( void*, sal_Int32 ); 93cdf0e10cSrcweir sal_Int32 Write( const void*, sal_Int32 ); 94cdf0e10cSrcweir void Copy( StgDirEntry& ); 95cdf0e10cSrcweir void Copy( BaseStorageStream& ); 96cdf0e10cSrcweir }; 97cdf0e10cSrcweir 98cdf0e10cSrcweir class StgDirStrm : public StgDataStrm 99cdf0e10cSrcweir { 100cdf0e10cSrcweir friend class StgIterator; 101cdf0e10cSrcweir StgDirEntry* pRoot; // root of dir tree 102cdf0e10cSrcweir short nEntries; // entries per page 103*cbcf3648SJürgen Schmidt void SetupEntry( 104*cbcf3648SJürgen Schmidt const sal_Int32 n, 105*cbcf3648SJürgen Schmidt StgDirEntry* pUpper, 106*cbcf3648SJürgen Schmidt const sal_Int32 nEntryCount, 107*cbcf3648SJürgen Schmidt const sal_Int32 nDepth); 108*cbcf3648SJürgen Schmidt public: 109cdf0e10cSrcweir StgDirStrm( StgIo& ); 110cdf0e10cSrcweir ~StgDirStrm(); 111cdf0e10cSrcweir virtual sal_Bool SetSize( sal_Int32 ); // change the size 112cdf0e10cSrcweir sal_Bool Store(); 113cdf0e10cSrcweir void* GetEntry( sal_Int32 n, sal_Bool=sal_False );// get an entry GetRoot()114cdf0e10cSrcweir StgDirEntry* GetRoot() { return pRoot; } 115cdf0e10cSrcweir StgDirEntry* Find( StgDirEntry&, const String& ); 116cdf0e10cSrcweir StgDirEntry* Create( StgDirEntry&, const String&, StgEntryType ); 117cdf0e10cSrcweir sal_Bool Remove( StgDirEntry&, const String& ); 118cdf0e10cSrcweir sal_Bool Rename( StgDirEntry&, const String&, const String& ); 119cdf0e10cSrcweir sal_Bool Move( StgDirEntry&, StgDirEntry&, const String& ); 120cdf0e10cSrcweir }; 121cdf0e10cSrcweir 122cdf0e10cSrcweir class StgIterator : public StgAvlIterator 123cdf0e10cSrcweir { 124cdf0e10cSrcweir public: StgIterator(StgDirEntry & rStg)125cdf0e10cSrcweir StgIterator( StgDirEntry& rStg ) : StgAvlIterator( rStg.pDown ) {} First()126cdf0e10cSrcweir StgDirEntry* First() { return (StgDirEntry*) StgAvlIterator::First(); } Next()127cdf0e10cSrcweir StgDirEntry* Next() { return (StgDirEntry*) StgAvlIterator::Next(); } Last()128cdf0e10cSrcweir StgDirEntry* Last() { return (StgDirEntry*) StgAvlIterator::Last(); } Prev()129cdf0e10cSrcweir StgDirEntry* Prev() { return (StgDirEntry*) StgAvlIterator::Prev(); } 130cdf0e10cSrcweir }; 131cdf0e10cSrcweir 132cdf0e10cSrcweir #endif 133