bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / store / store.hxx
blobfb4b430c5f2e32f9d50c0fedf0fef88e4ee61e17
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_STORE_STORE_HXX
21 #define INCLUDED_STORE_STORE_HXX
23 #include <store/store.h>
24 #include <sal/types.h>
25 #include <rtl/ustring.hxx>
26 #include <store/types.h>
28 namespace store
31 class OStoreStream
33 public:
34 /** Construction.
36 OStoreStream()
37 : m_hImpl (nullptr)
40 /** Destruction.
42 ~OStoreStream()
44 if (m_hImpl)
45 (void) store_releaseHandle (m_hImpl);
48 /** Copy construction.
50 OStoreStream (OStoreStream const & rhs)
51 : m_hImpl (rhs.m_hImpl)
53 if (m_hImpl)
54 (void) store_acquireHandle (m_hImpl);
57 /** Assignment.
59 OStoreStream & operator= (OStoreStream const & rhs)
61 if (rhs.m_hImpl)
62 (void) store_acquireHandle (rhs.m_hImpl);
63 if (m_hImpl)
64 (void) store_releaseHandle (m_hImpl);
65 m_hImpl = rhs.m_hImpl;
66 return *this;
69 /** Open the stream.
70 @see store_openStream()
72 storeError create (
73 storeFileHandle hFile,
74 OUString const & rPath,
75 OUString const & rName,
76 storeAccessMode eMode)
78 if (m_hImpl)
80 (void) store_releaseHandle (m_hImpl);
81 m_hImpl = nullptr;
83 return store_openStream (hFile, rPath.pData, rName.pData, eMode, &m_hImpl);
86 /** Read from the stream.
87 @see store_readStream()
89 storeError readAt (
90 sal_uInt32 nOffset,
91 void * pBuffer,
92 sal_uInt32 nBytes,
93 sal_uInt32 & rnDone)
95 if (!m_hImpl)
96 return store_E_InvalidHandle;
98 return store_readStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone);
101 /** Write to the stream.
102 @see store_writeStream()
104 storeError writeAt (
105 sal_uInt32 nOffset,
106 void const * pBuffer,
107 sal_uInt32 nBytes,
108 sal_uInt32 & rnDone)
110 if (!m_hImpl)
111 return store_E_InvalidHandle;
113 return store_writeStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone);
116 private:
117 /** Representation.
119 storeStreamHandle m_hImpl;
122 class OStoreDirectory
124 public:
125 /** Construction.
127 OStoreDirectory()
128 : m_hImpl (nullptr)
131 /** Destruction.
133 ~OStoreDirectory()
135 if (m_hImpl)
136 (void) store_releaseHandle (m_hImpl);
139 /** Copy construction.
141 OStoreDirectory (OStoreDirectory const & rhs)
142 : m_hImpl (rhs.m_hImpl)
144 if (m_hImpl)
145 (void) store_acquireHandle (m_hImpl);
148 /** Move construction.
150 OStoreDirectory (OStoreDirectory && rhs)
151 : m_hImpl (rhs.m_hImpl)
153 rhs.m_hImpl = nullptr;
156 /** Assignment.
158 OStoreDirectory & operator= (OStoreDirectory const & rhs)
160 if (rhs.m_hImpl)
161 (void) store_acquireHandle (rhs.m_hImpl);
162 if (m_hImpl)
163 (void) store_releaseHandle (m_hImpl);
164 m_hImpl = rhs.m_hImpl;
165 return *this;
168 /** Move assignment.
170 OStoreDirectory & operator= (OStoreDirectory && rhs)
172 if (m_hImpl)
173 (void) store_releaseHandle (m_hImpl);
174 m_hImpl = rhs.m_hImpl;
175 rhs.m_hImpl = nullptr;
176 return *this;
179 /** Open the directory.
180 @see store_openDirectory()
182 storeError create (
183 storeFileHandle hFile,
184 OUString const & rPath,
185 OUString const & rName,
186 storeAccessMode eMode)
188 if (m_hImpl)
190 (void) store_releaseHandle (m_hImpl);
191 m_hImpl = nullptr;
193 return store_openDirectory (hFile, rPath.pData, rName.pData, eMode, &m_hImpl);
196 /** Directory iterator type.
197 @see first()
198 @see next()
200 typedef storeFindData iterator;
202 /** Find first directory entry.
203 @see store_findFirst()
205 storeError first (iterator& it)
207 if (!m_hImpl)
208 return store_E_InvalidHandle;
210 return store_findFirst (m_hImpl, &it);
213 /** Find next directory entry.
214 @see store_findNext()
216 storeError next (iterator& it)
218 if (!m_hImpl)
219 return store_E_InvalidHandle;
221 return store_findNext (m_hImpl, &it);
224 private:
225 /** Representation.
227 storeDirectoryHandle m_hImpl;
230 class OStoreFile
232 public:
233 /** Construction.
235 OStoreFile()
236 : m_hImpl (nullptr)
239 /** Destruction.
241 ~OStoreFile()
243 if (m_hImpl)
244 (void) store_releaseHandle (m_hImpl);
247 /** Copy construction.
249 OStoreFile (OStoreFile const & rhs)
250 : m_hImpl (rhs.m_hImpl)
252 if (m_hImpl)
253 (void) store_acquireHandle (m_hImpl);
256 /** Assignment.
258 OStoreFile & operator= (OStoreFile const & rhs)
260 if (rhs.m_hImpl)
261 (void) store_acquireHandle (rhs.m_hImpl);
262 if (m_hImpl)
263 (void) store_releaseHandle (m_hImpl);
264 m_hImpl = rhs.m_hImpl;
265 return *this;
268 /** Conversion into File Handle.
270 operator storeFileHandle() const
272 return m_hImpl;
275 /** Check for a valid File Handle.
276 @return sal_True if valid, sal_False otherwise.
278 bool isValid() const
280 return (m_hImpl != nullptr);
283 /** Open the file.
284 @see store_openFile()
286 storeError create(
287 OUString const & rFilename,
288 storeAccessMode eAccessMode )
290 if (m_hImpl)
292 (void) store_releaseHandle (m_hImpl);
293 m_hImpl = nullptr;
295 return store_openFile (rFilename.pData, eAccessMode, STORE_DEFAULT_PAGESIZE, &m_hImpl);
298 /** Open the temporary file in memory.
299 @see store_createMemoryFile()
301 storeError createInMemory ()
303 if (m_hImpl)
305 (void) store_releaseHandle (m_hImpl);
306 m_hImpl = nullptr;
308 return store_createMemoryFile (STORE_DEFAULT_PAGESIZE, &m_hImpl);
311 /** Close the file.
312 @see store_closeFile()
314 void close()
316 if (m_hImpl)
318 (void) store_closeFile (m_hImpl);
319 m_hImpl = nullptr;
323 /** Flush the file.
324 @see store_flushFile()
326 storeError flush() const
328 if (!m_hImpl)
329 return store_E_InvalidHandle;
331 return store_flushFile (m_hImpl);
334 /** Remove a file entry.
335 @see store_remove()
337 storeError remove (
338 OUString const & rPath, OUString const & rName)
340 if (!m_hImpl)
341 return store_E_InvalidHandle;
343 return store_remove (m_hImpl, rPath.pData, rName.pData);
346 private:
347 /** Representation.
349 storeFileHandle m_hImpl;
352 } // namespace store
354 #endif /* ! INCLUDED_STORE_STORE_HXX */
356 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */