LCOV - code coverage report
Current view: top level - frmts/pcidsk/sdk/blockdir - blocktiledir.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 26 40 65.0 %
Date: 2024-11-21 22:18:42 Functions: 8 9 88.9 %

          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             :  * SPDX-License-Identifier: MIT
      10             :  ****************************************************************************/
      11             : 
      12             : #include "blockdir/blocktiledir.h"
      13             : #include "blockdir/blocktilelayer.h"
      14             : #include "blockdir/blockfile.h"
      15             : #include "core/pcidsk_utils.h"
      16             : #include <cassert>
      17             : 
      18             : using namespace PCIDSK;
      19             : 
      20             : /************************************************************************/
      21             : /*                              BlockTileDir()                          */
      22             : /************************************************************************/
      23             : 
      24             : /**
      25             :  * Constructor.
      26             :  *
      27             :  * @param poFile The associated file object.
      28             :  * @param nSegment The segment of the block directory.
      29             :  */
      30          24 : BlockTileDir::BlockTileDir(BlockFile * poFile, uint16 nSegment)
      31          24 :     : BlockDir(poFile, nSegment)
      32             : {
      33          24 : }
      34             : 
      35             : /************************************************************************/
      36             : /*                              BlockTileDir()                          */
      37             : /************************************************************************/
      38             : 
      39             : /**
      40             :  * Constructor.
      41             :  *
      42             :  * @param poFile The associated file object.
      43             :  * @param nSegment The segment of the block directory.
      44             :  * @param nVersion The version of the block directory.
      45             :  */
      46           8 : BlockTileDir::BlockTileDir(BlockFile * poFile, uint16 nSegment, uint16 nVersion)
      47           8 :     : BlockDir(poFile, nSegment, nVersion)
      48             : {
      49           8 : }
      50             : 
      51             : /************************************************************************/
      52             : /*                             ~BlockTileDir()                          */
      53             : /************************************************************************/
      54             : 
      55             : /**
      56             :  * Destructor.
      57             :  */
      58          32 : BlockTileDir::~BlockTileDir(void)
      59             : {
      60          32 :     assert(moLayerInfoList.size() == moTileLayerInfoList.size());
      61             : 
      62          68 :     for (auto poIter : moLayerInfoList)
      63          36 :         delete poIter;
      64             : 
      65          68 :     for (auto poIter : moTileLayerInfoList)
      66          36 :         delete poIter;
      67          32 : }
      68             : 
      69             : /************************************************************************/
      70             : /*                              GetTileLayer()                          */
      71             : /************************************************************************/
      72             : 
      73             : /**
      74             :  * Gets the block tile layer at the specified index.
      75             :  *
      76             :  * @param iLayer The index of the block tile layer.
      77             :  *
      78             :  * @return The block tile layer at the specified index.
      79             :  */
      80          44 : BlockTileLayer * BlockTileDir::GetTileLayer(uint32 iLayer)
      81             : {
      82          44 :     return dynamic_cast<BlockTileLayer *>(GetLayer(iLayer));
      83             : }
      84             : 
      85             : /************************************************************************/
      86             : /*                                                                      */
      87             : /************************************************************************/
      88             : 
      89             : /**
      90             :  * Gets the number of new blocks to create.
      91             :  *
      92             :  * @return The number of new blocks to create.
      93             :  */
      94           8 : uint32 BlockTileDir::GetNewBlockCount(void) const
      95             : {
      96           8 :     return (uint32) ((unsigned long long)(mpoFile->GetImageFileSize() / GetBlockSize()) * 0.01);
      97             : }
      98             : 
      99             : /************************************************************************/
     100             : /*                             SwapBlockLayer()                         */
     101             : /************************************************************************/
     102             : 
     103             : /**
     104             :  * Swaps the specified block layer info.
     105             :  *
     106             :  * @param psBlockLayer The block layer info to swap.
     107             :  */
     108          40 : void BlockTileDir::SwapBlockLayer(BlockLayerInfo * psBlockLayer)
     109             : {
     110          40 :     if (!mbNeedsSwap)
     111          40 :         return;
     112             : 
     113           0 :     SwapData(&psBlockLayer->nLayerType, 2, 1);
     114           0 :     SwapData(&psBlockLayer->nStartBlock, 4, 1);
     115           0 :     SwapData(&psBlockLayer->nBlockCount, 4, 1);
     116           0 :     SwapData(&psBlockLayer->nLayerSize, 8, 1);
     117             : }
     118             : 
     119             : /************************************************************************/
     120             : /*                             SwapTileLayer()                          */
     121             : /************************************************************************/
     122             : 
     123             : /**
     124             :  * Swaps the specified tile layer info.
     125             :  *
     126             :  * @param psTileLayer The tile layer info to swap.
     127             :  */
     128          31 : void BlockTileDir::SwapTileLayer(TileLayerInfo * psTileLayer)
     129             : {
     130          31 :     if (!mbNeedsSwap)
     131          31 :         return;
     132             : 
     133           0 :     SwapData(&psTileLayer->nXSize, 4, 1);
     134           0 :     SwapData(&psTileLayer->nYSize, 4, 1);
     135           0 :     SwapData(&psTileLayer->nTileXSize, 4, 1);
     136           0 :     SwapData(&psTileLayer->nTileYSize, 4, 1);
     137           0 :     SwapData(&psTileLayer->bNoDataValid, 2, 1);
     138           0 :     SwapData(&psTileLayer->dfNoDataValue, 8, 1);
     139             : }
     140             : 
     141             : /************************************************************************/
     142             : /*                               SwapBlock()                            */
     143             : /************************************************************************/
     144             : 
     145             : /**
     146             :  * Swaps the specified block info array.
     147             :  *
     148             :  * @param psBlock The block info array to swap.
     149             :  * @param nCount The number of block info.
     150             :  */
     151          19 : void BlockTileDir::SwapBlock(BlockInfo * psBlock, size_t nCount)
     152             : {
     153          19 :     if (!mbNeedsSwap)
     154          19 :         return;
     155             : 
     156           0 :     for (BlockInfo * psEnd = psBlock + nCount;
     157           0 :          psBlock < psEnd; psBlock++)
     158             :     {
     159           0 :         SwapData(&psBlock->nSegment, 2, 1);
     160           0 :         SwapData(&psBlock->nStartBlock, 4, 1);
     161             :     }
     162             : }

Generated by: LCOV version 1.14