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_BINARY_TILE_DIR_H
29 #define PCIDSK_BINARY_TILE_DIR_H
30 
31 #include "blockdir/blocktiledir.h"
32 
33 namespace PCIDSK
34 {
35 
36 class BinaryTileLayer;
37 
38 /************************************************************************/
39 /*                           class BinaryTileDir                        */
40 /************************************************************************/
41 
42 /**
43  * Class used to manage a binary block tile directory.
44  *
45  * @see BlockTileDir
46  */
47 class PCIDSK_DLL BinaryTileDir : public BlockTileDir
48 {
49 public:
50 #pragma pack(push, 1)
51 
52     /// The block directory info.
53     struct BlockDirInfo
54     {
55         uint32 nLayerCount;
56         uint32 nBlockSize;
57     };
58 
59 #pragma pack(pop)
60 
61 protected:
62     // The block directory info.
63     BlockDirInfo        msBlockDir;
64 
65     size_t              GetDirSize(void) const;
66 
67     void                InitBlockList(BinaryTileLayer * poLayer);
68 
69     virtual void        ReadLayerBlocks(uint32 iLayer) override;
70     virtual void        ReadFreeBlockLayer(void) override;
71     virtual void        WriteDir(void) override;
72 
73     virtual BlockLayer *_CreateLayer(uint16 nLayerType, uint32 iLayer) override;
74     virtual void        _DeleteLayer(uint32 iLayer) override;
75 
76     virtual std::string GetDataSegmentName(void) const override;
77     virtual std::string GetDataSegmentDesc(void) const override;
78 
79     void                SwapBlockDir(BlockDirInfo * psBlockDir);
80 
81 public:
82     static uint32       GetOptimizedBlockSize(BlockFile * poFile);
83     static size_t       GetOptimizedDirSize(BlockFile * poFile);
84 
85     BinaryTileDir(BlockFile * poFile, uint16 nSegment);
86     BinaryTileDir(BlockFile * poFile, uint16 nSegment, uint32 nBlockSize);
87 
88     BinaryTileLayer *   GetTileLayer(uint32 iLayer);
89 
90     virtual uint32      GetBlockSize(void) const override;
91 };
92 
93 } // namespace PCIDSK
94 
95 #endif
96