LCOV - code coverage report
Current view: top level - sot/source/sdstor - stgstrms.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 12 16 75.0 %
Date: 2012-08-25 Functions: 15 19 78.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 6 50.0 %

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

Generated by: LCOV version 1.10