10 static int cacheRead_readFun(
int tileIndex,
void *tileBuf,
void *closure)
15 Rast3d_error(
"cacheRead_readFun: error in Rast3d_read_tile");
23 static int initCacheRead(
RASTER3D_Map * map,
int nCached)
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;
64 pos = map->
index[tileIndex];
77 offs = pos * (nBytes +
sizeof(int));
81 if (lseek(map->
cacheFD, offs, SEEK_SET) == -1) {
85 if (read(map->
cacheFD, tileBuf, nBytes) != nBytes) {
92 map->
index[tileIndex] = -1;
107 if (lseek(map->
cacheFD, offsLast, SEEK_SET) == -1) {
108 Rast3d_error(
"cacheWrite_readFun: can't position file");
111 if (read(map->
cacheFD,
xdr, nBytes +
sizeof(
int)) != nBytes +
sizeof(
int)) {
116 if (lseek(map->
cacheFD, offs, SEEK_SET) == -1) {
117 Rast3d_error(
"cacheWrite_readFun: can't position file");
120 if (write(map->
cacheFD,
xdr, nBytes +
sizeof(
int)) !=
121 nBytes +
sizeof(
int)) {
126 index = *((
int*)((
unsigned char *)
xdr + nBytes));
127 map->
index[index] = -pos - 2;
137 cacheWrite_writeFun(
int tileIndex,
const void *tileBuf,
void *closure)
143 if (map->
index[tileIndex] != -1)
150 if (lseek(map->
cacheFD, offs, SEEK_SET) == -1) {
151 Rast3d_error(
"cacheWrite_writeFun: can't position file");
154 if (write(map->
cacheFD, tileBuf, nBytes) != nBytes) {
158 if (write(map->
cacheFD, &tileIndex,
sizeof(
int)) !=
sizeof(
int)) {
173 if (close(map->
cacheFD) != 0) {
174 Rast3d_error(
"disposeCacheWrite: could not close file");
188 static int initCacheWrite(
RASTER3D_Map * map,
int nCached)
203 cacheWrite_writeFun, map,
204 cacheWrite_readFun, map);
207 disposeCacheWrite(map);
208 Rast3d_error(
"initCacheWrite: error in Rast3d_cache_new");
220 if (!initCacheRead(map, nCached)) {
221 Rast3d_error(
"Rast3d_init_cache: error in initCacheRead");
227 if (!initCacheWrite(map, nCached)) {
228 Rast3d_error(
"Rast3d_init_cache: error in initCacheWrite");
248 if (!disposeCacheRead(map)) {
249 Rast3d_error(
"Rast3d_dispose_cache: error in disposeCacheRead");
255 if (!disposeCacheWrite(map)) {
256 Rast3d_error(
"Rast3d_dispose_cache: error in disposeCacheWrite");
266 static int cacheFlushFun(
int tileIndex,
const void *tileBuf,
void *closure)
271 Rast3d_error(
"cacheFlushFun: error in Rast3d_write_tile");
282 size_t tileIndex, nBytes;
287 Rast3d_error(
"Rast3d_flush_all_tiles: error in Rast3d_cache_remove_all");
301 offs = map->
cachePosLast * (nBytes +
sizeof(int)) + nBytes;
303 if (lseek(map->
cacheFD, offs, SEEK_SET) == -1) {
304 Rast3d_error(
"Rast3d_flush_all_tiles: can't position file");
307 if (read(map->
cacheFD, &tileIndex,
sizeof(
int)) !=
sizeof(
int)) {
308 Rast3d_error(
"Rast3d_flush_all_tiles: can't read file");
313 Rast3d_error(
"Rast3d_flush_all_tiles: error in Rast3d_cache_load");
317 Rast3d_error(
"Rast3d_flush_all_tiles: error in Rast3d_cache_flush");
324 Rast3d_error(
"Rast3d_flush_all_tiles: error in Rast3d_cache_flush_all");
int Rast3d_init_cache(RASTER3D_Map *map, int nCached)
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 ...
int Rast3d_cache_flush(RASTER3D_cache *, int)
int Rast3d_dispose_cache(RASTER3D_Map *map)
void Rast3d_error(const char *,...) __attribute__((format(printf
char * G_tempfile(void)
Returns a temporary file name.
#define RASTER3D_READ_DATA
int Rast3d_flush_all_tiles(RASTER3D_Map *map)
int Rast3d_cache_load(RASTER3D_cache *, int)
void Rast3d_cache_set_remove_fun(RASTER3D_cache *, write_fn *, void *)
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...
void * Rast3d_cache_new(int, int, int, write_fn *, void *, read_fn *, void *)
int Rast3d_cache_flush_all(RASTER3D_cache *)
void * Rast3d_cache_new_read(int, int, int, read_fn *, void *)
int Rast3d_cache_remove_all(RASTER3D_cache *)
void Rast3d_free(void *)
Same as free (ptr).
void Rast3d_cache_dispose(RASTER3D_cache *)