Fix GNU C++ version check
[LibreOffice.git] / ucb / source / ucp / tdoc / tdoc_stgelems.hxx
blob6562ab7ffa477277fd4197edfbff0ec3c2a69fdc
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 #pragma once
22 #include <rtl/ref.hxx>
24 #include <cppuhelper/implbase.hxx>
26 #include <com/sun/star/embed/XStorage.hpp>
27 #include <com/sun/star/embed/XTransactedObject.hpp>
28 #include <com/sun/star/io/XOutputStream.hpp>
29 #include <com/sun/star/io/XStream.hpp>
30 #include <com/sun/star/io/XTruncate.hpp>
31 #include <com/sun/star/lang/XComponent.hpp>
32 #include <com/sun/star/uno/XAggregation.hpp>
34 #include "tdoc_storage.hxx"
36 #include <mutex>
38 namespace tdoc_ucp {
40 class OfficeDocumentsManager;
42 class ParentStorageHolder
44 public:
45 ParentStorageHolder(
46 css::uno::Reference< css::embed::XStorage > xParentStorage,
47 const OUString & rUri );
49 bool isParentARootStorage() const
50 { return m_bParentIsRootStorage; }
51 css::uno::Reference< css::embed::XStorage >
52 getParentStorage() const
54 std::scoped_lock aGuard( m_aMutex );
55 return m_xParentStorage;
57 void clearParentStorage()
59 std::scoped_lock aGuard( m_aMutex );
60 m_xParentStorage = nullptr;
63 private:
64 mutable std::mutex m_aMutex;
65 css::uno::Reference< css::embed::XStorage > m_xParentStorage;
66 bool m_bParentIsRootStorage;
70 typedef
71 cppu::WeakImplHelper<
72 css::embed::XStorage,
73 css::embed::XTransactedObject > StorageUNOBase;
75 class Storage : public StorageUNOBase, public ParentStorageHolder
77 public:
78 Storage(
79 const css::uno::Reference< css::uno::XComponentContext > & rxContext,
80 rtl::Reference< StorageElementFactory > xFactory,
81 const OUString & rUri,
82 const css::uno::Reference< css::embed::XStorage > & xParentStorage,
83 const css::uno::Reference< css::embed::XStorage > & xStorageToWrap );
84 virtual ~Storage() override;
86 // XInterface
87 virtual css::uno::Any SAL_CALL queryInterface(
88 const css::uno::Type& aType ) override;
89 virtual void SAL_CALL acquire()
90 noexcept override;
91 virtual void SAL_CALL release()
92 noexcept override;
94 // XTypeProvider (implemented by base, but needs to be overridden for
95 // delegating to aggregate)
96 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
97 getTypes() override;
98 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
99 getImplementationId() override;
101 // XComponent ( one of XStorage bases )
102 virtual void SAL_CALL
103 dispose() override;
104 virtual void SAL_CALL
105 addEventListener( const css::uno::Reference< css::lang::XEventListener > & xListener ) override;
106 virtual void SAL_CALL
107 removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
109 // XNameAccess ( one of XStorage bases )
110 virtual css::uno::Any SAL_CALL
111 getByName( const OUString& aName ) override;
112 virtual css::uno::Sequence< OUString > SAL_CALL
113 getElementNames() override;
114 virtual sal_Bool SAL_CALL
115 hasByName( const OUString& aName ) override;
117 // XElementAccess (base of XNameAccess)
118 virtual css::uno::Type SAL_CALL
119 getElementType() override;
120 virtual sal_Bool SAL_CALL
121 hasElements() override;
123 // XStorage
124 virtual void SAL_CALL
125 copyToStorage( const css::uno::Reference< css::embed::XStorage >& xDest ) override;
126 virtual css::uno::Reference< css::io::XStream > SAL_CALL
127 openStreamElement( const OUString& aStreamName,
128 sal_Int32 nOpenMode ) override;
129 virtual css::uno::Reference< css::io::XStream > SAL_CALL
130 openEncryptedStreamElement( const OUString& aStreamName,
131 sal_Int32 nOpenMode,
132 const OUString& aPassword ) override;
133 virtual css::uno::Reference< css::embed::XStorage > SAL_CALL
134 openStorageElement( const OUString& aStorName,
135 sal_Int32 nOpenMode ) override;
136 virtual css::uno::Reference< css::io::XStream > SAL_CALL
137 cloneStreamElement( const OUString& aStreamName ) override;
138 virtual css::uno::Reference< css::io::XStream > SAL_CALL
139 cloneEncryptedStreamElement( const OUString& aStreamName,
140 const OUString& aPassword ) override;
141 virtual void SAL_CALL
142 copyLastCommitTo( const css::uno::Reference<
143 css::embed::XStorage >& xTargetStorage ) override;
144 virtual void SAL_CALL
145 copyStorageElementLastCommitTo( const OUString& aStorName,
146 const css::uno::Reference<
147 css::embed::XStorage > &
148 xTargetStorage ) override;
149 virtual sal_Bool SAL_CALL
150 isStreamElement( const OUString& aElementName ) override;
151 virtual sal_Bool SAL_CALL
152 isStorageElement( const OUString& aElementName ) override;
153 virtual void SAL_CALL
154 removeElement( const OUString& aElementName ) override;
155 virtual void SAL_CALL
156 renameElement( const OUString& aEleName,
157 const OUString& aNewName ) override;
158 virtual void SAL_CALL
159 copyElementTo( const OUString& aElementName,
160 const css::uno::Reference< css::embed::XStorage >& xDest,
161 const OUString& aNewName ) override;
162 virtual void SAL_CALL
163 moveElementTo( const OUString& aElementName,
164 const css::uno::Reference< css::embed::XStorage >& xDest,
165 const OUString& rNewName ) override;
167 // XTransactedObject
168 virtual void SAL_CALL commit() override;
169 virtual void SAL_CALL revert() override;
171 private:
172 rtl::Reference< StorageElementFactory > m_xFactory;
173 css::uno::Reference< css::uno::XAggregation > m_xAggProxy;
174 css::uno::Reference< css::embed::XStorage > m_xWrappedStorage;
175 css::uno::Reference< css::embed::XTransactedObject > m_xWrappedTransObj;
176 css::uno::Reference< css::lang::XComponent > m_xWrappedComponent;
177 css::uno::Reference< css::lang::XTypeProvider > m_xWrappedTypeProv;
178 bool m_bIsDocumentStorage;
180 StorageElementFactory::StorageMap::iterator m_aContainerIt;
182 friend class StorageElementFactory;
186 typedef
187 cppu::WeakImplHelper<
188 css::io::XOutputStream,
189 css::lang::XComponent > OutputStreamUNOBase;
191 class OutputStream : public OutputStreamUNOBase, public ParentStorageHolder
193 public:
194 OutputStream(
195 const css::uno::Reference< css::uno::XComponentContext > & rxContext,
196 const OUString & rUri,
197 const css::uno::Reference< css::embed::XStorage > & xParentStorage,
198 const css::uno::Reference< css::io::XOutputStream > & xStreamToWrap );
199 virtual ~OutputStream() override;
201 // XInterface
202 virtual css::uno::Any SAL_CALL
203 queryInterface( const css::uno::Type& aType ) override;
205 // XTypeProvider (implemented by base, but needs to be overridden for
206 // delegating to aggregate)
207 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
208 getTypes() override;
209 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
210 getImplementationId() override;
212 // XOutputStream
213 virtual void SAL_CALL
214 writeBytes( const css::uno::Sequence< sal_Int8 >& aData ) override;
215 virtual void SAL_CALL
216 flush( ) override;
217 // Note: We need to intercept this one.
218 virtual void SAL_CALL
219 closeOutput( ) override;
221 // XComponent
222 // Note: We need to intercept this one.
223 virtual void SAL_CALL
224 dispose() override;
225 virtual void SAL_CALL
226 addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
227 virtual void SAL_CALL
228 removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
230 private:
231 css::uno::Reference<
232 css::uno::XAggregation > m_xAggProxy;
233 css::uno::Reference<
234 css::io::XOutputStream > m_xWrappedStream;
235 css::uno::Reference<
236 css::lang::XComponent > m_xWrappedComponent;
237 css::uno::Reference<
238 css::lang::XTypeProvider > m_xWrappedTypeProv;
242 typedef cppu::WeakImplHelper< css::io::XStream,
243 css::io::XOutputStream,
244 css::io::XTruncate,
245 css::io::XInputStream,
246 css::lang::XComponent >
247 StreamUNOBase;
249 class Stream : public StreamUNOBase, public ParentStorageHolder
251 public:
252 Stream(
253 const css::uno::Reference< css::uno::XComponentContext > & rxContext,
254 rtl::Reference<OfficeDocumentsManager> const & docsMgr,
255 const OUString & rUri,
256 const css::uno::Reference< css::embed::XStorage > & xParentStorage,
257 const css::uno::Reference< css::io::XStream > & xStreamToWrap );
259 virtual ~Stream() override;
261 // XInterface
262 virtual css::uno::Any SAL_CALL
263 queryInterface( const css::uno::Type& aType ) override;
265 // XTypeProvider (implemented by base, but needs to be overridden for
266 // delegating to aggregate)
267 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
268 getTypes() override;
269 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
270 getImplementationId() override;
272 // XStream
273 virtual css::uno::Reference< css::io::XInputStream > SAL_CALL
274 getInputStream() override;
276 virtual css::uno::Reference< css::io::XOutputStream > SAL_CALL
277 getOutputStream() override;
279 // XOutputStream
280 virtual void SAL_CALL
281 writeBytes( const css::uno::Sequence< sal_Int8 >& aData ) override;
283 virtual void SAL_CALL
284 flush() override;
286 virtual void SAL_CALL
287 closeOutput() override;
289 // XTruncate
290 virtual void SAL_CALL
291 truncate() override;
293 // XInputStream
294 virtual sal_Int32 SAL_CALL
295 readBytes( css::uno::Sequence< sal_Int8 >& aData,
296 sal_Int32 nBytesToRead ) override;
298 virtual sal_Int32 SAL_CALL
299 readSomeBytes( css::uno::Sequence< sal_Int8 >& aData,
300 sal_Int32 nMaxBytesToRead ) override;
302 virtual void SAL_CALL
303 skipBytes( sal_Int32 nBytesToSkip ) override;
305 virtual sal_Int32 SAL_CALL
306 available() override;
308 virtual void SAL_CALL
309 closeInput() override;
311 // XComponent
312 // Note: We need to intercept this one.
313 virtual void SAL_CALL
314 dispose() override;
315 virtual void SAL_CALL
316 addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
317 virtual void SAL_CALL
318 removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
320 private:
321 /// @throws css::io::IOException
322 void commitChanges();
324 rtl::Reference<OfficeDocumentsManager> m_docsMgr;
325 OUString m_uri;
326 css::uno::Reference<
327 css::uno::XAggregation > m_xAggProxy;
328 css::uno::Reference<
329 css::io::XStream > m_xWrappedStream;
330 css::uno::Reference<
331 css::io::XOutputStream > m_xWrappedOutputStream;
332 css::uno::Reference<
333 css::io::XTruncate > m_xWrappedTruncate;
334 css::uno::Reference<
335 css::io::XInputStream > m_xWrappedInputStream;
336 css::uno::Reference<
337 css::lang::XComponent > m_xWrappedComponent;
338 css::uno::Reference<
339 css::lang::XTypeProvider > m_xWrappedTypeProv;
342 } // namespace tdoc_ucp
344 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */