diff --git a/packages/geo/RasterFileDictionary.cpp b/packages/geo/RasterFileDictionary.cpp index 67ffd762..2a455752 100644 --- a/packages/geo/RasterFileDictionary.cpp +++ b/packages/geo/RasterFileDictionary.cpp @@ -81,13 +81,14 @@ uint64_t RasterFileDictionary::add(const string& fileName, bool sample) const char* RasterFileDictionary::get(uint64_t fileId) { const char* fileName = ""; + uint32_t index; - /* Mask upper 32 bits to get index into vector */ - const uint32_t index = static_cast(fileId & 0xFFFFFFFF); - if(index < fileVector.size()) + if(getIndex(fileId, index)) { + /* Mask upper 32 bits to get index into vector */ fileName = fileVector[index].c_str(); } + return fileName; } @@ -96,9 +97,9 @@ const char* RasterFileDictionary::get(uint64_t fileId) *----------------------------------------------------------------------------*/ void RasterFileDictionary::setSample(uint64_t sampleFileId) { - /* Make sure sampleFileId is valid */ - const char* fileName = get(sampleFileId); - if(fileName && *fileName != '\0') + uint32_t index; + + if(getIndex(sampleFileId, index)) { sampleIdSet.insert(sampleFileId); } diff --git a/packages/geo/RasterFileDictionary.h b/packages/geo/RasterFileDictionary.h index bc6c51c5..bfada6a9 100644 --- a/packages/geo/RasterFileDictionary.h +++ b/packages/geo/RasterFileDictionary.h @@ -51,6 +51,8 @@ class RasterFileDictionary /*-------------------------------------------------------------------- * Constants *--------------------------------------------------------------------*/ + const uint64_t UPPER32_MASK = 0xFFFFFFFF00000000; + const uint32_t INDEX_MASK = 0xFFFFFFFF; /*-------------------------------------------------------------------- * Typedefs @@ -64,6 +66,7 @@ class RasterFileDictionary const char* get (uint64_t fileId); void setSample(uint64_t sampleFileId); void clear (void); + size_t size (void) const { return fileVector.size(); } const std::set& getSampleIds(void) const; RasterFileDictionary copy(void); @@ -74,6 +77,16 @@ class RasterFileDictionary * Methods *--------------------------------------------------------------------*/ + /* Force inline by implementing here */ + bool getIndex(uint64_t fileId, uint32_t& index) + { + if((fileId & UPPER32_MASK) == keySpace) + { + index = static_cast(fileId & INDEX_MASK); + return index < fileVector.size(); + } + return false; + } /*-------------------------------------------------------------------- * Data