mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-09 21:21:19 -06:00
Better variable names in DiskCache
This commit is contained in:
@@ -102,7 +102,7 @@ namespace openspace {
|
||||
|
||||
|
||||
|
||||
void TileIOResult::serialize(std::ostream& os) {
|
||||
void TileIOResult::serializeMetaData(std::ostream& os) {
|
||||
os << dimensions.x << " " << dimensions.y << " " << dimensions.z << std::endl;
|
||||
os << chunkIndex.x << " " << chunkIndex.y << " " << chunkIndex.level << std::endl;
|
||||
os << error << std::endl;
|
||||
@@ -114,19 +114,10 @@ namespace openspace {
|
||||
}
|
||||
|
||||
os << nBytesImageData << std::endl;
|
||||
/*
|
||||
char binaryDataSeparator = 'Ö'; // sweden represent!
|
||||
os << binaryDataSeparator;
|
||||
|
||||
if (nBytesImageData) {
|
||||
char* buffer = reinterpret_cast<char*>(imageData);
|
||||
os.write(buffer, nBytesImageData);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
TileIOResult TileIOResult::deserialize(std::istream& is) {
|
||||
TileIOResult TileIOResult::deserializeMetaData(std::istream& is) {
|
||||
TileIOResult res;
|
||||
is >> res.dimensions.x >> res.dimensions.y >> res.dimensions.z;
|
||||
is >> res.chunkIndex.x >> res.chunkIndex.y >> res.chunkIndex.level;
|
||||
@@ -146,12 +137,6 @@ namespace openspace {
|
||||
is >> binaryDataSeparator; // not used
|
||||
|
||||
char* buffer = new char[res.nBytesImageData]();
|
||||
/*is.read(buffer, res.nBytesImageData);
|
||||
for (size_t i = 0; i < res.nBytesImageData; i++){
|
||||
is.get(buffer[i]);
|
||||
}
|
||||
res.imageData = reinterpret_cast<void*>(buffer);
|
||||
*/
|
||||
return std::move(res);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,8 +73,8 @@ namespace openspace {
|
||||
CPLErr error;
|
||||
size_t nBytesImageData;
|
||||
|
||||
void serialize(std::ostream& s);
|
||||
static TileIOResult deserialize(std::istream& s);
|
||||
void serializeMetaData(std::ostream& s);
|
||||
static TileIOResult deserializeMetaData(std::istream& s);
|
||||
|
||||
static TileIOResult createDefaultRes();
|
||||
|
||||
|
||||
@@ -55,19 +55,19 @@ namespace openspace {
|
||||
}
|
||||
|
||||
bool TileDiskCache::has(const ChunkIndex& chunkIndex) const {
|
||||
File metaFile = getMetaFile(chunkIndex);
|
||||
File metaFile = getMetaDataFile(chunkIndex);
|
||||
return FileSys.fileExists(metaFile);
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<TileIOResult> TileDiskCache::get(const ChunkIndex& chunkIndex) {
|
||||
File metaFile = getMetaFile(chunkIndex);
|
||||
File metaDataFile = getMetaDataFile(chunkIndex);
|
||||
File dataFile = getDataFile(chunkIndex);
|
||||
if (FileSys.fileExists(metaFile) && FileSys.fileExists(dataFile)) {
|
||||
if (FileSys.fileExists(metaDataFile) && FileSys.fileExists(dataFile)) {
|
||||
// read meta
|
||||
std::ifstream ifsMeta;
|
||||
ifsMeta.open(metaFile.path(), std::ifstream::in);
|
||||
TileIOResult res = TileIOResult::deserialize(ifsMeta);
|
||||
ifsMeta.open(metaDataFile.path(), std::ifstream::in);
|
||||
TileIOResult res = TileIOResult::deserializeMetaData(ifsMeta);
|
||||
ifsMeta.close();
|
||||
|
||||
// read data
|
||||
@@ -83,11 +83,11 @@ namespace openspace {
|
||||
}
|
||||
|
||||
bool TileDiskCache::put(const ChunkIndex& chunkIndex, std::shared_ptr<TileIOResult> tileIOResult) {
|
||||
File metaFile = getMetaFile(chunkIndex);
|
||||
if (!FileSys.fileExists(metaFile)) {
|
||||
File metaDataFile = getMetaDataFile(chunkIndex);
|
||||
if (!FileSys.fileExists(metaDataFile)) {
|
||||
std::ofstream ofsMeta;
|
||||
ofsMeta.open(metaFile.path());
|
||||
tileIOResult->serialize(ofsMeta);
|
||||
ofsMeta.open(metaDataFile.path());
|
||||
tileIOResult->serializeMetaData(ofsMeta);
|
||||
ofsMeta.close();
|
||||
|
||||
std::ofstream ofsData;
|
||||
@@ -110,7 +110,7 @@ namespace openspace {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
File TileDiskCache::getMetaFile(const ChunkIndex& chunkIndex) const {
|
||||
File TileDiskCache::getMetaDataFile(const ChunkIndex& chunkIndex) const {
|
||||
return File(getFilePath(chunkIndex) + ".meta");
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace openspace {
|
||||
Directory _cacheDir;
|
||||
|
||||
std::string getFilePath(const ChunkIndex& chunkIndex) const;
|
||||
File getMetaFile(const ChunkIndex& chunkIndex) const;
|
||||
File getMetaDataFile(const ChunkIndex& chunkIndex) const;
|
||||
File getDataFile(const ChunkIndex& chunkIndex) const;
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user