Branch libreoffice-5-0-4
[LibreOffice.git] / include / store / store.hxx
blob943b73ccd5707d75f8ed23ff09cfd289db2d754b
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 <sal/types.h>
24 #include <rtl/ustring.hxx>
25 #include <store/store.h>
27 namespace store
30 /*========================================================================
32 * OStoreStream interface.
34 *======================================================================*/
35 class OStoreStream
37 public:
38 /** Construction.
40 inline OStoreStream()
41 : m_hImpl (0)
44 /** Destruction.
46 inline ~OStoreStream()
48 if (m_hImpl)
49 (void) store_releaseHandle (m_hImpl);
52 /** Copy construction.
54 inline OStoreStream (OStoreStream const & rhs)
55 : m_hImpl (rhs.m_hImpl)
57 if (m_hImpl)
58 (void) store_acquireHandle (m_hImpl);
61 /** Assignment.
63 inline OStoreStream & operator= (OStoreStream const & rhs)
65 if (rhs.m_hImpl)
66 (void) store_acquireHandle (rhs.m_hImpl);
67 if (m_hImpl)
68 (void) store_releaseHandle (m_hImpl);
69 m_hImpl = rhs.m_hImpl;
70 return *this;
73 /** Construction from Stream Handle.
75 inline explicit OStoreStream (storeStreamHandle Handle)
76 : m_hImpl (Handle)
78 if (m_hImpl)
79 (void) store_acquireHandle (m_hImpl);
82 /** Conversion into Stream Handle.
84 inline operator storeStreamHandle() const
86 return m_hImpl;
89 /** Check for a valid Stream Handle.
90 @return sal_True if valid, sal_False otherwise.
92 inline bool isValid() const
94 return (m_hImpl != 0);
97 /** Open the stream.
98 @see store_openStream()
100 inline storeError create (
101 storeFileHandle hFile,
102 rtl::OUString const & rPath,
103 rtl::OUString const & rName,
104 storeAccessMode eMode)
106 if (m_hImpl)
108 (void) store_releaseHandle (m_hImpl);
109 m_hImpl = 0;
111 return store_openStream (hFile, rPath.pData, rName.pData, eMode, &m_hImpl);
114 /** Close the stream.
115 @see store_closeStream()
117 inline void close()
119 if (m_hImpl)
121 (void) store_closeStream (m_hImpl);
122 m_hImpl = 0;
126 /** Read from the stream.
127 @see store_readStream()
129 inline storeError readAt (
130 sal_uInt32 nOffset,
131 void * pBuffer,
132 sal_uInt32 nBytes,
133 sal_uInt32 & rnDone)
135 if (!m_hImpl)
136 return store_E_InvalidHandle;
138 return store_readStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone);
141 /** Write to the stream.
142 @see store_writeStream()
144 inline storeError writeAt (
145 sal_uInt32 nOffset,
146 void const * pBuffer,
147 sal_uInt32 nBytes,
148 sal_uInt32 & rnDone)
150 if (!m_hImpl)
151 return store_E_InvalidHandle;
153 return store_writeStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone);
156 /** Flush the stream.
157 @see store_flushStream()
159 inline storeError flush() const
161 if (!m_hImpl)
162 return store_E_InvalidHandle;
164 return store_flushStream (m_hImpl);
167 /** Get the stream size.
168 @see store_getStreamSize()
170 inline storeError getSize (sal_uInt32 & rnSize) const
172 if (!m_hImpl)
173 return store_E_InvalidHandle;
175 return store_getStreamSize (m_hImpl, &rnSize);
178 /** Set the stream size.
179 @see store_setStreamSize()
181 inline storeError setSize (sal_uInt32 nSize)
183 if (!m_hImpl)
184 return store_E_InvalidHandle;
186 return store_setStreamSize (m_hImpl, nSize);
189 private:
190 /** Representation.
192 storeStreamHandle m_hImpl;
195 /*========================================================================
197 * OStoreDirectory interface.
199 *======================================================================*/
200 class OStoreDirectory
202 public:
203 /** Construction.
205 inline OStoreDirectory()
206 : m_hImpl (0)
209 /** Destruction.
211 inline ~OStoreDirectory()
213 if (m_hImpl)
214 (void) store_releaseHandle (m_hImpl);
217 /** Copy construction.
219 inline OStoreDirectory (OStoreDirectory const & rhs)
220 : m_hImpl (rhs.m_hImpl)
222 if (m_hImpl)
223 (void) store_acquireHandle (m_hImpl);
226 /** Assignment.
228 inline OStoreDirectory & operator= (OStoreDirectory const & rhs)
230 if (rhs.m_hImpl)
231 (void) store_acquireHandle (rhs.m_hImpl);
232 if (m_hImpl)
233 (void) store_releaseHandle (m_hImpl);
234 m_hImpl = rhs.m_hImpl;
235 return *this;
238 /** Construction from Directory Handle.
240 inline explicit OStoreDirectory (storeDirectoryHandle Handle)
241 : m_hImpl (Handle)
243 if (m_hImpl)
244 (void) store_acquireHandle (m_hImpl);
247 /** Conversion into Directory Handle.
249 inline operator storeDirectoryHandle() const
251 return m_hImpl;
254 /** Check for a valid Directory Handle.
255 @return sal_True if valid, sal_False otherwise.
257 inline bool isValid() const
259 return (m_hImpl != 0);
262 /** Open the directory.
263 @see store_openDirectory()
265 inline storeError create (
266 storeFileHandle hFile,
267 rtl::OUString const & rPath,
268 rtl::OUString const & rName,
269 storeAccessMode eMode)
271 if (m_hImpl)
273 (void) store_releaseHandle (m_hImpl);
274 m_hImpl = 0;
276 return store_openDirectory (hFile, rPath.pData, rName.pData, eMode, &m_hImpl);
279 /** Close the directory.
280 @see store_closeDirectory()
282 inline void close()
284 if (m_hImpl)
286 (void) store_closeDirectory (m_hImpl);
287 m_hImpl = 0;
291 /** Directory iterator type.
292 @see first()
293 @see next()
295 typedef storeFindData iterator;
297 /** Find first directory entry.
298 @see store_findFirst()
300 inline storeError first (iterator& it)
302 if (!m_hImpl)
303 return store_E_InvalidHandle;
305 return store_findFirst (m_hImpl, &it);
308 /** Find next directory entry.
309 @see store_findNext()
311 inline storeError next (iterator& it)
313 if (!m_hImpl)
314 return store_E_InvalidHandle;
316 return store_findNext (m_hImpl, &it);
319 private:
320 /** Representation.
322 storeDirectoryHandle m_hImpl;
325 /*========================================================================
327 * OStoreFile interface.
329 *======================================================================*/
330 class OStoreFile
332 public:
333 /** Construction.
335 inline OStoreFile()
336 : m_hImpl (0)
339 /** Destruction.
341 inline ~OStoreFile()
343 if (m_hImpl)
344 (void) store_releaseHandle (m_hImpl);
347 /** Copy construction.
349 inline OStoreFile (OStoreFile const & rhs)
350 : m_hImpl (rhs.m_hImpl)
352 if (m_hImpl)
353 (void) store_acquireHandle (m_hImpl);
356 /** Assignment.
358 inline OStoreFile & operator= (OStoreFile const & rhs)
360 if (rhs.m_hImpl)
361 (void) store_acquireHandle (rhs.m_hImpl);
362 if (m_hImpl)
363 (void) store_releaseHandle (m_hImpl);
364 m_hImpl = rhs.m_hImpl;
365 return *this;
368 /** Construction from File Handle.
370 inline explicit OStoreFile (storeFileHandle Handle)
371 : m_hImpl (Handle)
373 if (m_hImpl)
374 (void) store_acquireHandle (m_hImpl);
377 /** Conversion into File Handle.
379 inline operator storeFileHandle() const
381 return m_hImpl;
384 /** Check for a valid File Handle.
385 @return sal_True if valid, sal_False otherwise.
387 inline bool isValid() const
389 return (m_hImpl != 0);
392 /** Open the file.
393 @see store_openFile()
395 inline storeError create (
396 rtl::OUString const & rFilename,
397 storeAccessMode eAccessMode,
398 sal_uInt16 nPageSize = STORE_DEFAULT_PAGESIZE)
400 if (m_hImpl)
402 (void) store_releaseHandle (m_hImpl);
403 m_hImpl = 0;
405 return store_openFile (rFilename.pData, eAccessMode, nPageSize, &m_hImpl);
408 /** Open the temporary file in memory.
409 @see store_createMemoryFile()
411 inline storeError createInMemory (
412 sal_uInt16 nPageSize = STORE_DEFAULT_PAGESIZE)
414 if (m_hImpl)
416 (void) store_releaseHandle (m_hImpl);
417 m_hImpl = 0;
419 return store_createMemoryFile (nPageSize, &m_hImpl);
422 /** Close the file.
423 @see store_closeFile()
425 inline void close()
427 if (m_hImpl)
429 (void) store_closeFile (m_hImpl);
430 m_hImpl = 0;
434 /** Flush the file.
435 @see store_flushFile()
437 inline storeError flush() const
439 if (!m_hImpl)
440 return store_E_InvalidHandle;
442 return store_flushFile (m_hImpl);
445 /** Get the number of referers to the file.
446 @see store_getFileRefererCount()
448 inline storeError getRefererCount (sal_uInt32 & rnRefCount) const
450 if (!m_hImpl)
451 return store_E_InvalidHandle;
453 return store_getFileRefererCount (m_hImpl, &rnRefCount);
456 /** Get the file size.
457 @see store_getFileSize()
459 inline storeError getSize (sal_uInt32 & rnSize) const
461 if (!m_hImpl)
462 return store_E_InvalidHandle;
464 return store_getFileSize (m_hImpl, &rnSize);
467 /** Set attributes of a file entry.
468 @see store_attrib()
470 inline storeError attrib (
471 rtl::OUString const & rPath,
472 rtl::OUString const & rName,
473 sal_uInt32 nMask1,
474 sal_uInt32 nMask2,
475 sal_uInt32 & rnAttrib)
477 if (!m_hImpl)
478 return store_E_InvalidHandle;
480 return store_attrib (m_hImpl, rPath.pData, rName.pData, nMask1, nMask2, &rnAttrib);
483 /** Set attributes of a file entry.
484 @see store_attrib()
486 inline storeError attrib (
487 rtl::OUString const & rPath,
488 rtl::OUString const & rName,
489 sal_uInt32 nMask1,
490 sal_uInt32 nMask2)
492 if (!m_hImpl)
493 return store_E_InvalidHandle;
495 return store_attrib (m_hImpl, rPath.pData, rName.pData, nMask1, nMask2, NULL);
498 /** Insert a file entry as 'hard link' to another file entry.
499 @see store_link()
501 inline storeError link (
502 rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName,
503 rtl::OUString const & rDstPath, rtl::OUString const & rDstName)
505 if (!m_hImpl)
506 return store_E_InvalidHandle;
508 return store_link (
509 m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData);
512 /** Insert a file entry as 'symbolic link' to another file entry.
513 @see store_symlink()
515 inline storeError symlink (
516 rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName,
517 rtl::OUString const & rDstPath, rtl::OUString const & rDstName)
519 if (!m_hImpl)
520 return store_E_InvalidHandle;
522 return store_symlink (m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData);
525 /** Rename a file entry.
526 @see store_rename()
528 inline storeError rename (
529 rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName,
530 rtl::OUString const & rDstPath, rtl::OUString const & rDstName)
532 if (!m_hImpl)
533 return store_E_InvalidHandle;
535 return store_rename (m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData);
538 /** Remove a file entry.
539 @see store_remove()
541 inline storeError remove (
542 rtl::OUString const & rPath, rtl::OUString const & rName)
544 if (!m_hImpl)
545 return store_E_InvalidHandle;
547 return store_remove (m_hImpl, rPath.pData, rName.pData);
550 private:
551 /** Representation.
553 storeFileHandle m_hImpl;
556 /*========================================================================
558 * The End.
560 *======================================================================*/
562 } // namespace store
564 #endif /* ! INCLUDED_STORE_STORE_HXX */
569 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */