From 71d184c39bdcd6b7bcc25716e77897d8d1d8ddf8 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Wed, 19 Sep 2012 11:46:41 +0200 Subject: [PATCH] removing old style casts and unused parameters and fixed unsafe float comparisons --- DataStructures/DeallocatingVector.h | 8 +++--- DataStructures/NNGrid.h | 39 +++++++++++++++-------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/DataStructures/DeallocatingVector.h b/DataStructures/DeallocatingVector.h index db0cb49c5..997622c37 100644 --- a/DataStructures/DeallocatingVector.h +++ b/DataStructures/DeallocatingVector.h @@ -235,7 +235,7 @@ public: ++mCurrentSize; } - inline void reserve(const size_t new_size) const { + inline void reserve(const size_t) const { //don't do anything } @@ -266,7 +266,7 @@ public: } inline iterator begin() { - return iterator((size_t)0, mBucketList); + return iterator(static_cast(0), mBucketList); } inline iterator end() { @@ -274,7 +274,7 @@ public: } inline deallocation_iterator dbegin() { - return deallocation_iterator((size_t)0, mBucketList); + return deallocation_iterator(static_cast(0), mBucketList); } inline deallocation_iterator dend() { @@ -282,7 +282,7 @@ public: } inline const_iterator begin() const { - return const_iterator((size_t)0, mBucketList); + return const_iterator(static_cast(0), mBucketList); } inline const_iterator end() const { diff --git a/DataStructures/NNGrid.h b/DataStructures/NNGrid.h index 5588b1dfd..17c40dd06 100644 --- a/DataStructures/NNGrid.h +++ b/DataStructures/NNGrid.h @@ -23,6 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include +#include #include #include #include @@ -84,7 +85,7 @@ public: void OpenIndexFiles() { assert(ramInFile.is_open()); - ramInFile.read((char*)&ramIndexTable[0], sizeof(unsigned long)*1024*1024); + ramInFile.read(static_cast(static_cast(&ramIndexTable[0]) ), sizeof(unsigned long)*1024*1024); ramInFile.close(); } @@ -187,7 +188,7 @@ public: smallestEdge = candidate; //} else if(tmpDist < dist) { //INFO("a) ignored " << candidate.edgeBasedNode << " at distance " << std::fabs(dist - tmpDist)); - } else if(DoubleEpsilonCompare(dist, tmpDist) && 1 == std::abs((int)candidate.edgeBasedNode-(int)resultNode.edgeBasedNode)) { + } else if(DoubleEpsilonCompare(dist, tmpDist) && 1 == std::abs(static_cast(candidate.edgeBasedNode)-static_cast(resultNode.edgeBasedNode) )) { resultNode.weight2 = candidate.weight; //INFO("b) " << candidate.edgeBasedNode << ", dist: " << tmpDist); } @@ -343,7 +344,7 @@ private: indexIntoTmpBuffer += FlushEntriesWithSameFileIndexToBuffer(entriesWithSameFileIndex, tmpBuffer, indexIntoTmpBuffer); assert(entriesWithSameFileIndex.size() == 0); - indexOutFile.write((char *)&cellIndex[0],32*32*sizeof(unsigned long)); + indexOutFile.write(static_cast(static_cast(&cellIndex[0])),32*32*sizeof(unsigned long)); numberOfWrittenBytes += 32*32*sizeof(unsigned long); //write contents of tmpbuffer to disk @@ -366,12 +367,12 @@ private: } //write length of bucket - memcpy((char*)&(tmpBuffer[index+counter]), (char *)&lengthOfBucket, sizeof(lengthOfBucket)); + memcpy(static_cast(static_cast(&(tmpBuffer[index+counter]))), static_cast(static_cast(&lengthOfBucket)), sizeof(lengthOfBucket)); counter += sizeof(lengthOfBucket); BOOST_FOREACH(const GridEntry & entry, vectorWithSameFileIndex) { - char * data = (char *)&(entry.edge); - memcpy((char*)&(tmpBuffer[index+counter]), data, sizeof(entry.edge)); + char * data = static_cast(static_cast(&(entry.edge) )); + memcpy(static_cast(static_cast(&(tmpBuffer[index+counter]) )), data, sizeof(entry.edge)); counter += sizeof(entry.edge); } //Freeing data @@ -398,7 +399,7 @@ private: //only read the single necessary cell index localStream->seekg(startIndexInFile+(enumeratedIndex*sizeof(unsigned long))); unsigned long fetchedIndex = 0; - localStream->read((char*) &fetchedIndex, sizeof(unsigned long)); + localStream->read(static_cast( static_cast(&fetchedIndex)), sizeof(unsigned long)); if(fetchedIndex == ULONG_MAX) { return; @@ -408,9 +409,9 @@ private: unsigned lengthOfBucket; unsigned currentSizeOfResult = result.size(); localStream->seekg(position); - localStream->read((char *)&(lengthOfBucket), sizeof(unsigned)); + localStream->read(static_cast( static_cast(&(lengthOfBucket))), sizeof(unsigned)); result.resize(currentSizeOfResult+lengthOfBucket); - localStream->read((char *)&result[currentSizeOfResult], lengthOfBucket*sizeof(_GridEdge)); + localStream->read(static_cast( static_cast(&result[currentSizeOfResult])), lengthOfBucket*sizeof(_GridEdge)); } @@ -434,7 +435,7 @@ private: } localStream->seekg(startIndexInFile); - localStream->read((char*) cellIndex, 32*32*sizeof(unsigned long)); + localStream->read(static_cast(static_cast( cellIndex)), 32*32*sizeof(unsigned long)); assert(cellMap.find(fileIndex) != cellMap.end()); if(cellIndex[cellMap[fileIndex]] == ULONG_MAX) { return; @@ -444,9 +445,9 @@ private: unsigned lengthOfBucket; unsigned currentSizeOfResult = result.size(); localStream->seekg(position); - localStream->read((char *)&(lengthOfBucket), sizeof(unsigned)); + localStream->read(static_cast(static_cast(&(lengthOfBucket))), sizeof(unsigned)); result.resize(currentSizeOfResult+lengthOfBucket); - localStream->read((char *)&result[currentSizeOfResult], lengthOfBucket*sizeof(_GridEdge)); + localStream->read(static_cast(static_cast(&result[currentSizeOfResult])), lengthOfBucket*sizeof(_GridEdge)); } inline void AddEdge(const _GridEdge & edge) { @@ -461,14 +462,14 @@ private: inline double ComputeDistance(const _Coordinate& inputPoint, const _Coordinate& source, const _Coordinate& target, _Coordinate& nearest, double *r) { - const double x = (double)inputPoint.lat; - const double y = (double)inputPoint.lon; - const double a = (double)source.lat; - const double b = (double)source.lon; - const double c = (double)target.lat; - const double d = (double)target.lon; + const double x = static_cast(inputPoint.lat); + const double y = static_cast(inputPoint.lon); + const double a = static_cast(source.lat); + const double b = static_cast(source.lon); + const double c = static_cast(target.lat); + const double d = static_cast(target.lon); double p,q,mX,nY; - if(c != a){ + if(fabs(a-c) < FLT_EPSILON){ const double m = (d-b)/(c-a); // slope // Projection of (x,y) on line joining (a,b) and (c,d) p = ((x + (m*y)) + (m*m*a - m*b))/(1. + m*m);