LCOV - code coverage report
Current view: top level - include/store - store.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 73 93 78.5 %
Date: 2014-11-03 Functions: 21 22 95.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_STORE_STORE_HXX
      21             : #define INCLUDED_STORE_STORE_HXX
      22             : 
      23             : #include <sal/types.h>
      24             : #include <rtl/ustring.hxx>
      25             : #include <store/store.h>
      26             : 
      27             : namespace store
      28             : {
      29             : 
      30             : /*========================================================================
      31             :  *
      32             :  * OStoreStream interface.
      33             :  *
      34             :  *======================================================================*/
      35             : class OStoreStream
      36             : {
      37             : public:
      38             :     /** Construction.
      39             :      */
      40         830 :     inline OStoreStream (void)
      41         830 :         : m_hImpl (0)
      42         830 :     {}
      43             : 
      44             :     /** Destruction.
      45             :      */
      46         830 :     inline ~OStoreStream (void)
      47             :     {
      48         830 :         if (m_hImpl)
      49         814 :             (void) store_releaseHandle (m_hImpl);
      50         830 :     }
      51             : 
      52             :     /** Copy construction.
      53             :      */
      54             :     inline OStoreStream (OStoreStream const & rhs)
      55             :         : m_hImpl (rhs.m_hImpl)
      56             :     {
      57             :         if (m_hImpl)
      58             :             (void) store_acquireHandle (m_hImpl);
      59             :     }
      60             : 
      61             :     /** Assignment.
      62             :      */
      63             :     inline OStoreStream & operator= (OStoreStream const & rhs)
      64             :     {
      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;
      71             :     }
      72             : 
      73             :     /** Construction from Stream Handle.
      74             :      */
      75             :     inline explicit OStoreStream (storeStreamHandle Handle)
      76             :         : m_hImpl (Handle)
      77             :     {
      78             :         if (m_hImpl)
      79             :             (void) store_acquireHandle (m_hImpl);
      80             :     }
      81             : 
      82             :     /** Conversion into Stream Handle.
      83             :      */
      84             :     inline operator storeStreamHandle (void) const
      85             :     {
      86             :         return m_hImpl;
      87             :     }
      88             : 
      89             :     /** Check for a valid Stream Handle.
      90             :         @return sal_True if valid, sal_False otherwise.
      91             :      */
      92             :     inline bool isValid (void) const
      93             :     {
      94             :         return (m_hImpl != 0);
      95             :     }
      96             : 
      97             :     /** Open the stream.
      98             :         @see store_openStream()
      99             :      */
     100         830 :     inline storeError create (
     101             :         storeFileHandle       hFile,
     102             :         rtl::OUString const & rPath,
     103             :         rtl::OUString const & rName,
     104             :         storeAccessMode       eMode)
     105             :     {
     106         830 :         if (m_hImpl)
     107             :         {
     108           0 :             (void) store_releaseHandle (m_hImpl);
     109           0 :             m_hImpl = 0;
     110             :         }
     111         830 :         return store_openStream (hFile, rPath.pData, rName.pData, eMode, &m_hImpl);
     112             :     }
     113             : 
     114             :     /** Close the stream.
     115             :         @see store_closeStream()
     116             :      */
     117             :     inline void close (void)
     118             :     {
     119             :         if (m_hImpl)
     120             :         {
     121             :             (void) store_closeStream (m_hImpl);
     122             :             m_hImpl = 0;
     123             :         }
     124             :     }
     125             : 
     126             :     /** Read from the stream.
     127             :         @see store_readStream()
     128             :      */
     129          24 :     inline storeError readAt (
     130             :         sal_uInt32   nOffset,
     131             :         void *       pBuffer,
     132             :         sal_uInt32   nBytes,
     133             :         sal_uInt32 & rnDone)
     134             :     {
     135          24 :         if (!m_hImpl)
     136           0 :             return store_E_InvalidHandle;
     137             : 
     138          24 :         return store_readStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone);
     139             :     }
     140             : 
     141             :     /** Write to the stream.
     142             :         @see store_writeStream()
     143             :      */
     144         796 :     inline storeError writeAt (
     145             :         sal_uInt32   nOffset,
     146             :         void const * pBuffer,
     147             :         sal_uInt32   nBytes,
     148             :         sal_uInt32 & rnDone)
     149             :     {
     150         796 :         if (!m_hImpl)
     151           0 :             return store_E_InvalidHandle;
     152             : 
     153         796 :         return store_writeStream (m_hImpl, nOffset, pBuffer, nBytes, &rnDone);
     154             :     }
     155             : 
     156             :     /** Flush the stream.
     157             :         @see store_flushStream()
     158             :      */
     159             :     inline storeError flush (void) const
     160             :     {
     161             :         if (!m_hImpl)
     162             :             return store_E_InvalidHandle;
     163             : 
     164             :         return store_flushStream (m_hImpl);
     165             :     }
     166             : 
     167             :     /** Get the stream size.
     168             :         @see store_getStreamSize()
     169             :      */
     170             :     inline storeError getSize (sal_uInt32 & rnSize) const
     171             :     {
     172             :         if (!m_hImpl)
     173             :             return store_E_InvalidHandle;
     174             : 
     175             :         return store_getStreamSize (m_hImpl, &rnSize);
     176             :     }
     177             : 
     178             :     /** Set the stream size.
     179             :         @see store_setStreamSize()
     180             :      */
     181             :     inline storeError setSize (sal_uInt32 nSize)
     182             :     {
     183             :         if (!m_hImpl)
     184             :             return store_E_InvalidHandle;
     185             : 
     186             :         return store_setStreamSize (m_hImpl, nSize);
     187             :     }
     188             : 
     189             : private:
     190             :     /** Representation.
     191             :      */
     192             :     storeStreamHandle m_hImpl;
     193             : };
     194             : 
     195             : /*========================================================================
     196             :  *
     197             :  * OStoreDirectory interface.
     198             :  *
     199             :  *======================================================================*/
     200             : class OStoreDirectory
     201             : {
     202             : public:
     203             :     /** Construction.
     204             :      */
     205        1250 :     inline OStoreDirectory (void)
     206        1250 :         : m_hImpl (0)
     207        1250 :     {}
     208             : 
     209             :     /** Destruction.
     210             :      */
     211        1250 :     inline ~OStoreDirectory (void)
     212             :     {
     213        1250 :         if (m_hImpl)
     214        1238 :             (void) store_releaseHandle (m_hImpl);
     215        1250 :     }
     216             : 
     217             :     /** Copy construction.
     218             :      */
     219             :     inline OStoreDirectory (OStoreDirectory const & rhs)
     220             :         : m_hImpl (rhs.m_hImpl)
     221             :     {
     222             :         if (m_hImpl)
     223             :             (void) store_acquireHandle (m_hImpl);
     224             :     }
     225             : 
     226             :     /** Assignment.
     227             :      */
     228           0 :     inline OStoreDirectory & operator= (OStoreDirectory const & rhs)
     229             :     {
     230           0 :         if (rhs.m_hImpl)
     231           0 :             (void) store_acquireHandle (rhs.m_hImpl);
     232           0 :         if (m_hImpl)
     233           0 :             (void) store_releaseHandle (m_hImpl);
     234           0 :         m_hImpl = rhs.m_hImpl;
     235           0 :         return *this;
     236             :     }
     237             : 
     238             :     /** Construction from Directory Handle.
     239             :      */
     240             :     inline explicit OStoreDirectory (storeDirectoryHandle Handle)
     241             :         : m_hImpl (Handle)
     242             :     {
     243             :         if (m_hImpl)
     244             :             (void) store_acquireHandle (m_hImpl);
     245             :     }
     246             : 
     247             :     /** Conversion into Directory Handle.
     248             :      */
     249             :     inline operator storeDirectoryHandle(void) const
     250             :     {
     251             :         return m_hImpl;
     252             :     }
     253             : 
     254             :     /** Check for a valid Directory Handle.
     255             :         @return sal_True if valid, sal_False otherwise.
     256             :      */
     257             :     inline bool isValid (void) const
     258             :     {
     259             :         return (m_hImpl != 0);
     260             :     }
     261             : 
     262             :     /** Open the directory.
     263             :         @see store_openDirectory()
     264             :      */
     265        1840 :     inline storeError create (
     266             :         storeFileHandle       hFile,
     267             :         rtl::OUString const & rPath,
     268             :         rtl::OUString const & rName,
     269             :         storeAccessMode       eMode)
     270             :     {
     271        1840 :         if (m_hImpl)
     272             :         {
     273         590 :             (void) store_releaseHandle (m_hImpl);
     274         590 :             m_hImpl = 0;
     275             :         }
     276        1840 :         return store_openDirectory (hFile, rPath.pData, rName.pData, eMode, &m_hImpl);
     277             :     }
     278             : 
     279             :     /** Close the directory.
     280             :         @see store_closeDirectory()
     281             :      */
     282             :     inline void close (void)
     283             :     {
     284             :         if (m_hImpl)
     285             :         {
     286             :             (void) store_closeDirectory (m_hImpl);
     287             :             m_hImpl = 0;
     288             :         }
     289             :     }
     290             : 
     291             :     /** Directory iterator type.
     292             :         @see first()
     293             :         @see next()
     294             :      */
     295             :     typedef storeFindData iterator;
     296             : 
     297             :     /** Find first directory entry.
     298             :         @see store_findFirst()
     299             :      */
     300          74 :     inline storeError first (iterator& it)
     301             :     {
     302          74 :         if (!m_hImpl)
     303           0 :             return store_E_InvalidHandle;
     304             : 
     305          74 :         return store_findFirst (m_hImpl, &it);
     306             :     }
     307             : 
     308             :     /** Find next directory entry.
     309             :         @see store_findNext()
     310             :      */
     311          82 :     inline storeError next (iterator& it)
     312             :     {
     313          82 :         if (!m_hImpl)
     314           0 :             return store_E_InvalidHandle;
     315             : 
     316          82 :         return store_findNext (m_hImpl, &it);
     317             :     }
     318             : 
     319             :     /** Directory traversal helper.
     320             :         @see travel()
     321             :      */
     322             :     class traveller
     323             :     {
     324             :     public:
     325             :         /** Directory traversal callback.
     326             :             @param  it [in] current directory entry.
     327             :             @return sal_True to continue iteration, sal_False to stop.
     328             :          */
     329             :         virtual bool visit (const iterator& it) = 0;
     330             : 
     331             :     protected:
     332             :         ~traveller() {}
     333             :     };
     334             : 
     335             :     /** Directory traversal.
     336             :         @see store_findFirst()
     337             :         @see store_findNext()
     338             : 
     339             :         @param  rTraveller [in] the traversal callback.
     340             :         @return store_E_NoMoreFiles upon end of iteration.
     341             :      */
     342             :     inline storeError travel (traveller & rTraveller) const
     343             :     {
     344             :         storeError eErrCode = store_E_InvalidHandle;
     345             :         if (m_hImpl)
     346             :         {
     347             :             iterator it;
     348             :             eErrCode = store_findFirst (m_hImpl, &it);
     349             :             while ((eErrCode == store_E_None) && rTraveller.visit(it))
     350             :                 eErrCode = store_findNext (m_hImpl, &it);
     351             :         }
     352             :         return eErrCode;
     353             :     }
     354             : 
     355             : private:
     356             :     /** Representation.
     357             :      */
     358             :     storeDirectoryHandle m_hImpl;
     359             : };
     360             : 
     361             : /*========================================================================
     362             :  *
     363             :  * OStoreFile interface.
     364             :  *
     365             :  *======================================================================*/
     366             : class OStoreFile
     367             : {
     368             : public:
     369             :     /** Construction.
     370             :      */
     371         608 :     inline OStoreFile (void)
     372         608 :         : m_hImpl (0)
     373         608 :     {}
     374             : 
     375             :     /** Destruction.
     376             :      */
     377         618 :     inline ~OStoreFile (void)
     378             :     {
     379         618 :         if (m_hImpl)
     380         310 :             (void) store_releaseHandle (m_hImpl);
     381         618 :     }
     382             : 
     383             :     /** Copy construction.
     384             :      */
     385          14 :     inline OStoreFile (OStoreFile const & rhs)
     386          14 :         : m_hImpl (rhs.m_hImpl)
     387             :     {
     388          14 :         if (m_hImpl)
     389          14 :             (void) store_acquireHandle (m_hImpl);
     390          14 :     }
     391             : 
     392             :     /** Assignment.
     393             :      */
     394         296 :     inline OStoreFile & operator= (OStoreFile const & rhs)
     395             :     {
     396         296 :         if (rhs.m_hImpl)
     397         296 :             (void) store_acquireHandle (rhs.m_hImpl);
     398         296 :         if (m_hImpl)
     399           0 :             (void) store_releaseHandle (m_hImpl);
     400         296 :         m_hImpl = rhs.m_hImpl;
     401         296 :         return *this;
     402             :     }
     403             : 
     404             :     /** Construction from File Handle.
     405             :      */
     406             :     inline explicit OStoreFile (storeFileHandle Handle)
     407             :         : m_hImpl (Handle)
     408             :     {
     409             :         if (m_hImpl)
     410             :             (void) store_acquireHandle (m_hImpl);
     411             :     }
     412             : 
     413             :     /** Conversion into File Handle.
     414             :      */
     415        2670 :     inline operator storeFileHandle (void) const
     416             :     {
     417        2670 :         return m_hImpl;
     418             :     }
     419             : 
     420             :     /** Check for a valid File Handle.
     421             :         @return sal_True if valid, sal_False otherwise.
     422             :      */
     423         602 :     inline bool isValid (void) const
     424             :     {
     425         602 :         return (m_hImpl != 0);
     426             :     }
     427             : 
     428             :     /** Open the file.
     429             :         @see store_openFile()
     430             :      */
     431         300 :     inline storeError create (
     432             :         rtl::OUString const & rFilename,
     433             :         storeAccessMode       eAccessMode,
     434             :         sal_uInt16            nPageSize = STORE_DEFAULT_PAGESIZE)
     435             :     {
     436         300 :         if (m_hImpl)
     437             :         {
     438           0 :             (void) store_releaseHandle (m_hImpl);
     439           0 :             m_hImpl = 0;
     440             :         }
     441         300 :         return store_openFile (rFilename.pData, eAccessMode, nPageSize, &m_hImpl);
     442             :     }
     443             : 
     444             :     /** Open the temporary file in memory.
     445             :         @see store_createMemoryFile()
     446             :      */
     447           4 :     inline storeError createInMemory (
     448             :         sal_uInt16 nPageSize = STORE_DEFAULT_PAGESIZE)
     449             :     {
     450           4 :         if (m_hImpl)
     451             :         {
     452           0 :             (void) store_releaseHandle (m_hImpl);
     453           0 :             m_hImpl = 0;
     454             :         }
     455           4 :         return store_createMemoryFile (nPageSize, &m_hImpl);
     456             :     }
     457             : 
     458             :     /** Close the file.
     459             :         @see store_closeFile()
     460             :      */
     461         292 :     inline void close (void)
     462             :     {
     463         292 :         if (m_hImpl)
     464             :         {
     465         292 :             (void) store_closeFile (m_hImpl);
     466         292 :             m_hImpl = 0;
     467             :         }
     468         292 :     }
     469             : 
     470             :     /** Flush the file.
     471             :         @see store_flushFile()
     472             :      */
     473           4 :     inline storeError flush (void) const
     474             :     {
     475           4 :         if (!m_hImpl)
     476           0 :             return store_E_InvalidHandle;
     477             : 
     478           4 :         return store_flushFile (m_hImpl);
     479             :     }
     480             : 
     481             :     /** Get the number of referers to the file.
     482             :         @see store_getFileRefererCount()
     483             :      */
     484             :     inline storeError getRefererCount (sal_uInt32 & rnRefCount) const
     485             :     {
     486             :         if (!m_hImpl)
     487             :             return store_E_InvalidHandle;
     488             : 
     489             :         return store_getFileRefererCount (m_hImpl, &rnRefCount);
     490             :     }
     491             : 
     492             :     /** Get the file size.
     493             :         @see store_getFileSize()
     494             :      */
     495             :     inline storeError getSize (sal_uInt32 & rnSize) const
     496             :     {
     497             :         if (!m_hImpl)
     498             :             return store_E_InvalidHandle;
     499             : 
     500             :         return store_getFileSize (m_hImpl, &rnSize);
     501             :     }
     502             : 
     503             :     /** Set attributes of a file entry.
     504             :         @see store_attrib()
     505             :      */
     506             :     inline storeError attrib (
     507             :         rtl::OUString const & rPath,
     508             :         rtl::OUString const & rName,
     509             :         sal_uInt32            nMask1,
     510             :         sal_uInt32            nMask2,
     511             :         sal_uInt32          & rnAttrib)
     512             :     {
     513             :         if (!m_hImpl)
     514             :             return store_E_InvalidHandle;
     515             : 
     516             :         return store_attrib (m_hImpl, rPath.pData, rName.pData, nMask1, nMask2, &rnAttrib);
     517             :     }
     518             : 
     519             :     /** Set attributes of a file entry.
     520             :         @see store_attrib()
     521             :      */
     522             :     inline storeError attrib (
     523             :         rtl::OUString const & rPath,
     524             :         rtl::OUString const & rName,
     525             :         sal_uInt32            nMask1,
     526             :         sal_uInt32            nMask2)
     527             :     {
     528             :         if (!m_hImpl)
     529             :             return store_E_InvalidHandle;
     530             : 
     531             :         return store_attrib (m_hImpl, rPath.pData, rName.pData, nMask1, nMask2, NULL);
     532             :     }
     533             : 
     534             :     /** Insert a file entry as 'hard link' to another file entry.
     535             :         @see store_link()
     536             :      */
     537             :     inline storeError link (
     538             :         rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName,
     539             :         rtl::OUString const & rDstPath, rtl::OUString const & rDstName)
     540             :     {
     541             :         if (!m_hImpl)
     542             :             return store_E_InvalidHandle;
     543             : 
     544             :         return store_link (
     545             :             m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData);
     546             :     }
     547             : 
     548             :     /** Insert a file entry as 'symbolic link' to another file entry.
     549             :         @see store_symlink()
     550             :      */
     551             :     inline storeError symlink (
     552             :         rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName,
     553             :         rtl::OUString const & rDstPath, rtl::OUString const & rDstName)
     554             :     {
     555             :         if (!m_hImpl)
     556             :             return store_E_InvalidHandle;
     557             : 
     558             :         return store_symlink (m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData);
     559             :     }
     560             : 
     561             :     /** Rename a file entry.
     562             :         @see store_rename()
     563             :      */
     564             :     inline storeError rename (
     565             :         rtl::OUString const & rSrcPath, rtl::OUString const & rSrcName,
     566             :         rtl::OUString const & rDstPath, rtl::OUString const & rDstName)
     567             :     {
     568             :         if (!m_hImpl)
     569             :             return store_E_InvalidHandle;
     570             : 
     571             :         return store_rename (m_hImpl, rSrcPath.pData, rSrcName.pData, rDstPath.pData, rDstName.pData);
     572             :     }
     573             : 
     574             :     /** Remove a file entry.
     575             :         @see store_remove()
     576             :      */
     577          18 :     inline storeError remove (
     578             :         rtl::OUString const & rPath, rtl::OUString const & rName)
     579             :     {
     580          18 :         if (!m_hImpl)
     581           0 :             return store_E_InvalidHandle;
     582             : 
     583          18 :         return store_remove (m_hImpl, rPath.pData, rName.pData);
     584             :     }
     585             : 
     586             : private:
     587             :     /** Representation.
     588             :      */
     589             :     storeFileHandle m_hImpl;
     590             : };
     591             : 
     592             : /*========================================================================
     593             :  *
     594             :  * The End.
     595             :  *
     596             :  *======================================================================*/
     597             : 
     598             : } // namespace store
     599             : 
     600             : #endif /* ! INCLUDED_STORE_STORE_HXX */
     601             : 
     602             : 
     603             : 
     604             : 
     605             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10