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 : #ifndef PCIDSK_BLOCK_DIR_H 13 : #define PCIDSK_BLOCK_DIR_H 14 : 15 : #include "pcidsk_config.h" 16 : #include <vector> 17 : #include <string> 18 : 19 : namespace PCIDSK 20 : { 21 : 22 : class BlockFile; 23 : class BlockLayer; 24 : 25 : #define INVALID_SEGMENT ((uint16) -1) 26 : #define INVALID_LAYER ((uint32) -1) 27 : #define INVALID_BLOCK ((uint32) -1) 28 : #define INVALID_OFFSET ((uint64) -1) 29 : 30 : #pragma pack(push, 1) 31 : 32 : /// The block info structure. 33 : struct BlockInfo 34 : { 35 : uint16 nSegment; 36 : uint32 nStartBlock; 37 : }; 38 : 39 : #pragma pack(pop) 40 : 41 : /// The block layer list type. 42 : typedef std::vector<BlockLayer *> BlockLayerList; 43 : 44 : /// The block info list type. 45 : typedef std::vector<BlockInfo> BlockInfoList; 46 : 47 : /************************************************************************/ 48 : /* class BlockDir */ 49 : /************************************************************************/ 50 : 51 : /** 52 : * Class used as the base class for all block directories. 53 : */ 54 : class PCIDSK_DLL BlockDir 55 : { 56 : protected: 57 : /// The associated file. 58 : BlockFile * mpoFile; 59 : 60 : /// The block directory segment. 61 : uint16 mnSegment; 62 : 63 : /// The block directory version. 64 : uint16 mnVersion; 65 : 66 : // The endianness of the block directory on disk. 67 : char mchEndianness; 68 : 69 : // If the block directory on disk needs swapping. 70 : bool mbNeedsSwap; 71 : 72 : /// The block directory validity info. 73 : uint16 mnValidInfo; 74 : 75 : /// If the block directory is modified. 76 : bool mbModified; 77 : 78 : /// If the block directory is on disk. 79 : bool mbOnDisk; 80 : 81 : /// The block layer list. 82 : BlockLayerList moLayerList; 83 : 84 : /// The free block layer. 85 : BlockLayer * mpoFreeBlockLayer; 86 : 87 : virtual void ReadLayerBlocks(uint32 iLayer) = 0; 88 : virtual void ReadFreeBlockLayer(void) = 0; 89 : virtual void WriteDir(void) = 0; 90 : 91 : virtual BlockLayer *_CreateLayer(uint16 nLayerType, uint32 iLayer) = 0; 92 : virtual void _DeleteLayer(uint32 iLayer) = 0; 93 : 94 : virtual uint32 GetNewBlockCount(void) const = 0; 95 : 96 : virtual std::string GetDataSegmentName(void) const = 0; 97 : virtual std::string GetDataSegmentDesc(void) const = 0; 98 : 99 18 : virtual void ValidateNewBlocks(CPL_UNUSED uint32 & nBlockCount, 100 18 : CPL_UNUSED bool bFreeBlocks) { } 101 : 102 : void SwapValue(uint16 * pnValue) const; 103 : 104 : // We need the block layer interface to be friend so that it can request 105 : // to read block information off of the disk. 106 : friend class BlockLayer; 107 : 108 : public: 109 : BlockDir(BlockFile * poFile, uint16 nSegment); 110 : BlockDir(BlockFile * poFile, uint16 nSegment, uint16 nVersion); 111 : 112 : virtual ~BlockDir(void); 113 : 114 : /** 115 : * Gets the block size of the block directory. 116 : * 117 : * @return The block size of the block directory. 118 : */ 119 : virtual uint32 GetBlockSize(void) const = 0; 120 : 121 : void Sync(void); 122 : 123 : BlockFile * GetFile(void) const; 124 : 125 : uint16 GetSegmentIndex(void) const; 126 : 127 : uint16 GetVersion(void) const; 128 : 129 : bool NeedsSwap(void) const; 130 : 131 : bool IsValid(void) const; 132 : 133 : bool IsModified(void) const; 134 : 135 : uint32 GetLayerCount(void) const; 136 : uint16 GetLayerType(uint32 iLayer) const; 137 : uint64 GetLayerSize(uint32 iLayer) const; 138 : bool IsLayerValid(uint32 iLayer) const; 139 : 140 : BlockLayer * GetLayer(uint32 iLayer); 141 : 142 : uint32 CreateLayer(int16 nLayerType); 143 : 144 : void DeleteLayer(uint32 iLayer); 145 : 146 : BlockInfoList CreateNewBlocks(uint32 nBlockCount); 147 : 148 : void CreateFreeBlocks(uint32 nBlockCount); 149 : 150 : void AddFreeBlocks(const BlockInfoList & oBlockList); 151 : 152 : BlockInfo GetFreeBlock(void); 153 : }; 154 : 155 : } // namespace PCIDSK 156 : 157 : #endif