xref: /aoo4110/main/sot/source/sdstor/stgdir.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _STGDIR_HXX
25 #define _STGDIR_HXX
26 
27 #include "stgavl.hxx"
28 #include "stgelem.hxx"
29 #include "stgstrms.hxx"
30 
31 class StgIo;
32 class StgEntry;
33 class StgDirEntry;
34 class StgDirStrm;
35 
36 class BaseStorageStream;
37 class StgDirEntry : public StgAvlNode
38 {
39 	friend class StgIterator;
40 	friend class StgDirStrm;
41 	StgEntry	 aSave;						// original dir entry
42 	StgDirEntry*  pUp;						// parent directory
43 	StgDirEntry*  pDown;					// child directory for storages
44 	StgDirEntry** ppRoot;					// root of TOC tree
45     StgStrm*     pStgStrm; 	                // storage stream
46 	StgTmpStrm*	 pTmpStrm;					// temporary stream
47 	StgTmpStrm*  pCurStrm;					// temp stream after commit
48 	sal_Int32		 nEntry;					// entry # in TOC stream (temp)
49 	sal_Int32		 nPos;						// current position
50 	sal_Bool		 bDirty;					// dirty directory entry
51 	sal_Bool		 bCreated;					// newly created entry
52 	sal_Bool		 bRemoved;					// removed per Invalidate()
53 	sal_Bool		 bRenamed;					// renamed
54 	void		 InitMembers();				// ctor helper
55 	virtual short Compare( const StgAvlNode* ) const;
56 	sal_Bool		 StoreStream( StgIo& );		// store the stream
57 	sal_Bool		 StoreStreams( StgIo& );	// store all streams
58 	void		 RevertAll();				// revert the whole tree
59 	sal_Bool		 Strm2Tmp();				// copy stgstream to temp file
60 	sal_Bool		 Tmp2Strm();				// copy temp file to stgstream
61 public:
62 	StgEntry 	 aEntry;					// entry data
63 	sal_Int32  		 nRefCnt;					// reference count
64     StreamMode   nMode;             		// open mode
65 	sal_Bool		 bTemp;						// sal_True: delete on dir flush
66 	sal_Bool		 bDirect; 		  			// sal_True: direct mode
67 	sal_Bool         bZombie;                   // sal_True: Removed From StgIo
68 	sal_Bool		 bInvalid;					// sal_True: invalid entry
69 	StgDirEntry( const void* pBuffer, sal_uInt32 nBufferLen, sal_Bool * pbOk );
70 	StgDirEntry( const StgEntry& );
71 	~StgDirEntry();
72 
73 	void Invalidate( sal_Bool=sal_False ); 			// invalidate all open entries
74 	void Enum( sal_Int32& );					// enumerate entries for iteration
75 	void DelTemp( sal_Bool );					// delete temporary entries
76 	sal_Bool Store( StgDirStrm& );				// save entry into dir strm
77 	sal_Bool IsContained( StgDirEntry* );		// check if subentry
78 
SetDirty()79 	void SetDirty()  { bDirty = sal_True;     }
80 	sal_Bool IsDirty();
81 	void ClearDirty();
82 
83 	sal_Bool Commit();
84 	sal_Bool Revert();
85 
86 	void  OpenStream( StgIo&, sal_Bool=sal_False );		// set up an approbiate stream
87 	void  Close();
88 	sal_Int32 GetSize();
89 	sal_Bool  SetSize( sal_Int32 );
90 	sal_Int32 Seek( sal_Int32 );
Tell()91 	sal_Int32 Tell() { return nPos; }
92 	sal_Int32 Read( void*, sal_Int32 );
93 	sal_Int32 Write( const void*, sal_Int32 );
94 	void  Copy( StgDirEntry& );
95     void  Copy( BaseStorageStream& );
96 };
97 
98 class StgDirStrm : public StgDataStrm
99 {
100 	friend class StgIterator;
101 	StgDirEntry* pRoot;							// root of dir tree
102 	short 		 nEntries;						// entries per page
103     void SetupEntry(
104         const sal_Int32 n,
105         StgDirEntry* pUpper,
106         const sal_Int32 nEntryCount,
107         const sal_Int32 nDepth);
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
GetRoot()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:
StgIterator(StgDirEntry & rStg)125 	StgIterator( StgDirEntry& rStg ) : StgAvlIterator( rStg.pDown ) {}
First()126 	StgDirEntry* First() { return (StgDirEntry*) StgAvlIterator::First(); }
Next()127 	StgDirEntry* Next()  { return (StgDirEntry*) StgAvlIterator::Next();  }
Last()128 	StgDirEntry* Last()  { return (StgDirEntry*) StgAvlIterator::Last();  }
Prev()129 	StgDirEntry* Prev()  { return (StgDirEntry*) StgAvlIterator::Prev();  }
130 };
131 
132 #endif
133