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
26class GDALRasterBand;
27
32class CPL_DLL GDALRasterBlock final
33{
34 friend class GDALAbstractBandBlockCache;
35
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:
63 GDALRasterBlock(int nXOffIn, int nYOffIn); /* only for lookup purpose */
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
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
147 {
148 return static_cast<GPtrDiff_t>(nXSize) * nYSize *
150 }
151
152 int TakeLock();
153 int DropLockForRemovalFromStorage();
154
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:
182};
183
184#endif
A single raster band (or channel).
Definition gdal_rasterband.h:105
A single raster block in the block cache.
Definition gdal_rasterblock.h:33
int GetDirty() const
Return the dirty flag.
Definition gdal_rasterblock.h:130
GDALRasterBand * GetBand()
Accessor to source GDALRasterBand object.
Definition gdal_rasterblock.h:157
void MarkDirty(void)
Mark the block as modified.
Definition gdalrasterblock.cpp:1087
int GetXSize() const
Return the width of the block.
Definition gdal_rasterblock.h:114
GPtrDiff_t GetBlockSize() const
Return the block size in bytes.
Definition gdal_rasterblock.h:146
int GetYSize() const
Return the height of the block.
Definition gdal_rasterblock.h:122
GDALDataType GetDataType() const
Return the data type.
Definition gdal_rasterblock.h:90
int GetXOff() const
Return the x offset of the top-left corner of the block.
Definition gdal_rasterblock.h:98
CPLErr Internalize(void)
Allocate memory for block.
Definition gdalrasterblock.cpp:871
void Touch(void)
Push block to top of LRU (least-recently used) list.
Definition gdalrasterblock.cpp:800
int AddLock(void)
Increment the lock count.
Definition gdal_rasterblock.h:72
void * GetDataRef(void)
Return the data buffer.
Definition gdal_rasterblock.h:138
int GetYOff() const
Return the y offset of the top-left corner of the block.
Definition gdal_rasterblock.h:106
GDALRasterBlock(GDALRasterBand *, int, int)
GDALRasterBlock Constructor.
Definition gdalrasterblock.cpp:527
void MarkClean(void)
Mark the block as unmodified.
Definition gdalrasterblock.cpp:1109
int DropLock(void)
Decrement the lock count.
Definition gdal_rasterblock.h:78
CPLErr
Error category.
Definition cpl_error.h:37
Core portability definitions for CPL.
int GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition cpl_port.h:246
#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
Public (C callable) GDAL entry points.
GDALDataType
Definition gdal.h:48
@ GDT_Unknown
Definition gdal.h:49
int GDALGetDataTypeSizeBytes(GDALDataType)
Get data type size in bytes.
Definition gdal_misc.cpp:374