GDAL

gdal_rasterblock.h
1/******************************************************************************
2 *
3 * Name: gdal_rasterblock.h
4 * Project: GDAL Core
5 * Purpose: Declaration of GDALRasterBlock class
6 * Author: Frank Warmerdam, warmerdam@pobox.com
7 *
8 ******************************************************************************
9 * Copyright (c) 1998, Frank Warmerdam
10 * Copyright (c) 2007-2014, Even Rouault <even dot rouault at spatialys.com>
11 *
12 * SPDX-License-Identifier: MIT
13 ****************************************************************************/
14
15#ifndef GDALRASTERBLOCK_H_INCLUDED
16#define GDALRASTERBLOCK_H_INCLUDED
17
18#include "cpl_port.h"
19#include "cpl_atomic_ops.h"
20#include "gdal.h"
21
22/* ******************************************************************** */
23/* GDALRasterBlock */
24/* ******************************************************************** */
25
26 class GDALRasterBand;
27
32 class CPL_DLL GDALRasterBlock final
33{
34 friend class GDALAbstractBandBlockCache;
35
36 GDALDataType eType = GDT_Unknown;
37
38 bool bDirty = false;
39 volatile int nLockCount = 0;
40
41 int nXOff = 0;
42 int nYOff = 0;
43
44 int nXSize = 0;
45 int nYSize = 0;
46
47 void *pData = nullptr;
48
49 GDALRasterBand *poBand = nullptr;
50
51 GDALRasterBlock *poNext = nullptr;
52 GDALRasterBlock *poPrevious = nullptr;
53
54 bool bMustDetach = false;
55
56 CPL_INTERNAL void Detach_unlocked(void);
57 CPL_INTERNAL void Touch_unlocked(void);
58
59 CPL_INTERNAL void RecycleFor(int nXOffIn, int nYOffIn);
60
61 public:
62 GDALRasterBlock(GDALRasterBand *, int, int);
63 GDALRasterBlock(int nXOffIn, int nYOffIn); /* only for lookup purpose */
64 ~GDALRasterBlock();
65
66 CPLErr Internalize(void);
67 void Touch(void);
68 void MarkDirty(void);
69 void MarkClean(void);
70
72 int AddLock(void)
73 {
74 return CPLAtomicInc(&nLockCount);
75 }
76
78 int DropLock(void)
79 {
80 return CPLAtomicDec(&nLockCount);
81 }
82
83 void Detach();
84
85 CPLErr Write();
86
90 GDALDataType GetDataType() const
91 {
92 return eType;
93 }
94
98 int GetXOff() const
99 {
100 return nXOff;
101 }
102
106 int GetYOff() const
107 {
108 return nYOff;
109 }
110
114 int GetXSize() const
115 {
116 return nXSize;
117 }
118
122 int GetYSize() const
123 {
124 return nYSize;
125 }
126
130 int GetDirty() const
131 {
132 return bDirty;
133 }
134
138 void *GetDataRef(void)
139 {
140 return pData;
141 }
142
146 GPtrDiff_t GetBlockSize() const
147 {
148 return static_cast<GPtrDiff_t>(nXSize) * nYSize *
149 GDALGetDataTypeSizeBytes(eType);
150 }
151
152 int TakeLock();
153 int DropLockForRemovalFromStorage();
154
157 GDALRasterBand *GetBand()
158 {
159 return poBand;
160 }
161
162 static void FlushDirtyBlocks();
163 static int FlushCacheBlock(int bDirtyBlocksOnly = FALSE);
164 static void Verify();
165
166 static void EnterDisableDirtyBlockFlush();
167 static void LeaveDisableDirtyBlockFlush();
168
169#ifdef notdef
170 static void CheckNonOrphanedBlocks(GDALRasterBand *poBand);
171 void DumpBlock();
172 static void DumpAll();
173#endif
174
175 /* Should only be called by GDALDestroyDriverManager() */
177 CPL_INTERNAL static void DestroyRBMutex();
179
180 private:
181 CPL_DISALLOW_COPY_ASSIGN(GDALRasterBlock)
182};
183
184#endif
GDALRasterBand
A single raster band (or channel).
Definition gdal_rasterband.h:105
GDALRasterBlock
A single raster block in the block cache.
Definition gdal_rasterblock.h:33
GDALRasterBlock::GetDirty
int GetDirty() const
Return the dirty flag.
Definition gdal_rasterblock.h:130
GDALRasterBlock::GetBand
GDALRasterBand * GetBand()
Accessor to source GDALRasterBand object.
Definition gdal_rasterblock.h:157
GDALRasterBlock::GetXSize
int GetXSize() const
Return the width of the block.
Definition gdal_rasterblock.h:114
GDALRasterBlock::GetBlockSize
GPtrDiff_t GetBlockSize() const
Return the block size in bytes.
Definition gdal_rasterblock.h:146
GDALRasterBlock::GetYSize
int GetYSize() const
Return the height of the block.
Definition gdal_rasterblock.h:122
GDALRasterBlock::GetDataType
GDALDataType GetDataType() const
Return the data type.
Definition gdal_rasterblock.h:90
GDALRasterBlock::GetXOff
int GetXOff() const
Return the x offset of the top-left corner of the block.
Definition gdal_rasterblock.h:98
GDALRasterBlock::AddLock
int AddLock(void)
Increment the lock count.
Definition gdal_rasterblock.h:72
GDALRasterBlock::GetDataRef
void * GetDataRef(void)
Return the data buffer.
Definition gdal_rasterblock.h:138
GDALRasterBlock::GetYOff
int GetYOff() const
Return the y offset of the top-left corner of the block.
Definition gdal_rasterblock.h:106
GDALRasterBlock::DropLock
int DropLock(void)
Decrement the lock count.
Definition gdal_rasterblock.h:78
CPLErr
CPLErr
Error category.
Definition cpl_error.h:37
cpl_port.h
Core portability definitions for CPL.
GPtrDiff_t
int GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition cpl_port.h:246
CPL_DISALLOW_COPY_ASSIGN
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition cpl_port.h:936
gdal.h
Public (C callable) GDAL entry points.
GDALDataType
GDALDataType
Definition gdal.h:48
GDT_Unknown
@ GDT_Unknown
Definition gdal.h:49
GDALGetDataTypeSizeBytes
int GDALGetDataTypeSizeBytes(GDALDataType)
Get data type size in bytes.
Definition gdal_misc.cpp:374