Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef _STGDIR_HXX
21 : #define _STGDIR_HXX
22 :
23 : #include "stgavl.hxx"
24 : #include "stgelem.hxx"
25 : #include "stgstrms.hxx"
26 :
27 : class StgIo;
28 : class StgEntry;
29 : class StgDirEntry;
30 : class StgDirStrm;
31 :
32 : class BaseStorageStream;
33 : class StgDirEntry : public StgAvlNode
34 : {
35 : friend class StgIterator;
36 : friend class StgDirStrm;
37 : StgEntry aSave; // original dir entry
38 : StgDirEntry* pUp; // parent directory
39 : StgDirEntry* pDown; // child directory for storages
40 : StgDirEntry** ppRoot; // root of TOC tree
41 : StgStrm* pStgStrm; // storage stream
42 : StgTmpStrm* pTmpStrm; // temporary stream
43 : StgTmpStrm* pCurStrm; // temp stream after commit
44 : sal_Int32 nEntry; // entry # in TOC stream (temp)
45 : sal_Int32 nPos; // current position
46 : sal_Bool bDirty; // dirty directory entry
47 : sal_Bool bCreated; // newly created entry
48 : sal_Bool bRemoved; // removed per Invalidate()
49 : sal_Bool bRenamed; // renamed
50 : void InitMembers(); // ctor helper
51 : virtual short Compare( const StgAvlNode* ) const;
52 : sal_Bool StoreStream( StgIo& ); // store the stream
53 : sal_Bool StoreStreams( StgIo& ); // store all streams
54 : void RevertAll(); // revert the whole tree
55 : sal_Bool Strm2Tmp(); // copy stgstream to temp file
56 : sal_Bool Tmp2Strm(); // copy temp file to stgstream
57 : public:
58 : StgEntry aEntry; // entry data
59 : sal_Int32 nRefCnt; // reference count
60 : StreamMode nMode; // open mode
61 : sal_Bool bTemp; // sal_True: delete on dir flush
62 : sal_Bool bDirect; // sal_True: direct mode
63 : sal_Bool bZombie; // sal_True: Removed From StgIo
64 : sal_Bool bInvalid; // sal_True: invalid entry
65 : StgDirEntry( const void* pBuffer, sal_uInt32 nBufferLen, sal_Bool * pbOk );
66 : StgDirEntry( const StgEntry& );
67 : ~StgDirEntry();
68 :
69 : void Invalidate( sal_Bool=sal_False ); // invalidate all open entries
70 : void Enum( sal_Int32& ); // enumerate entries for iteration
71 : void DelTemp( sal_Bool ); // delete temporary entries
72 : sal_Bool Store( StgDirStrm& ); // save entry into dir strm
73 : sal_Bool IsContained( StgDirEntry* ); // check if subentry
74 :
75 3830 : void SetDirty() { bDirty = sal_True; }
76 : sal_Bool IsDirty();
77 : void ClearDirty();
78 :
79 : sal_Bool Commit();
80 : sal_Bool Revert();
81 :
82 : void OpenStream( StgIo&, sal_Bool=sal_False ); // set up an approbiate stream
83 : void Close();
84 : sal_Int32 GetSize();
85 : sal_Bool SetSize( sal_Int32 );
86 : sal_Int32 Seek( sal_Int32 );
87 : sal_Int32 Tell() { return nPos; }
88 : sal_Int32 Read( void*, sal_Int32 );
89 : sal_Int32 Write( const void*, sal_Int32 );
90 : void Copy( BaseStorageStream& );
91 : };
92 :
93 : class StgDirStrm : public StgDataStrm
94 : {
95 : friend class StgIterator;
96 : StgDirEntry* pRoot; // root of dir tree
97 : short nEntries; // entries per page
98 : void SetupEntry( sal_Int32, StgDirEntry* );
99 : public:
100 : StgDirStrm( StgIo& );
101 : ~StgDirStrm();
102 : virtual sal_Bool SetSize( sal_Int32 ); // change the size
103 : sal_Bool Store();
104 : void* GetEntry( sal_Int32 n, sal_Bool=sal_False );// get an entry
105 198 : StgDirEntry* GetRoot() { return pRoot; }
106 : StgDirEntry* Find( StgDirEntry&, const String& );
107 : StgDirEntry* Create( StgDirEntry&, const String&, StgEntryType );
108 : sal_Bool Remove( StgDirEntry&, const String& );
109 : sal_Bool Rename( StgDirEntry&, const String&, const String& );
110 : sal_Bool Move( StgDirEntry&, StgDirEntry&, const String& );
111 : };
112 :
113 : class StgIterator : public StgAvlIterator
114 : {
115 : public:
116 401 : StgIterator( StgDirEntry& rStg ) : StgAvlIterator( rStg.pDown ) {}
117 401 : StgDirEntry* First() { return (StgDirEntry*) StgAvlIterator::First(); }
118 3000 : StgDirEntry* Next() { return (StgDirEntry*) StgAvlIterator::Next(); }
119 : };
120 :
121 : #endif
122 :
123 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|