Drop unneeded indirection and unused argument
[LibreOffice.git] / include / store / store.hxx
blobada5579f36605872958b14fc4ea280690f4caf59
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 <store/store.h>
23 #include <sal/types.h>
24 #include <rtl/ustring.hxx>
25 #include <store/types.h>
27 namespace store
30 class OStoreStream
32 public:
33 OStoreStream()
34 : m_hImpl (nullptr)
37 ~OStoreStream()
39 if (m_hImpl)
40 (void) store_releaseHandle (m_hImpl);
43 OStoreStream (OStoreStream const & rhs)
44 : m_hImpl (rhs.m_hImpl)
46 if (m_hImpl)
47 (void) store_acquireHandle (m_hImpl);
50 OStoreStream & operator= (OStoreStream const & rhs)
52 if (rhs.m_hImpl)
53 (void) store_acquireHandle (rhs.m_hImpl);
54 if (m_hImpl)
55 (void) store_releaseHandle (m_hImpl);
56 m_hImpl = rhs.m_hImpl;
57 return *this;
60 /** Open the stream.
61 @see store_openStream()
63 storeError create (
64 storeFileHandle hFile,
65 OUString const & rPath,
66 OUString const & rName,
67 storeAccessMode eMode)
69 if (m_hImpl)
71 (void) store_releaseHandle (m_hImpl);
72 m_hImpl = nullptr;
74 return store_openStream (hFile, rPath.pData, rName.pData, eMode, &m_hImpl);
77 /** Read from the stream.
78 @see store_readStream()
80 storeError readAt (
81 sal_uInt32 nOffset,
82 void * pBuffer,
83 sal_uInt32 nBytes,
84 sal_uInt32 & rnDone)
86 if (!m_hImpl)
87 return store_E_InvalidHandle;
89 return store_readStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone);
92 /** Write to the stream.
93 @see store_writeStream()
95 storeError writeAt (
96 sal_uInt32 nOffset,
97 void const * pBuffer,
98 sal_uInt32 nBytes,
99 sal_uInt32 & rnDone)
101 if (!m_hImpl)
102 return store_E_InvalidHandle;
104 return store_writeStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone);
107 private:
108 storeStreamHandle m_hImpl;
111 class OStoreDirectory
113 public:
114 OStoreDirectory()
115 : m_hImpl (nullptr)
118 ~OStoreDirectory()
120 if (m_hImpl)
121 (void) store_releaseHandle (m_hImpl);
124 OStoreDirectory (OStoreDirectory const & rhs)
125 : m_hImpl (rhs.m_hImpl)
127 if (m_hImpl)
128 (void) store_acquireHandle (m_hImpl);
131 OStoreDirectory (OStoreDirectory && rhs) noexcept
132 : m_hImpl (rhs.m_hImpl)
134 rhs.m_hImpl = nullptr;
137 OStoreDirectory & operator= (OStoreDirectory const & rhs)
139 if (rhs.m_hImpl)
140 (void) store_acquireHandle (rhs.m_hImpl);
141 if (m_hImpl)
142 (void) store_releaseHandle (m_hImpl);
143 m_hImpl = rhs.m_hImpl;
144 return *this;
147 OStoreDirectory & operator= (OStoreDirectory && rhs) noexcept
149 if (m_hImpl)
150 (void) store_releaseHandle (m_hImpl);
151 m_hImpl = rhs.m_hImpl;
152 rhs.m_hImpl = nullptr;
153 return *this;
156 /** Open the directory.
157 @see store_openDirectory()
159 storeError create (
160 storeFileHandle hFile,
161 OUString const & rPath,
162 OUString const & rName,
163 storeAccessMode eMode)
165 if (m_hImpl)
167 (void) store_releaseHandle (m_hImpl);
168 m_hImpl = nullptr;
170 return store_openDirectory (hFile, rPath.pData, rName.pData, eMode, &m_hImpl);
173 /** Directory iterator type.
174 @see first()
175 @see next()
177 typedef storeFindData iterator;
179 /** Find first directory entry.
180 @see store_findFirst()
182 storeError first (iterator& it)
184 if (!m_hImpl)
185 return store_E_InvalidHandle;
187 return store_findFirst (m_hImpl, &it);
190 /** Find next directory entry.
191 @see store_findNext()
193 storeError next (iterator& it)
195 if (!m_hImpl)
196 return store_E_InvalidHandle;
198 return store_findNext (m_hImpl, &it);
201 private:
202 storeDirectoryHandle m_hImpl;
205 class OStoreFile
207 public:
208 OStoreFile()
209 : m_hImpl (nullptr)
212 ~OStoreFile()
214 if (m_hImpl)
215 (void) store_releaseHandle (m_hImpl);
218 OStoreFile (OStoreFile const & rhs)
219 : m_hImpl (rhs.m_hImpl)
221 if (m_hImpl)
222 (void) store_acquireHandle (m_hImpl);
225 OStoreFile & operator= (OStoreFile const & rhs)
227 if (rhs.m_hImpl)
228 (void) store_acquireHandle (rhs.m_hImpl);
229 if (m_hImpl)
230 (void) store_releaseHandle (m_hImpl);
231 m_hImpl = rhs.m_hImpl;
232 return *this;
235 operator storeFileHandle() const
237 return m_hImpl;
240 /** Check for a valid File Handle.
241 @return sal_True if valid, sal_False otherwise.
243 bool isValid() const
245 return (m_hImpl != nullptr);
248 /** Open the file.
249 @see store_openFile()
251 storeError create(
252 OUString const & rFilename,
253 storeAccessMode eAccessMode )
255 if (m_hImpl)
257 (void) store_releaseHandle (m_hImpl);
258 m_hImpl = nullptr;
260 return store_openFile (rFilename.pData, eAccessMode, STORE_DEFAULT_PAGESIZE, &m_hImpl);
263 /** Open the temporary file in memory.
264 @see store_createMemoryFile()
266 storeError createInMemory ()
268 if (m_hImpl)
270 (void) store_releaseHandle (m_hImpl);
271 m_hImpl = nullptr;
273 return store_createMemoryFile (STORE_DEFAULT_PAGESIZE, &m_hImpl);
276 /** Close the file.
277 @see store_closeFile()
279 void close()
281 if (m_hImpl)
283 (void) store_closeFile (m_hImpl);
284 m_hImpl = nullptr;
288 /** Flush the file.
289 @see store_flushFile()
291 storeError flush() const
293 if (!m_hImpl)
294 return store_E_InvalidHandle;
296 return store_flushFile (m_hImpl);
299 /** Remove a file entry.
300 @see store_remove()
302 storeError remove (
303 OUString const & rPath, OUString const & rName)
305 if (!m_hImpl)
306 return store_E_InvalidHandle;
308 return store_remove (m_hImpl, rPath.pData, rName.pData);
311 private:
312 storeFileHandle m_hImpl;
315 } // namespace store
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */