summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Nienhüser <nienhueser@kde.org>2016-09-24 13:55:06 (GMT)
committerDennis Nienhüser <nienhueser@kde.org>2016-09-24 13:57:54 (GMT)
commitb1ee2d8cd9a09640a54b10c95fbcec8863bb860f (patch)
tree115f01dee4114712e1ec468dece2ffe9ef600662
parent453200a86fd04d085f2640b67b1f177038844af7 (diff)
Simplify memory management
-rw-r--r--tools/vectorosm-tilecreator/NodeReducer.cpp23
-rw-r--r--tools/vectorosm-tilecreator/NodeReducer.h7
2 files changed, 16 insertions, 14 deletions
diff --git a/tools/vectorosm-tilecreator/NodeReducer.cpp b/tools/vectorosm-tilecreator/NodeReducer.cpp
index c325c97..62bf91c 100644
--- a/tools/vectorosm-tilecreator/NodeReducer.cpp
+++ b/tools/vectorosm-tilecreator/NodeReducer.cpp
@@ -16,6 +16,7 @@
#include "GeoDataCoordinates.h"
#include "MarbleMath.h"
#include "NodeReducer.h"
+#include "OsmPlacemarkData.h"
#include <QDebug>
#include <QVector>
@@ -32,29 +33,31 @@ NodeReducer::NodeReducer(GeoDataDocument* document, int zoomLevel) :
if(placemark->geometry()->nodeType() == GeoDataTypes::GeoDataLineStringType) {
GeoDataLineString* prevLine = static_cast<GeoDataLineString*>(placemark->geometry());
- GeoDataLineString* reducedLine = reduce(prevLine);
+ GeoDataLineString* reducedLine = new GeoDataLineString;
+ reduce(prevLine, reducedLine);
placemark->setGeometry(reducedLine);
}
else if(placemark->geometry()->nodeType() == GeoDataTypes::GeoDataLinearRingType) {
GeoDataLinearRing* prevRing = static_cast<GeoDataLinearRing*>(placemark->geometry());
- GeoDataLinearRing* reducedRing = reduce(prevRing);
+ GeoDataLinearRing* reducedRing = new GeoDataLinearRing;
+ reduce(prevRing, reducedRing);
placemark->setGeometry(reducedRing);
}
else if(placemark->geometry()->nodeType() == GeoDataTypes::GeoDataPolygonType) {
GeoDataPolygon* reducedPolygon = new GeoDataPolygon;
GeoDataPolygon* prevPolygon = static_cast<GeoDataPolygon*>(placemark->geometry());
- GeoDataLinearRing* prevRing = &(prevPolygon->outerBoundary());
- GeoDataLinearRing* reducedRing = reduce(prevRing);
- reducedPolygon->setOuterBoundary(*reducedRing);
- delete reducedRing;
- QVector<GeoDataLinearRing>& innerBoundaries = prevPolygon->innerBoundaries();
+ GeoDataLinearRing const * prevRing = &(prevPolygon->outerBoundary());
+ GeoDataLinearRing reducedRing;
+ reduce(prevRing, &reducedRing);
+ reducedPolygon->setOuterBoundary(reducedRing);
+ QVector<GeoDataLinearRing> const & innerBoundaries = prevPolygon->innerBoundaries();
for(int i = 0; i < innerBoundaries.size(); i++) {
prevRing = &innerBoundaries[i];
- GeoDataLinearRing* reducedInnerRing = reduce(prevRing);
- reducedPolygon->appendInnerBoundary(*reducedInnerRing);
- delete reducedInnerRing;
+ GeoDataLinearRing reducedInnerRing;
+ reduce(prevRing, &reducedInnerRing);
+ reducedPolygon->appendInnerBoundary(reducedInnerRing);
}
placemark->setGeometry(reducedPolygon);
}
diff --git a/tools/vectorosm-tilecreator/NodeReducer.h b/tools/vectorosm-tilecreator/NodeReducer.h
index c1a64b8..8689585 100644
--- a/tools/vectorosm-tilecreator/NodeReducer.h
+++ b/tools/vectorosm-tilecreator/NodeReducer.h
@@ -25,14 +25,14 @@ public:
private:
template<class T>
- T* reduce(T* lineString)
+ void reduce(T const * lineString, T* reducedLine)
{
qint64 const prevSize = lineString->size();
if (prevSize < 2) {
- return new T(*lineString);
+ m_remainingNodes += prevSize;
+ return;
}
- T* reducedLine = new T;
auto iter = lineString->begin();
GeoDataCoordinates currentCoords = *iter;
reducedLine->append(*iter);
@@ -48,7 +48,6 @@ private:
qint64 reducedSize = reducedLine->size();
m_removedNodes += (prevSize - reducedSize);
m_remainingNodes += reducedSize;
- return reducedLine;
//qDebug()<<"Nodes reduced "<<(prevSize - reducedSize)<<endl;
}