1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef _STGDIR_HXX 29*cdf0e10cSrcweir #define _STGDIR_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "stgavl.hxx" 32*cdf0e10cSrcweir #include "stgelem.hxx" 33*cdf0e10cSrcweir #include "stgstrms.hxx" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir class StgIo; 36*cdf0e10cSrcweir class StgEntry; 37*cdf0e10cSrcweir class StgDirEntry; 38*cdf0e10cSrcweir class StgDirStrm; 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir class BaseStorageStream; 41*cdf0e10cSrcweir class StgDirEntry : public StgAvlNode 42*cdf0e10cSrcweir { 43*cdf0e10cSrcweir friend class StgIterator; 44*cdf0e10cSrcweir friend class StgDirStrm; 45*cdf0e10cSrcweir StgEntry aSave; // original dir entry 46*cdf0e10cSrcweir StgDirEntry* pUp; // parent directory 47*cdf0e10cSrcweir StgDirEntry* pDown; // child directory for storages 48*cdf0e10cSrcweir StgDirEntry** ppRoot; // root of TOC tree 49*cdf0e10cSrcweir StgStrm* pStgStrm; // storage stream 50*cdf0e10cSrcweir StgTmpStrm* pTmpStrm; // temporary stream 51*cdf0e10cSrcweir StgTmpStrm* pCurStrm; // temp stream after commit 52*cdf0e10cSrcweir sal_Int32 nEntry; // entry # in TOC stream (temp) 53*cdf0e10cSrcweir sal_Int32 nPos; // current position 54*cdf0e10cSrcweir sal_Bool bDirty; // dirty directory entry 55*cdf0e10cSrcweir sal_Bool bCreated; // newly created entry 56*cdf0e10cSrcweir sal_Bool bRemoved; // removed per Invalidate() 57*cdf0e10cSrcweir sal_Bool bRenamed; // renamed 58*cdf0e10cSrcweir void InitMembers(); // ctor helper 59*cdf0e10cSrcweir virtual short Compare( const StgAvlNode* ) const; 60*cdf0e10cSrcweir sal_Bool StoreStream( StgIo& ); // store the stream 61*cdf0e10cSrcweir sal_Bool StoreStreams( StgIo& ); // store all streams 62*cdf0e10cSrcweir void RevertAll(); // revert the whole tree 63*cdf0e10cSrcweir sal_Bool Strm2Tmp(); // copy stgstream to temp file 64*cdf0e10cSrcweir sal_Bool Tmp2Strm(); // copy temp file to stgstream 65*cdf0e10cSrcweir public: 66*cdf0e10cSrcweir StgEntry aEntry; // entry data 67*cdf0e10cSrcweir sal_Int32 nRefCnt; // reference count 68*cdf0e10cSrcweir StreamMode nMode; // open mode 69*cdf0e10cSrcweir sal_Bool bTemp; // sal_True: delete on dir flush 70*cdf0e10cSrcweir sal_Bool bDirect; // sal_True: direct mode 71*cdf0e10cSrcweir sal_Bool bZombie; // sal_True: Removed From StgIo 72*cdf0e10cSrcweir sal_Bool bInvalid; // sal_True: invalid entry 73*cdf0e10cSrcweir StgDirEntry( const void*, sal_Bool * pbOk ); 74*cdf0e10cSrcweir StgDirEntry( const StgEntry& ); 75*cdf0e10cSrcweir ~StgDirEntry(); 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir void Invalidate( sal_Bool=sal_False ); // invalidate all open entries 78*cdf0e10cSrcweir void Enum( sal_Int32& ); // enumerate entries for iteration 79*cdf0e10cSrcweir void DelTemp( sal_Bool ); // delete temporary entries 80*cdf0e10cSrcweir sal_Bool Store( StgDirStrm& ); // save entry into dir strm 81*cdf0e10cSrcweir sal_Bool IsContained( StgDirEntry* ); // check if subentry 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir void SetDirty() { bDirty = sal_True; } 84*cdf0e10cSrcweir sal_Bool IsDirty(); 85*cdf0e10cSrcweir void ClearDirty(); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir sal_Bool Commit(); 88*cdf0e10cSrcweir sal_Bool Revert(); 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir void OpenStream( StgIo&, sal_Bool=sal_False ); // set up an approbiate stream 91*cdf0e10cSrcweir void Close(); 92*cdf0e10cSrcweir sal_Int32 GetSize(); 93*cdf0e10cSrcweir sal_Bool SetSize( sal_Int32 ); 94*cdf0e10cSrcweir sal_Int32 Seek( sal_Int32 ); 95*cdf0e10cSrcweir sal_Int32 Tell() { return nPos; } 96*cdf0e10cSrcweir sal_Int32 Read( void*, sal_Int32 ); 97*cdf0e10cSrcweir sal_Int32 Write( const void*, sal_Int32 ); 98*cdf0e10cSrcweir void Copy( StgDirEntry& ); 99*cdf0e10cSrcweir void Copy( BaseStorageStream& ); 100*cdf0e10cSrcweir }; 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir class StgDirStrm : public StgDataStrm 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir friend class StgIterator; 105*cdf0e10cSrcweir StgDirEntry* pRoot; // root of dir tree 106*cdf0e10cSrcweir short nEntries; // entries per page 107*cdf0e10cSrcweir void SetupEntry( sal_Int32, StgDirEntry* ); 108*cdf0e10cSrcweir public: 109*cdf0e10cSrcweir StgDirStrm( StgIo& ); 110*cdf0e10cSrcweir ~StgDirStrm(); 111*cdf0e10cSrcweir virtual sal_Bool SetSize( sal_Int32 ); // change the size 112*cdf0e10cSrcweir sal_Bool Store(); 113*cdf0e10cSrcweir void* GetEntry( sal_Int32 n, sal_Bool=sal_False );// get an entry 114*cdf0e10cSrcweir StgDirEntry* GetRoot() { return pRoot; } 115*cdf0e10cSrcweir StgDirEntry* Find( StgDirEntry&, const String& ); 116*cdf0e10cSrcweir StgDirEntry* Create( StgDirEntry&, const String&, StgEntryType ); 117*cdf0e10cSrcweir sal_Bool Remove( StgDirEntry&, const String& ); 118*cdf0e10cSrcweir sal_Bool Rename( StgDirEntry&, const String&, const String& ); 119*cdf0e10cSrcweir sal_Bool Move( StgDirEntry&, StgDirEntry&, const String& ); 120*cdf0e10cSrcweir }; 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir class StgIterator : public StgAvlIterator 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir public: 125*cdf0e10cSrcweir StgIterator( StgDirEntry& rStg ) : StgAvlIterator( rStg.pDown ) {} 126*cdf0e10cSrcweir StgDirEntry* First() { return (StgDirEntry*) StgAvlIterator::First(); } 127*cdf0e10cSrcweir StgDirEntry* Next() { return (StgDirEntry*) StgAvlIterator::Next(); } 128*cdf0e10cSrcweir StgDirEntry* Last() { return (StgDirEntry*) StgAvlIterator::Last(); } 129*cdf0e10cSrcweir StgDirEntry* Prev() { return (StgDirEntry*) StgAvlIterator::Prev(); } 130*cdf0e10cSrcweir }; 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir #endif 133