build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / include / store / store.hxx
blob012afd1ab9b22cb89cf5a7033e5586fa528804dc
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 <stddef.h>
26 #include <rtl/ustring.hxx>
27 #include <store/types.h>
29 namespace store
32 /*========================================================================
34 * OStoreStream interface.
36 *======================================================================*/
37 class OStoreStream
39 public:
40 /** Construction.
42 inline OStoreStream()
43 : m_hImpl (nullptr)
46 /** Destruction.
48 inline ~OStoreStream()
50 if (m_hImpl)
51 (void) store_releaseHandle (m_hImpl);
54 /** Copy construction.
56 inline OStoreStream (OStoreStream const & rhs)
57 : m_hImpl (rhs.m_hImpl)
59 if (m_hImpl)
60 (void) store_acquireHandle (m_hImpl);
63 /** Assignment.
65 inline OStoreStream & operator= (OStoreStream const & rhs)
67 if (rhs.m_hImpl)
68 (void) store_acquireHandle (rhs.m_hImpl);
69 if (m_hImpl)
70 (void) store_releaseHandle (m_hImpl);
71 m_hImpl = rhs.m_hImpl;
72 return *this;
75 /** Open the stream.
76 @see store_openStream()
78 inline storeError create (
79 storeFileHandle hFile,
80 rtl::OUString const & rPath,
81 rtl::OUString const & rName,
82 storeAccessMode eMode)
84 if (m_hImpl)
86 (void) store_releaseHandle (m_hImpl);
87 m_hImpl = nullptr;
89 return store_openStream (hFile, rPath.pData, rName.pData, eMode, &m_hImpl);
92 /** Read from the stream.
93 @see store_readStream()
95 inline storeError readAt (
96 sal_uInt32 nOffset,
97 void * pBuffer,
98 sal_uInt32 nBytes,
99 sal_uInt32 & rnDone)
101 if (!m_hImpl)
102 return store_E_InvalidHandle;
104 return store_readStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone);
107 /** Write to the stream.
108 @see store_writeStream()
110 inline storeError writeAt (
111 sal_uInt32 nOffset,
112 void const * pBuffer,
113 sal_uInt32 nBytes,
114 sal_uInt32 & rnDone)
116 if (!m_hImpl)
117 return store_E_InvalidHandle;
119 return store_writeStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone);
122 private:
123 /** Representation.
125 storeStreamHandle m_hImpl;
128 /*========================================================================
130 * OStoreDirectory interface.
132 *======================================================================*/
133 class OStoreDirectory
135 public:
136 /** Construction.
138 inline OStoreDirectory()
139 : m_hImpl (nullptr)
142 /** Destruction.
144 inline ~OStoreDirectory()
146 if (m_hImpl)
147 (void) store_releaseHandle (m_hImpl);
150 /** Copy construction.
152 inline OStoreDirectory (OStoreDirectory const & rhs)
153 : m_hImpl (rhs.m_hImpl)
155 if (m_hImpl)
156 (void) store_acquireHandle (m_hImpl);
159 /** Move construction.
161 inline OStoreDirectory (OStoreDirectory && rhs)
162 : m_hImpl (rhs.m_hImpl)
164 rhs.m_hImpl = nullptr;
167 /** Assignment.
169 inline OStoreDirectory & operator= (OStoreDirectory const & rhs)
171 if (rhs.m_hImpl)
172 (void) store_acquireHandle (rhs.m_hImpl);
173 if (m_hImpl)
174 (void) store_releaseHandle (m_hImpl);
175 m_hImpl = rhs.m_hImpl;
176 return *this;
179 /** Move assignment.
181 inline OStoreDirectory & operator= (OStoreDirectory && rhs)
183 if (m_hImpl)
184 (void) store_releaseHandle (m_hImpl);
185 m_hImpl = rhs.m_hImpl;
186 rhs.m_hImpl = nullptr;
187 return *this;
190 /** Open the directory.
191 @see store_openDirectory()
193 inline storeError create (
194 storeFileHandle hFile,
195 rtl::OUString const & rPath,
196 rtl::OUString const & rName,
197 storeAccessMode eMode)
199 if (m_hImpl)
201 (void) store_releaseHandle (m_hImpl);
202 m_hImpl = nullptr;
204 return store_openDirectory (hFile, rPath.pData, rName.pData, eMode, &m_hImpl);
207 /** Directory iterator type.
208 @see first()
209 @see next()
211 typedef storeFindData iterator;
213 /** Find first directory entry.
214 @see store_findFirst()
216 inline storeError first (iterator& it)
218 if (!m_hImpl)
219 return store_E_InvalidHandle;
221 return store_findFirst (m_hImpl, &it);
224 /** Find next directory entry.
225 @see store_findNext()
227 inline storeError next (iterator& it)
229 if (!m_hImpl)
230 return store_E_InvalidHandle;
232 return store_findNext (m_hImpl, &it);
235 private:
236 /** Representation.
238 storeDirectoryHandle m_hImpl;
241 /*========================================================================
243 * OStoreFile interface.
245 *======================================================================*/
246 class OStoreFile
248 public:
249 /** Construction.
251 inline OStoreFile()
252 : m_hImpl (nullptr)
255 /** Destruction.
257 inline ~OStoreFile()
259 if (m_hImpl)
260 (void) store_releaseHandle (m_hImpl);
263 /** Copy construction.
265 inline OStoreFile (OStoreFile const & rhs)
266 : m_hImpl (rhs.m_hImpl)
268 if (m_hImpl)
269 (void) store_acquireHandle (m_hImpl);
272 /** Assignment.
274 inline OStoreFile & operator= (OStoreFile const & rhs)
276 if (rhs.m_hImpl)
277 (void) store_acquireHandle (rhs.m_hImpl);
278 if (m_hImpl)
279 (void) store_releaseHandle (m_hImpl);
280 m_hImpl = rhs.m_hImpl;
281 return *this;
284 /** Conversion into File Handle.
286 inline operator storeFileHandle() const
288 return m_hImpl;
291 /** Check for a valid File Handle.
292 @return sal_True if valid, sal_False otherwise.
294 inline bool isValid() const
296 return (m_hImpl != nullptr);
299 /** Open the file.
300 @see store_openFile()
302 inline storeError create(
303 rtl::OUString const & rFilename,
304 storeAccessMode eAccessMode )
306 if (m_hImpl)
308 (void) store_releaseHandle (m_hImpl);
309 m_hImpl = nullptr;
311 return store_openFile (rFilename.pData, eAccessMode, STORE_DEFAULT_PAGESIZE, &m_hImpl);
314 /** Open the temporary file in memory.
315 @see store_createMemoryFile()
317 inline storeError createInMemory ()
319 if (m_hImpl)
321 (void) store_releaseHandle (m_hImpl);
322 m_hImpl = nullptr;
324 return store_createMemoryFile (STORE_DEFAULT_PAGESIZE, &m_hImpl);
327 /** Close the file.
328 @see store_closeFile()
330 inline void close()
332 if (m_hImpl)
334 (void) store_closeFile (m_hImpl);
335 m_hImpl = nullptr;
339 /** Flush the file.
340 @see store_flushFile()
342 inline storeError flush() const
344 if (!m_hImpl)
345 return store_E_InvalidHandle;
347 return store_flushFile (m_hImpl);
350 /** Remove a file entry.
351 @see store_remove()
353 inline storeError remove (
354 rtl::OUString const & rPath, rtl::OUString const & rName)
356 if (!m_hImpl)
357 return store_E_InvalidHandle;
359 return store_remove (m_hImpl, rPath.pData, rName.pData);
362 private:
363 /** Representation.
365 storeFileHandle m_hImpl;
368 /*========================================================================
370 * The End.
372 *======================================================================*/
374 } // namespace store
376 #endif /* ! INCLUDED_STORE_STORE_HXX */
379 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */