LCOV - code coverage report
Current view: top level - sot/source/sdstor - stgstrms.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 13 17 76.5 %
Date: 2015-06-13 12:38:46 Functions: 16 20 80.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_SOT_SOURCE_SDSTOR_STGSTRMS_HXX
      21             : #define INCLUDED_SOT_SOURCE_SDSTOR_STGSTRMS_HXX
      22             : 
      23             : #include <tools/stream.hxx>
      24             : #include <rtl/ref.hxx>
      25             : #include <vector>
      26             : 
      27             : class StgIo;
      28             : class StgStrm;
      29             : class StgPage;
      30             : class StgDirEntry;
      31             : 
      32             : // The FAT class performs FAT operations on an underlying storage stream.
      33             : // This stream is either the physical FAT stream (bPhys == true ) or a normal
      34             : // storage stream, which then holds the FAT for small data allocations.
      35             : 
      36             : class StgFAT
      37             : {                                       // FAT allocator
      38             :     StgStrm& rStrm;                     // underlying stream
      39             :     sal_Int32 nMaxPage;                     // highest page allocated so far
      40             :     short nPageSize;                    // physical page size
      41             :     short nEntries;                     // FAT entries per page
      42             :     short nOffset;                      // current offset within page
      43             :     sal_Int32 nLimit;                       // search limit recommendation
      44             :     bool  bPhys;                        // true: physical FAT
      45             :     rtl::Reference< StgPage > GetPhysPage( sal_Int32 nPage );
      46             :     bool  MakeChain( sal_Int32 nStart, sal_Int32 nPages );
      47             :     bool  InitNew( sal_Int32 nPage1 );
      48             : public:
      49             :     StgFAT( StgStrm& rStrm, bool bMark );
      50             :     sal_Int32 FindBlock( sal_Int32& nPages );
      51             :     sal_Int32 GetNextPage( sal_Int32 nPg );
      52             :     sal_Int32 AllocPages( sal_Int32 nStart, sal_Int32 nPages );
      53             :     bool  FreePages( sal_Int32 nStart, bool bAll );
      54       26739 :     sal_Int32 GetMaxPage() { return nMaxPage; }
      55       31397 :     void  SetLimit( sal_Int32 n ) { nLimit = n; }
      56             : };
      57             : 
      58             : // The base stream class provides basic functionality for seeking
      59             : // and accessing the data on a physical basis. It uses the built-in
      60             : // FAT class for the page allocations.
      61             : 
      62             : class StgStrm {                         // base class for all streams
      63             : protected:
      64             :     StgIo& rIo;                         // I/O system
      65             :     StgFAT* pFat;                       // FAT stream for allocations
      66             :     StgDirEntry* pEntry;                // dir entry (for ownership)
      67             :     sal_Int32 nStart;                       // 1st data page
      68             :     sal_Int32 nSize;                        // stream size in bytes
      69             :     sal_Int32 nPos;                         // current byte position
      70             :     sal_Int32 nPage;                        // current logical page
      71             :     short nOffset;                      // offset into current page
      72             :     short nPageSize;                    // logical page size
      73             :     std::vector<sal_Int32> m_aPagesCache;
      74             :     void scanBuildPageChainCache(sal_Int32 *pOptionalCalcSize = NULL);
      75             :     bool  Copy( sal_Int32 nFrom, sal_Int32 nBytes );
      76             :     StgStrm( StgIo& );
      77             : public:
      78             :     virtual ~StgStrm();
      79      338539 :     StgIo&  GetIo()     { return rIo;    }
      80     2840158 :     sal_Int32   GetPos() const   { return nPos;   }
      81         872 :     sal_Int32   GetStart() const { return nStart; }
      82       40526 :     sal_Int32   GetSize() const  { return nSize;  }
      83      215418 :     sal_Int32   GetPage() const  { return nPage;  }
      84             :     short   GetPageSize() const { return nPageSize; }
      85       31833 :     sal_Int32   GetPages() const { return ( nSize + nPageSize - 1 ) / nPageSize;}
      86      215101 :     short   GetOffset() const { return nOffset;}
      87             :     void    SetEntry( StgDirEntry& );
      88             :     virtual bool SetSize( sal_Int32 );
      89             :     virtual bool Pos2Page( sal_Int32 nBytePos );
      90           0 :     virtual sal_Int32 Read( void*, sal_Int32 )        { return 0; }
      91           0 :     virtual sal_Int32 Write( const void*, sal_Int32 ) { return 0; }
      92             :     virtual rtl::Reference< StgPage > GetPhysPage( sal_Int32 nBytePos, bool bForce = false );
      93           0 :     virtual bool IsSmallStrm() const { return false; }
      94             : };
      95             : 
      96             : // The FAT stream class provides physical access to the master FAT.
      97             : // Since this access is implemented as a StgStrm, we can use the
      98             : // FAT allocator.
      99             : 
     100             : class StgFATStrm : public StgStrm {     // the master FAT stream
     101             :     virtual bool Pos2Page( sal_Int32 nBytePos ) SAL_OVERRIDE;
     102             :     bool  SetPage( short, sal_Int32 );
     103             : public:
     104             :     StgFATStrm( StgIo& );
     105        1570 :     virtual ~StgFATStrm() {}
     106             :     using StgStrm::GetPage;
     107             :     sal_Int32 GetPage( short, bool, sal_uInt16 *pnMasterAlloc = 0);
     108             :     virtual bool SetSize( sal_Int32 ) SAL_OVERRIDE;
     109             :     virtual rtl::Reference< StgPage > GetPhysPage( sal_Int32 nBytePos, bool bForce = false ) SAL_OVERRIDE;
     110             : };
     111             : 
     112             : // The stream has a size increment which normally is 1, but which can be
     113             : // set to any value is you want the size to be incremented by certain values.
     114             : 
     115        6293 : class StgDataStrm : public StgStrm      // a physical data stream
     116             : {
     117             :     short nIncr;                        // size adjust increment
     118             :     void Init( sal_Int32 nBgn, sal_Int32 nLen );
     119             : public:
     120             :     StgDataStrm( StgIo&, sal_Int32 nBgn, sal_Int32 nLen=-1 );
     121             :     StgDataStrm( StgIo&, StgDirEntry& );
     122             :     void* GetPtr( sal_Int32 nPos, bool bForce, bool bDirty );
     123        1562 :     void SetIncrement( short n ) { nIncr = n ; }
     124             :     virtual bool SetSize( sal_Int32 ) SAL_OVERRIDE;
     125             :     virtual sal_Int32 Read( void*, sal_Int32 ) SAL_OVERRIDE;
     126             :     virtual sal_Int32 Write( const void*, sal_Int32 ) SAL_OVERRIDE;
     127             : };
     128             : 
     129             : // The small stream class provides access to streams with a size < 4096 bytes.
     130             : // This stream is a StgStream containing small pages. The FAT for this stream
     131             : // is also a StgStream. The start of the FAT is in the header at DataRootPage,
     132             : // the stream itself is pointed to by the root entry (it holds start & size).
     133             : 
     134       14366 : class StgSmallStrm : public StgStrm     // a logical data stream
     135             : {
     136             :     StgStrm* pData;                     // the data stream
     137             :     void Init( sal_Int32 nBgn, sal_Int32 nLen );
     138             : public:
     139             :     StgSmallStrm( StgIo&, sal_Int32 nBgn, sal_Int32 nLen );
     140             :     StgSmallStrm( StgIo&, StgDirEntry& );
     141             :     virtual sal_Int32 Read( void*, sal_Int32 ) SAL_OVERRIDE;
     142             :     virtual sal_Int32 Write( const void*, sal_Int32 ) SAL_OVERRIDE;
     143           0 :     virtual bool IsSmallStrm() const SAL_OVERRIDE { return true; }
     144             : };
     145             : 
     146             : class StgTmpStrm : public SvMemoryStream
     147             : {
     148             :     OUString aName;
     149             :     SvFileStream* pStrm;
     150             :     using SvMemoryStream::GetData;
     151             :     virtual sal_uLong GetData( void* pData, sal_uLong nSize ) SAL_OVERRIDE;
     152             :     virtual sal_uLong PutData( const void* pData, sal_uLong nSize ) SAL_OVERRIDE;
     153             :     virtual sal_uInt64 SeekPos( sal_uInt64 nPos ) SAL_OVERRIDE;
     154             :     virtual void FlushData() SAL_OVERRIDE;
     155             : 
     156             : public:
     157             :     StgTmpStrm( sal_uLong=16 );
     158             :    virtual ~StgTmpStrm();
     159             :     bool Copy( StgTmpStrm& );
     160             :     virtual void SetSize( sal_uInt64 ) SAL_OVERRIDE;
     161             :     sal_uLong GetSize() const;
     162             : };
     163             : 
     164             : #endif
     165             : 
     166             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11