bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / sot / stg.hxx
blobd692403b9a72720b28322558ad18a41b8195f660
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SOT_STG_HXX
21 #define INCLUDED_SOT_STG_HXX
23 #include <tools/solar.h>
24 #include <tools/stream.hxx>
25 #include <tools/globname.hxx>
26 #include <sot/storinfo.hxx>
27 #include <sot/sotdllapi.h>
29 namespace com { namespace sun { namespace star { namespace ucb { class XProgressHandler; } } } }
30 namespace com { namespace sun { namespace star { namespace uno { class Any; } } } }
31 namespace com { namespace sun { namespace star { namespace uno { template <typename > class Reference; } } } }
33 class StgIo;
34 class StgDirEntry;
35 typedef struct SvGUID ClsId;
37 class SOT_DLLPUBLIC StorageBase : public SvRefBase
39 protected:
40 mutable ErrCode m_nError; // error code
41 StreamMode m_nMode; // open mode
42 bool m_bAutoCommit;
43 StorageBase();
44 virtual ~StorageBase() override;
45 public:
46 virtual bool Validate( bool=false ) const = 0;
47 virtual bool ValidateMode( StreamMode ) const = 0;
48 void ResetError() const;
49 void SetError( ErrCode ) const;
50 ErrCode GetError() const;
51 bool Good() const { return m_nError == ERRCODE_NONE; }
52 StreamMode GetMode() const { return m_nMode; }
53 void SetAutoCommit( bool bSet )
54 { m_bAutoCommit = bSet; }
57 class BaseStorageStream : public StorageBase
59 public:
60 virtual sal_uLong Read( void * pData, sal_uLong nSize ) = 0;
61 virtual sal_uLong Write( const void* pData, sal_uLong nSize ) = 0;
62 virtual sal_uInt64 Seek( sal_uInt64 nPos ) = 0;
63 virtual sal_uLong Tell() = 0;
64 virtual void Flush() = 0;
65 virtual bool SetSize( sal_uLong nNewSize ) = 0;
66 virtual sal_uLong GetSize() const = 0;
67 virtual void CopyTo( BaseStorageStream * pDestStm ) = 0;
68 virtual bool Commit() = 0;
69 virtual bool Equals( const BaseStorageStream& rStream ) const = 0;
72 enum class SotClipboardFormatId : sal_uInt32;
74 class SAL_DLLPUBLIC_RTTI BaseStorage : public StorageBase
76 public:
77 virtual const OUString& GetName() const = 0;
78 virtual bool IsRoot() const = 0;
79 virtual void SetClassId( const ClsId& ) = 0;
80 virtual const ClsId& GetClassId() const = 0;
81 virtual void SetDirty() = 0;
82 virtual void SetClass( const SvGlobalName & rClass,
83 SotClipboardFormatId nOriginalClipFormat,
84 const OUString & rUserTypeName ) = 0;
85 virtual SvGlobalName GetClassName() = 0;
86 virtual SotClipboardFormatId GetFormat() = 0;
87 virtual OUString GetUserName() = 0;
88 virtual void FillInfoList( SvStorageInfoList* ) const = 0;
89 virtual bool CopyTo( BaseStorage* pDestStg ) const = 0;
90 virtual bool Commit() = 0;
91 virtual bool Revert() = 0;
92 virtual BaseStorageStream* OpenStream( const OUString & rEleName,
93 StreamMode = StreamMode::STD_READWRITE,
94 bool bDirect = true ) = 0;
95 virtual BaseStorage* OpenStorage( const OUString & rEleName,
96 StreamMode = StreamMode::STD_READWRITE,
97 bool bDirect = false ) = 0;
98 virtual BaseStorage* OpenUCBStorage( const OUString & rEleName,
99 StreamMode = StreamMode::STD_READWRITE,
100 bool bDirect = false ) = 0;
101 virtual BaseStorage* OpenOLEStorage( const OUString & rEleName,
102 StreamMode = StreamMode::STD_READWRITE,
103 bool bDirect = false ) = 0;
104 virtual bool IsStream( const OUString& rEleName ) const = 0;
105 virtual bool IsStorage( const OUString& rEleName ) const = 0;
106 virtual bool IsContained( const OUString& rEleName ) const = 0;
107 virtual void Remove( const OUString & rEleName ) = 0;
108 virtual bool CopyTo( const OUString & rEleName, BaseStorage * pDest, const OUString & rNewName ) = 0;
109 virtual bool ValidateFAT() = 0;
110 virtual bool Equals( const BaseStorage& rStream ) const = 0;
113 class OLEStorageBase
115 protected:
116 StreamMode& nStreamMode; // open mode
117 StgIo* pIo; // I/O subsystem
118 StgDirEntry* pEntry; // the dir entry
119 OLEStorageBase( StgIo*, StgDirEntry*, StreamMode& );
120 ~OLEStorageBase();
121 bool Validate_Impl( bool ) const;
122 static bool ValidateMode_Impl( StreamMode, StgDirEntry const * p = nullptr );
125 class StorageStream : public BaseStorageStream, public OLEStorageBase
127 //friend class Storage;
128 sal_uLong nPos; // current position
129 protected:
130 virtual ~StorageStream() override;
131 public:
132 StorageStream( StgIo*, StgDirEntry*, StreamMode );
133 virtual sal_uLong Read( void * pData, sal_uLong nSize ) override;
134 virtual sal_uLong Write( const void* pData, sal_uLong nSize ) override;
135 virtual sal_uInt64 Seek( sal_uInt64 nPos ) override;
136 virtual sal_uLong Tell() override { return nPos; }
137 virtual void Flush() override;
138 virtual bool SetSize( sal_uLong nNewSize ) override;
139 virtual sal_uLong GetSize() const override;
140 virtual void CopyTo( BaseStorageStream * pDestStm ) override;
141 virtual bool Commit() final override;
142 virtual bool Validate( bool=false ) const override;
143 virtual bool ValidateMode( StreamMode ) const override;
144 virtual bool Equals( const BaseStorageStream& rStream ) const override;
147 class UCBStorageStream;
149 class SOT_DLLPUBLIC Storage : public BaseStorage, public OLEStorageBase
151 OUString aName;
152 bool bIsRoot;
153 void Init( bool bCreate );
154 Storage( StgIo*, StgDirEntry*, StreamMode );
155 protected:
156 virtual ~Storage() override;
157 public:
158 Storage( const OUString &, StreamMode, bool bDirect );
159 Storage( SvStream& rStrm, bool bDirect );
160 Storage( UCBStorageStream& rStrm, bool bDirect );
162 static bool IsStorageFile( const OUString & rFileName );
163 static bool IsStorageFile( SvStream* );
165 virtual const OUString& GetName() const final override;
166 virtual bool IsRoot() const override { return bIsRoot; }
167 virtual void SetClassId( const ClsId& ) override;
168 virtual const ClsId& GetClassId() const override;
169 virtual void SetDirty() override;
170 virtual void SetClass( const SvGlobalName & rClass,
171 SotClipboardFormatId nOriginalClipFormat,
172 const OUString & rUserTypeName ) override;
173 virtual SvGlobalName GetClassName() override;
174 virtual SotClipboardFormatId GetFormat() override;
175 virtual OUString GetUserName() override;
176 virtual void FillInfoList( SvStorageInfoList* ) const override;
177 virtual bool CopyTo( BaseStorage* pDestStg ) const override;
178 virtual bool Commit() final override;
179 virtual bool Revert() override;
180 virtual BaseStorageStream* OpenStream( const OUString & rEleName,
181 StreamMode = StreamMode::STD_READWRITE,
182 bool bDirect = true ) override;
183 virtual BaseStorage* OpenStorage( const OUString & rEleName,
184 StreamMode = StreamMode::STD_READWRITE,
185 bool bDirect = false ) override;
186 virtual BaseStorage* OpenUCBStorage( const OUString & rEleName,
187 StreamMode = StreamMode::STD_READWRITE,
188 bool bDirect = false ) override;
189 virtual BaseStorage* OpenOLEStorage( const OUString & rEleName,
190 StreamMode = StreamMode::STD_READWRITE,
191 bool bDirect = false ) override;
192 virtual bool IsStream( const OUString& rEleName ) const override;
193 virtual bool IsStorage( const OUString& rEleName ) const override;
194 virtual bool IsContained( const OUString& rEleName ) const override;
195 virtual void Remove( const OUString & rEleName ) override;
196 virtual bool CopyTo( const OUString & rEleName, BaseStorage * pDest, const OUString & rNewName ) override;
197 virtual bool ValidateFAT() override;
198 virtual bool Validate( bool=false ) const override;
199 virtual bool ValidateMode( StreamMode ) const override;
200 bool ValidateMode( StreamMode, StgDirEntry const * p ) const;
201 virtual bool Equals( const BaseStorage& rStream ) const override;
204 class UCBStorageStream_Impl;
205 class UCBStorageStream : public BaseStorageStream
207 friend class UCBStorage;
209 UCBStorageStream_Impl*
210 pImp;
211 protected:
212 virtual ~UCBStorageStream() override;
213 public:
214 UCBStorageStream( const OUString& rName, StreamMode nMode, bool bDirect, bool bRepair, css::uno::Reference< css::ucb::XProgressHandler > const & xProgress );
215 UCBStorageStream( UCBStorageStream_Impl* );
217 virtual sal_uLong Read( void * pData, sal_uLong nSize ) override;
218 virtual sal_uLong Write( const void* pData, sal_uLong nSize ) override;
219 virtual sal_uInt64 Seek( sal_uInt64 nPos ) override;
220 virtual sal_uLong Tell() override;
221 virtual void Flush() override;
222 virtual bool SetSize( sal_uLong nNewSize ) override;
223 virtual sal_uLong GetSize() const override;
224 virtual void CopyTo( BaseStorageStream * pDestStm ) override;
225 virtual bool Commit() override;
226 virtual bool Validate( bool=false ) const override;
227 virtual bool ValidateMode( StreamMode ) const override;
228 virtual bool Equals( const BaseStorageStream& rStream ) const override;
229 bool SetProperty( const OUString& rName, const css::uno::Any& rValue );
231 SvStream* GetModifySvStream();
234 namespace ucbhelper
236 class Content;
239 class UCBStorage_Impl;
240 struct UCBStorageElement_Impl;
241 class SOT_DLLPUBLIC UCBStorage : public BaseStorage
243 UCBStorage_Impl* pImp;
245 protected:
246 virtual ~UCBStorage() override;
247 public:
248 static bool IsStorageFile( SvStream* );
249 static OUString GetLinkedFile( SvStream& );
251 UCBStorage( const ::ucbhelper::Content& rContent,
252 const OUString& rName,
253 StreamMode nMode,
254 bool bDirect,
255 bool bIsRoot );
257 UCBStorage( const OUString& rName,
258 StreamMode nMode,
259 bool bDirect,
260 bool bIsRoot );
262 UCBStorage( const OUString& rName,
263 StreamMode nMode,
264 bool bDirect,
265 bool bIsRoot,
266 bool bIsRepair,
267 css::uno::Reference< css::ucb::XProgressHandler > const &
268 xProgressHandler );
270 UCBStorage( UCBStorage_Impl* );
272 UCBStorage( SvStream& rStrm, bool bDirect );
274 virtual const OUString& GetName() const override;
275 virtual bool IsRoot() const override;
276 virtual void SetClassId( const ClsId& ) override;
277 virtual const ClsId& GetClassId() const override;
278 virtual void SetDirty() override;
279 virtual void SetClass( const SvGlobalName & rClass,
280 SotClipboardFormatId nOriginalClipFormat,
281 const OUString & rUserTypeName ) override;
282 virtual SvGlobalName GetClassName() override;
283 virtual SotClipboardFormatId GetFormat() override;
284 virtual OUString GetUserName() override;
285 virtual void FillInfoList( SvStorageInfoList* ) const override;
286 virtual bool CopyTo( BaseStorage* pDestStg ) const override;
287 virtual bool Commit() final override;
288 virtual bool Revert() override;
289 virtual BaseStorageStream* OpenStream( const OUString & rEleName,
290 StreamMode = StreamMode::STD_READWRITE,
291 bool bDirect = true ) override;
292 virtual BaseStorage* OpenStorage( const OUString & rEleName,
293 StreamMode = StreamMode::STD_READWRITE,
294 bool bDirect = false ) override;
295 virtual BaseStorage* OpenUCBStorage( const OUString & rEleName,
296 StreamMode = StreamMode::STD_READWRITE,
297 bool bDirect = false ) override;
298 virtual BaseStorage* OpenOLEStorage( const OUString & rEleName,
299 StreamMode = StreamMode::STD_READWRITE,
300 bool bDirect = false ) override;
301 virtual bool IsStream( const OUString& rEleName ) const override;
302 virtual bool IsStorage( const OUString& rEleName ) const override;
303 virtual bool IsContained( const OUString& rEleName ) const override;
304 virtual void Remove( const OUString & rEleName ) override;
305 virtual bool CopyTo( const OUString & rEleName, BaseStorage * pDest, const OUString & rNewName ) override;
306 virtual bool ValidateFAT() override;
307 virtual bool Validate( bool=false ) const override;
308 virtual bool ValidateMode( StreamMode ) const override;
309 virtual bool Equals( const BaseStorage& rStream ) const override;
311 UCBStorageElement_Impl* FindElement_Impl( const OUString& rName ) const;
312 bool CopyStorageElement_Impl( UCBStorageElement_Impl const & rElement,
313 BaseStorage* pDest, const OUString& rNew ) const;
314 BaseStorage* OpenStorage_Impl( const OUString & rEleName,
315 StreamMode, bool bDirect, bool bForceUCBStorage );
319 #endif
321 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */