1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
30 /*========================================================================
32 * OStoreStream interface.
34 *======================================================================*/
40 inline OStoreStream (void) SAL_THROW(())
46 inline ~OStoreStream (void) SAL_THROW(())
49 (void) store_releaseHandle (m_hImpl
);
52 /** Copy construction.
54 inline OStoreStream (OStoreStream
const & rhs
) SAL_THROW(())
55 : m_hImpl (rhs
.m_hImpl
)
58 (void) store_acquireHandle (m_hImpl
);
63 inline OStoreStream
& operator= (OStoreStream
const & rhs
) SAL_THROW(())
66 (void) store_acquireHandle (rhs
.m_hImpl
);
68 (void) store_releaseHandle (m_hImpl
);
69 m_hImpl
= rhs
.m_hImpl
;
73 /** Construction from Stream Handle.
75 inline explicit OStoreStream (storeStreamHandle Handle
) SAL_THROW(())
79 (void) store_acquireHandle (m_hImpl
);
82 /** Conversion into Stream Handle.
84 inline operator storeStreamHandle (void) const SAL_THROW(())
89 /** Check for a valid Stream Handle.
90 @return sal_True if valid, sal_False otherwise.
92 inline bool isValid (void) const SAL_THROW(())
94 return (m_hImpl
!= 0);
98 @see store_openStream()
100 inline storeError
create (
101 storeFileHandle hFile
,
102 OUString
const & rPath
,
103 OUString
const & rName
,
104 storeAccessMode eMode
) SAL_THROW(())
108 (void) store_releaseHandle (m_hImpl
);
111 return store_openStream (hFile
, rPath
.pData
, rName
.pData
, eMode
, &m_hImpl
);
114 /** Close the stream.
115 @see store_closeStream()
117 inline void close (void) SAL_THROW(())
121 (void) store_closeStream (m_hImpl
);
126 /** Read from the stream.
127 @see store_readStream()
129 inline storeError
readAt (
133 sal_uInt32
& rnDone
) SAL_THROW(())
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 (
146 void const * pBuffer
,
148 sal_uInt32
& rnDone
) SAL_THROW(())
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 (void) const SAL_THROW(())
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 SAL_THROW(())
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
) SAL_THROW(())
184 return store_E_InvalidHandle
;
186 return store_setStreamSize (m_hImpl
, nSize
);
192 storeStreamHandle m_hImpl
;
195 /*========================================================================
197 * OStoreDirectory interface.
199 *======================================================================*/
200 class OStoreDirectory
205 inline OStoreDirectory (void) SAL_THROW(())
211 inline ~OStoreDirectory (void) SAL_THROW(())
214 (void) store_releaseHandle (m_hImpl
);
217 /** Copy construction.
219 inline OStoreDirectory (OStoreDirectory
const & rhs
) SAL_THROW(())
220 : m_hImpl (rhs
.m_hImpl
)
223 (void) store_acquireHandle (m_hImpl
);
228 inline OStoreDirectory
& operator= (OStoreDirectory
const & rhs
) SAL_THROW(())
231 (void) store_acquireHandle (rhs
.m_hImpl
);
233 (void) store_releaseHandle (m_hImpl
);
234 m_hImpl
= rhs
.m_hImpl
;
238 /** Construction from Directory Handle.
240 inline explicit OStoreDirectory (storeDirectoryHandle Handle
) SAL_THROW(())
244 (void) store_acquireHandle (m_hImpl
);
247 /** Conversion into Directory Handle.
249 inline operator storeDirectoryHandle(void) const SAL_THROW(())
254 /** Check for a valid Directory Handle.
255 @return sal_True if valid, sal_False otherwise.
257 inline bool isValid (void) const SAL_THROW(())
259 return (m_hImpl
!= 0);
262 /** Open the directory.
263 @see store_openDirectory()
265 inline storeError
create (
266 storeFileHandle hFile
,
267 OUString
const & rPath
,
268 OUString
const & rName
,
269 storeAccessMode eMode
) SAL_THROW(())
273 (void) store_releaseHandle (m_hImpl
);
276 return store_openDirectory (hFile
, rPath
.pData
, rName
.pData
, eMode
, &m_hImpl
);
279 /** Close the directory.
280 @see store_closeDirectory()
282 inline void close (void) SAL_THROW(())
286 (void) store_closeDirectory (m_hImpl
);
291 /** Directory iterator type.
295 typedef storeFindData iterator
;
297 /** Find first directory entry.
298 @see store_findFirst()
300 inline storeError
first (iterator
& it
) SAL_THROW(())
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
) SAL_THROW(())
314 return store_E_InvalidHandle
;
316 return store_findNext (m_hImpl
, &it
);
319 /** Directory traversal helper.
325 /** Directory traversal callback.
326 @param it [in] current directory entry.
327 @return sal_True to continue iteration, sal_False to stop.
329 virtual sal_Bool
visit (const iterator
& it
) = 0;
335 /** Directory traversal.
336 @see store_findFirst()
337 @see store_findNext()
339 @param rTraveller [in] the traversal callback.
340 @return store_E_NoMoreFiles upon end of iteration.
342 inline storeError
travel (traveller
& rTraveller
) const
344 storeError eErrCode
= store_E_InvalidHandle
;
348 eErrCode
= store_findFirst (m_hImpl
, &it
);
349 while ((eErrCode
== store_E_None
) && rTraveller
.visit(it
))
350 eErrCode
= store_findNext (m_hImpl
, &it
);
358 storeDirectoryHandle m_hImpl
;
361 /*========================================================================
363 * OStoreFile interface.
365 *======================================================================*/
371 inline OStoreFile (void) SAL_THROW(())
377 inline ~OStoreFile (void) SAL_THROW(())
380 (void) store_releaseHandle (m_hImpl
);
383 /** Copy construction.
385 inline OStoreFile (OStoreFile
const & rhs
) SAL_THROW(())
386 : m_hImpl (rhs
.m_hImpl
)
389 (void) store_acquireHandle (m_hImpl
);
394 inline OStoreFile
& operator= (OStoreFile
const & rhs
) SAL_THROW(())
397 (void) store_acquireHandle (rhs
.m_hImpl
);
399 (void) store_releaseHandle (m_hImpl
);
400 m_hImpl
= rhs
.m_hImpl
;
404 /** Construction from File Handle.
406 inline explicit OStoreFile (storeFileHandle Handle
) SAL_THROW(())
410 (void) store_acquireHandle (m_hImpl
);
413 /** Conversion into File Handle.
415 inline operator storeFileHandle (void) const SAL_THROW(())
420 /** Check for a valid File Handle.
421 @return sal_True if valid, sal_False otherwise.
423 inline bool isValid (void) const SAL_THROW(())
425 return (m_hImpl
!= 0);
429 @see store_openFile()
431 inline storeError
create (
432 OUString
const & rFilename
,
433 storeAccessMode eAccessMode
,
434 sal_uInt16 nPageSize
= STORE_DEFAULT_PAGESIZE
) SAL_THROW(())
438 (void) store_releaseHandle (m_hImpl
);
441 return store_openFile (rFilename
.pData
, eAccessMode
, nPageSize
, &m_hImpl
);
444 /** Open the temporary file in memory.
445 @see store_createMemoryFile()
447 inline storeError
createInMemory (
448 sal_uInt16 nPageSize
= STORE_DEFAULT_PAGESIZE
) SAL_THROW(())
452 (void) store_releaseHandle (m_hImpl
);
455 return store_createMemoryFile (nPageSize
, &m_hImpl
);
459 @see store_closeFile()
461 inline void close (void) SAL_THROW(())
465 (void) store_closeFile (m_hImpl
);
471 @see store_flushFile()
473 inline storeError
flush (void) const SAL_THROW(())
476 return store_E_InvalidHandle
;
478 return store_flushFile (m_hImpl
);
481 /** Get the number of referers to the file.
482 @see store_getFileRefererCount()
484 inline storeError
getRefererCount (sal_uInt32
& rnRefCount
) const SAL_THROW(())
487 return store_E_InvalidHandle
;
489 return store_getFileRefererCount (m_hImpl
, &rnRefCount
);
492 /** Get the file size.
493 @see store_getFileSize()
495 inline storeError
getSize (sal_uInt32
& rnSize
) const SAL_THROW(())
498 return store_E_InvalidHandle
;
500 return store_getFileSize (m_hImpl
, &rnSize
);
503 /** Set attributes of a file entry.
506 inline storeError
attrib (
507 OUString
const & rPath
,
508 OUString
const & rName
,
511 sal_uInt32
& rnAttrib
) SAL_THROW(())
514 return store_E_InvalidHandle
;
516 return store_attrib (m_hImpl
, rPath
.pData
, rName
.pData
, nMask1
, nMask2
, &rnAttrib
);
519 /** Set attributes of a file entry.
522 inline storeError
attrib (
523 OUString
const & rPath
,
524 OUString
const & rName
,
526 sal_uInt32 nMask2
) SAL_THROW(())
529 return store_E_InvalidHandle
;
531 return store_attrib (m_hImpl
, rPath
.pData
, rName
.pData
, nMask1
, nMask2
, NULL
);
534 /** Insert a file entry as 'hard link' to another file entry.
537 inline storeError
link (
538 OUString
const & rSrcPath
, OUString
const & rSrcName
,
539 OUString
const & rDstPath
, OUString
const & rDstName
) SAL_THROW(())
542 return store_E_InvalidHandle
;
545 m_hImpl
, rSrcPath
.pData
, rSrcName
.pData
, rDstPath
.pData
, rDstName
.pData
);
548 /** Insert a file entry as 'symbolic link' to another file entry.
551 inline storeError
symlink (
552 OUString
const & rSrcPath
, OUString
const & rSrcName
,
553 OUString
const & rDstPath
, OUString
const & rDstName
) SAL_THROW(())
556 return store_E_InvalidHandle
;
558 return store_symlink (m_hImpl
, rSrcPath
.pData
, rSrcName
.pData
, rDstPath
.pData
, rDstName
.pData
);
561 /** Rename a file entry.
564 inline storeError
rename (
565 OUString
const & rSrcPath
, OUString
const & rSrcName
,
566 OUString
const & rDstPath
, OUString
const & rDstName
) SAL_THROW(())
569 return store_E_InvalidHandle
;
571 return store_rename (m_hImpl
, rSrcPath
.pData
, rSrcName
.pData
, rDstPath
.pData
, rDstName
.pData
);
574 /** Remove a file entry.
577 inline storeError
remove (
578 OUString
const & rPath
, OUString
const & rName
) SAL_THROW(())
581 return store_E_InvalidHandle
;
583 return store_remove (m_hImpl
, rPath
.pData
, rName
.pData
);
589 storeFileHandle m_hImpl
;
592 /*========================================================================
596 *======================================================================*/
600 #endif /* ! INCLUDED_STORE_STORE_HXX */
605 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */