10 static int cacheRead_readFun(
int tileIndex,
void *tileBuf,
void *closure)
15 Rast3d_error(
"cacheRead_readFun: error in Rast3d_read_tile");
27 map->
nTiles, cacheRead_readFun, map);
29 Rast3d_error(
"initCacheRead: error in Rast3d_cache_new_read");
56 static int cacheWrite_readFun(
int tileIndex,
void *tileBuf,
void *closure)
61 size_t offs, offsLast;
65 pos = map->
index[tileIndex];
79 offs = pos * (nBytes +
sizeof(int));
83 if (lseek(map->
cacheFD, offs, SEEK_SET) == -1) {
87 if ((res = read(map->
cacheFD, tileBuf, nBytes)) < 0 ||
88 (
size_t)res != nBytes) {
95 map->
index[tileIndex] = -1;
110 if (lseek(map->
cacheFD, offsLast, SEEK_SET) == -1) {
111 Rast3d_error(
"cacheWrite_readFun: can't position file");
114 if ((res = read(map->
cacheFD,
xdr, nBytes +
sizeof(
int))) < 0 ||
115 (
size_t)res != nBytes +
sizeof(
int)) {
120 if (lseek(map->
cacheFD, offs, SEEK_SET) == -1) {
121 Rast3d_error(
"cacheWrite_readFun: can't position file");
124 if ((res = write(map->
cacheFD,
xdr, nBytes +
sizeof(
int))) < 0 ||
125 (
size_t)res != nBytes +
sizeof(
int)) {
130 index = *((
int *)((
unsigned char *)
xdr + nBytes));
131 map->
index[index] = -pos - 2;
140 static int cacheWrite_writeFun(
int tileIndex,
const void *tileBuf,
148 if (map->
index[tileIndex] != -1)
155 if (lseek(map->
cacheFD, offs, SEEK_SET) == -1) {
156 Rast3d_error(
"cacheWrite_writeFun: can't position file");
159 if ((res = write(map->
cacheFD, tileBuf, nBytes)) < 0 ||
160 (
size_t)res != nBytes) {
164 if (write(map->
cacheFD, &tileIndex,
sizeof(
int)) !=
sizeof(
int)) {
179 if (close(map->
cacheFD) != 0) {
180 Rast3d_error(
"disposeCacheWrite: could not close file");
194 static int initCacheWrite(
RASTER3D_Map *map,
int nCached)
207 map->
nTiles, cacheWrite_writeFun, map,
208 cacheWrite_readFun, map);
211 disposeCacheWrite(map);
212 Rast3d_error(
"initCacheWrite: error in Rast3d_cache_new");
224 if (!initCacheRead(map, nCached)) {
225 Rast3d_error(
"Rast3d_init_cache: error in initCacheRead");
231 if (!initCacheWrite(map, nCached)) {
232 Rast3d_error(
"Rast3d_init_cache: error in initCacheWrite");
252 if (!disposeCacheRead(map)) {
253 Rast3d_error(
"Rast3d_dispose_cache: error in disposeCacheRead");
259 if (!disposeCacheWrite(map)) {
260 Rast3d_error(
"Rast3d_dispose_cache: error in disposeCacheWrite");
269 static int cacheFlushFun(
int tileIndex,
const void *tileBuf,
void *closure)
274 Rast3d_error(
"cacheFlushFun: error in Rast3d_write_tile");
285 size_t tileIndex, nBytes;
291 "Rast3d_flush_all_tiles: error in Rast3d_cache_remove_all");
305 offs = map->
cachePosLast * (nBytes +
sizeof(int)) + nBytes;
307 if (lseek(map->
cacheFD, offs, SEEK_SET) == -1) {
308 Rast3d_error(
"Rast3d_flush_all_tiles: can't position file");
311 if (read(map->
cacheFD, &tileIndex,
sizeof(
int)) !=
sizeof(
int)) {
312 Rast3d_error(
"Rast3d_flush_all_tiles: can't read file");
317 Rast3d_error(
"Rast3d_flush_all_tiles: error in Rast3d_cache_load");
321 Rast3d_error(
"Rast3d_flush_all_tiles: error in Rast3d_cache_flush");
328 Rast3d_error(
"Rast3d_flush_all_tiles: error in Rast3d_cache_flush_all");
int Rast3d_flush_all_tiles(RASTER3D_Map *map)
int Rast3d_dispose_cache(RASTER3D_Map *map)
int Rast3d_init_cache(RASTER3D_Map *map, int nCached)
char * G_tempfile(void)
Returns a temporary file name.
void * Rast3d_cache_new_read(int, int, int, read_fn *, void *)
int Rast3d_cache_flush_all(RASTER3D_cache *)
void Rast3d_cache_dispose(RASTER3D_cache *)
void Rast3d_free(void *)
Same as free (ptr).
int Rast3d_cache_load(RASTER3D_cache *, int)
int Rast3d_cache_flush(RASTER3D_cache *, int)
void * Rast3d_cache_new(int, int, int, write_fn *, void *, read_fn *, void *)
void Rast3d_cache_set_remove_fun(RASTER3D_cache *, write_fn *, void *)
int Rast3d_read_tile(RASTER3D_Map *, int, void *, int)
Reads tile with index tileIndex into the tile buffer. The cells are stored with type type which must ...
void Rast3d_error(const char *,...) __attribute__((format(printf
int Rast3d_write_tile(RASTER3D_Map *, int, const void *, int)
Writes tile with index tileIndex to the file corresponding to map. It is assumed that the cells in ti...
int Rast3d_cache_remove_all(RASTER3D_cache *)
#define RASTER3D_READ_DATA