LCOV - code coverage report
Current view: top level - include/oox/helper - storagebase.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 3 3 100.0 %
Date: 2015-06-13 12:38:46 Functions: 4 4 100.0 %
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_OOX_HELPER_STORAGEBASE_HXX
      21             : #define INCLUDED_OOX_HELPER_STORAGEBASE_HXX
      22             : 
      23             : #include <vector>
      24             : #include <com/sun/star/uno/Reference.hxx>
      25             : #include <oox/helper/refmap.hxx>
      26             : #include <oox/dllapi.h>
      27             : 
      28             : namespace com { namespace sun { namespace star {
      29             :     namespace embed { class XStorage; }
      30             :     namespace io { class XInputStream; }
      31             :     namespace io { class XOutputStream; }
      32             :     namespace io { class XStream; }
      33             : } } }
      34             : 
      35             : namespace oox {
      36             : 
      37             : 
      38             : 
      39             : class StorageBase;
      40             : typedef std::shared_ptr< StorageBase > StorageRef;
      41             : 
      42             : /** Base class for storage access implementations.
      43             : 
      44             :     Derived classes will be used to encapsulate storage access implementations
      45             :     for ZIP storages containing XML streams, and OLE storages containing binary
      46             :     data streams.
      47             :  */
      48             : class OOX_DLLPUBLIC StorageBase
      49             : {
      50             : public:
      51             :     explicit            StorageBase(
      52             :                             const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStream,
      53             :                             bool bBaseStreamAccess );
      54             : 
      55             :     explicit            StorageBase(
      56             :                             const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& rxOutStream,
      57             :                             bool bBaseStreamAccess );
      58             : 
      59             :     virtual             ~StorageBase();
      60             : 
      61             :     /** Returns true, if the object represents a valid storage. */
      62             :     bool                isStorage() const;
      63             : 
      64             :     /** Returns true, if the object represents the root storage. */
      65             :     bool                isRootStorage() const;
      66             : 
      67             :     /** Returns true, if the storage operates in read-only mode (based on an
      68             :         input stream). */
      69       11533 :     bool                isReadOnly() const { return mbReadOnly;}
      70             : 
      71             :     /** Returns the com.sun.star.embed.XStorage interface of the current storage. */
      72             :     ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
      73             :                         getXStorage() const;
      74             : 
      75             :     /** Returns the element name of this storage. */
      76          66 :     const OUString& getName() const { return maStorageName;}
      77             : 
      78             :     /** Returns the full path of this storage. */
      79             :     OUString     getPath() const;
      80             : 
      81             :     /** Fills the passed vector with the names of all direct elements of this
      82             :         storage. */
      83             :     void                getElementNames( ::std::vector< OUString >& orElementNames ) const;
      84             : 
      85             :     /** Opens and returns the specified sub storage from the storage.
      86             : 
      87             :         @param rStorageName
      88             :             The name of the embedded storage. The name may contain slashes to
      89             :             open storages from embedded substorages.
      90             :         @param bCreateMissing
      91             :             True = create missing sub storages (for export filters). Must be
      92             :             false for storages based on input streams.
      93             :      */
      94             :     StorageRef          openSubStorage( const OUString& rStorageName, bool bCreateMissing );
      95             : 
      96             :     /** Opens and returns the specified input stream from the storage.
      97             : 
      98             :         @param rStreamName
      99             :             The name of the embedded storage stream. The name may contain
     100             :             slashes to open streams from embedded substorages. If base stream
     101             :             access has been enabled in the constructor, the base stream can be
     102             :             accessed by passing an empty string as stream name.
     103             :      */
     104             :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
     105             :                         openInputStream( const OUString& rStreamName );
     106             : 
     107             :     /** Opens and returns the specified output stream from the storage.
     108             : 
     109             :         @param rStreamName
     110             :             The name of the embedded storage stream. The name may contain
     111             :             slashes to create and open streams in embedded substorages. If base
     112             :             stream access has been enabled in the constructor, the base stream
     113             :             can be accessed by passing an empty string as stream name.
     114             :      */
     115             :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >
     116             :                         openOutputStream( const OUString& rStreamName );
     117             : 
     118             :     /** Copies the specified element from this storage to the passed
     119             :          destination storage.
     120             : 
     121             :         @param rElementName
     122             :             The name of the embedded storage or stream. The name may contain
     123             :             slashes to specify an element in an embedded substorage. In this
     124             :             case, the element will be copied to the same substorage in the
     125             :             destination storage.
     126             :      */
     127             :     void                copyToStorage( StorageBase& rDestStrg, const OUString& rElementName );
     128             : 
     129             :     /** Copies all streams of this storage and of all substorages to the passed
     130             :         destination. */
     131             :     void                copyStorageToStorage( StorageBase& rDestStrg );
     132             : 
     133             :     /** Commits the changes to the storage and all substorages. */
     134             :     void                commit();
     135             : 
     136             : protected:
     137             :     /** Special constructor for sub storage objects. */
     138             :     explicit            StorageBase( const StorageBase& rParentStorage, const OUString& rStorageName, bool bReadOnly );
     139             : 
     140             : private:
     141             :                         StorageBase( const StorageBase& ) SAL_DELETED_FUNCTION;
     142             :     StorageBase&        operator=( const StorageBase& ) SAL_DELETED_FUNCTION;
     143             : 
     144             :     /** Returns true, if the object represents a valid storage. */
     145             :     virtual bool        implIsStorage() const = 0;
     146             : 
     147             :     /** Returns the com.sun.star.embed.XStorage interface of the current storage. */
     148             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
     149             :                         implGetXStorage() const = 0;
     150             : 
     151             :     /** Returns the names of all elements of this storage. */
     152             :     virtual void        implGetElementNames( ::std::vector< OUString >& orElementNames ) const = 0;
     153             : 
     154             :     /** Implementation of opening a storage element. */
     155             :     virtual StorageRef  implOpenSubStorage( const OUString& rElementName, bool bCreate ) = 0;
     156             : 
     157             :     /** Implementation of opening an input stream element. */
     158             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
     159             :                         implOpenInputStream( const OUString& rElementName ) = 0;
     160             : 
     161             :     /** Implementation of opening an output stream element. */
     162             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >
     163             :                         implOpenOutputStream( const OUString& rElementName ) = 0;
     164             : 
     165             :     /** Commits the current storage. */
     166             :     virtual void        implCommit() const = 0;
     167             : 
     168             :     /** Helper that opens and caches the specified direct substorage. */
     169             :     StorageRef          getSubStorage( const OUString& rElementName, bool bCreateMissing );
     170             : 
     171             : private:
     172             :     typedef RefMap< OUString, StorageBase > SubStorageMap;
     173             : 
     174             :     SubStorageMap       maSubStorages;      ///< Map of direct sub storages.
     175             :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
     176             :                         mxInStream;         ///< Cached base input stream (to keep it alive).
     177             :     ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >
     178             :                         mxOutStream;        ///< Cached base output stream (to keep it alive).
     179             :     OUString     maParentPath;       ///< Full path of parent storage.
     180             :     OUString     maStorageName;      ///< Name of this storage, if it is a substorage.
     181             :     bool                mbBaseStreamAccess; ///< True = access base streams with empty stream name.
     182             :     bool                mbReadOnly;         ///< True = storage opened read-only (based on input stream).
     183             : };
     184             : 
     185             : 
     186             : 
     187         246 : } // namespace oox
     188             : 
     189             : #endif
     190             : 
     191             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11