LCOV - code coverage report
Current view: top level - frmts/pcidsk/sdk/blockdir - blockdir.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 2 2 100.0 %
Date: 2024-05-14 13:00:50 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Purpose:  Block directory API.
       4             :  *
       5             :  ******************************************************************************
       6             :  * Copyright (c) 2011
       7             :  * PCI Geomatics, 90 Allstate Parkway, Markham, Ontario, Canada.
       8             :  *
       9             :  * Permission is hereby granted, free of charge, to any person obtaining a
      10             :  * copy of this software and associated documentation files (the "Software"),
      11             :  * to deal in the Software without restriction, including without limitation
      12             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      13             :  * and/or sell copies of the Software, and to permit persons to whom the
      14             :  * Software is furnished to do so, subject to the following conditions:
      15             :  *
      16             :  * The above copyright notice and this permission notice shall be included
      17             :  * in all copies or substantial portions of the Software.
      18             :  *
      19             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      20             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      21             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      22             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      23             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      24             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      25             :  * DEALINGS IN THE SOFTWARE.
      26             :  ****************************************************************************/
      27             : 
      28             : #ifndef PCIDSK_BLOCK_DIR_H
      29             : #define PCIDSK_BLOCK_DIR_H
      30             : 
      31             : #include "pcidsk_config.h"
      32             : #include <vector>
      33             : #include <string>
      34             : 
      35             : namespace PCIDSK
      36             : {
      37             : 
      38             : class BlockFile;
      39             : class BlockLayer;
      40             : 
      41             : #define INVALID_SEGMENT ((uint16) -1)
      42             : #define INVALID_LAYER   ((uint32) -1)
      43             : #define INVALID_BLOCK   ((uint32) -1)
      44             : #define INVALID_OFFSET  ((uint64) -1)
      45             : 
      46             : #pragma pack(push, 1)
      47             : 
      48             : /// The block info structure.
      49             : struct BlockInfo
      50             : {
      51             :     uint16 nSegment;
      52             :     uint32 nStartBlock;
      53             : };
      54             : 
      55             : #pragma pack(pop)
      56             : 
      57             : /// The block layer list type.
      58             : typedef std::vector<BlockLayer *> BlockLayerList;
      59             : 
      60             : /// The block info list type.
      61             : typedef std::vector<BlockInfo> BlockInfoList;
      62             : 
      63             : /************************************************************************/
      64             : /*                              class BlockDir                          */
      65             : /************************************************************************/
      66             : 
      67             : /**
      68             :  * Class used as the base class for all block directories.
      69             :  */
      70             : class PCIDSK_DLL BlockDir
      71             : {
      72             : protected:
      73             :     /// The associated file.
      74             :     BlockFile *         mpoFile;
      75             : 
      76             :     /// The block directory segment.
      77             :     uint16              mnSegment;
      78             : 
      79             :     /// The block directory version.
      80             :     uint16              mnVersion;
      81             : 
      82             :     // The endianness of the block directory on disk.
      83             :     char                mchEndianness;
      84             : 
      85             :     // If the block directory on disk needs swapping.
      86             :     bool                mbNeedsSwap;
      87             : 
      88             :     /// The block directory validity info.
      89             :     uint16              mnValidInfo;
      90             : 
      91             :     /// If the block directory is modified.
      92             :     bool                mbModified;
      93             : 
      94             :     /// If the block directory is on disk.
      95             :     bool                mbOnDisk;
      96             : 
      97             :     /// The block layer list.
      98             :     BlockLayerList      moLayerList;
      99             : 
     100             :     /// The free block layer.
     101             :     BlockLayer *        mpoFreeBlockLayer;
     102             : 
     103             :     virtual void        ReadLayerBlocks(uint32 iLayer) = 0;
     104             :     virtual void        ReadFreeBlockLayer(void) = 0;
     105             :     virtual void        WriteDir(void) = 0;
     106             : 
     107             :     virtual BlockLayer *_CreateLayer(uint16 nLayerType, uint32 iLayer) = 0;
     108             :     virtual void        _DeleteLayer(uint32 iLayer) = 0;
     109             : 
     110             :     virtual uint32      GetNewBlockCount(void) const = 0;
     111             : 
     112             :     virtual std::string GetDataSegmentName(void) const = 0;
     113             :     virtual std::string GetDataSegmentDesc(void) const = 0;
     114             : 
     115          18 :     virtual void        ValidateNewBlocks(CPL_UNUSED uint32 & nBlockCount,
     116          18 :                                           CPL_UNUSED bool bFreeBlocks) { }
     117             : 
     118             :     void                SwapValue(uint16 * pnValue) const;
     119             : 
     120             :     // We need the block layer interface to be friend so that it can request
     121             :     // to read block information off of the disk.
     122             :     friend class BlockLayer;
     123             : 
     124             : public:
     125             :     BlockDir(BlockFile * poFile, uint16 nSegment);
     126             :     BlockDir(BlockFile * poFile, uint16 nSegment, uint16 nVersion);
     127             : 
     128             :     virtual             ~BlockDir(void);
     129             : 
     130             : /**
     131             :  * Gets the block size of the block directory.
     132             :  *
     133             :  * @return The block size of the block directory.
     134             :  */
     135             :     virtual uint32      GetBlockSize(void) const = 0;
     136             : 
     137             :     void                Sync(void);
     138             : 
     139             :     BlockFile *         GetFile(void) const;
     140             : 
     141             :     uint16              GetSegmentIndex(void) const;
     142             : 
     143             :     uint16              GetVersion(void) const;
     144             : 
     145             :     bool                NeedsSwap(void) const;
     146             : 
     147             :     bool                IsValid(void) const;
     148             : 
     149             :     bool                IsModified(void) const;
     150             : 
     151             :     uint32              GetLayerCount(void) const;
     152             :     uint16              GetLayerType(uint32 iLayer) const;
     153             :     uint64              GetLayerSize(uint32 iLayer) const;
     154             :     bool                IsLayerValid(uint32 iLayer) const;
     155             : 
     156             :     BlockLayer *        GetLayer(uint32 iLayer);
     157             : 
     158             :     uint32              CreateLayer(int16 nLayerType);
     159             : 
     160             :     void                DeleteLayer(uint32 iLayer);
     161             : 
     162             :     BlockInfoList       CreateNewBlocks(uint32 nBlockCount);
     163             : 
     164             :     void                CreateFreeBlocks(uint32 nBlockCount);
     165             : 
     166             :     void                AddFreeBlocks(const BlockInfoList & oBlockList);
     167             : 
     168             :     BlockInfo           GetFreeBlock(void);
     169             : };
     170             : 
     171             : } // namespace PCIDSK
     172             : 
     173             : #endif

Generated by: LCOV version 1.14