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