summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Nienhüser <nienhueser@kde.org>2016-11-05 12:16:51 (GMT)
committerFriedrich W. H. Kossebau <kossebau@kde.org>2016-11-05 16:49:34 (GMT)
commit3908eedf274fd9250c9fb142f7dfebd20662833d (patch)
tree99e04c06be98e078bb40cb347002491aeffe6c90
parent78b8313d55355066396b0688130a0bc0db7811f9 (diff)
Use smart pointers to fix memory leaks.
-rw-r--r--tools/vectorosm-tilecreator/WayChunk.cpp2
-rw-r--r--tools/vectorosm-tilecreator/WayChunk.h4
-rw-r--r--tools/vectorosm-tilecreator/WayConcatenator.cpp33
-rw-r--r--tools/vectorosm-tilecreator/WayConcatenator.h16
4 files changed, 25 insertions, 30 deletions
diff --git a/tools/vectorosm-tilecreator/WayChunk.cpp b/tools/vectorosm-tilecreator/WayChunk.cpp
index 524d068..a2af9cc 100644
--- a/tools/vectorosm-tilecreator/WayChunk.cpp
+++ b/tools/vectorosm-tilecreator/WayChunk.cpp
@@ -58,7 +58,7 @@ void WayChunk::prepend(const PlacemarkPtr &placemark, qint64 first)
}
-void WayChunk::append(WayChunk *chunk)
+void WayChunk::append(const WayChunk::Ptr &chunk)
{
m_wayList << chunk->m_wayList;
m_last = chunk->last();
diff --git a/tools/vectorosm-tilecreator/WayChunk.h b/tools/vectorosm-tilecreator/WayChunk.h
index e91a4dd..7388a16 100644
--- a/tools/vectorosm-tilecreator/WayChunk.h
+++ b/tools/vectorosm-tilecreator/WayChunk.h
@@ -26,10 +26,12 @@ private:
typedef QSharedPointer<GeoDataPlacemark> PlacemarkPtr;
public:
+ typedef QSharedPointer<WayChunk> Ptr;
+
WayChunk(const PlacemarkPtr &placemark, qint64 first, qint64 last );
~WayChunk();
void append(const PlacemarkPtr &placemark, qint64 last);
- void append(WayChunk *chunk);
+ void append(const Ptr &chunk);
void prepend(const PlacemarkPtr & placemark, qint64 first);
/*
diff --git a/tools/vectorosm-tilecreator/WayConcatenator.cpp b/tools/vectorosm-tilecreator/WayConcatenator.cpp
index 7a07d70..c268483 100644
--- a/tools/vectorosm-tilecreator/WayConcatenator.cpp
+++ b/tools/vectorosm-tilecreator/WayConcatenator.cpp
@@ -55,22 +55,22 @@ WayConcatenator::WayConcatenator(GeoDataDocument *document) :
if (!containsFirst && !containsLast) {
createWayChunk(placemark, firstId, lastId);
} else if (containsFirst && !containsLast) {
- WayChunk *chunk = wayChunk(placemark, firstId);
+ auto chunk = wayChunk(placemark, firstId);
if (chunk != nullptr) {
concatFirst(placemark, chunk);
} else {
createWayChunk(placemark, firstId, lastId);
}
} else if (!containsFirst && containsLast) {
- WayChunk *chunk = wayChunk(placemark, lastId);
+ auto chunk = wayChunk(placemark, lastId);
if (chunk != nullptr) {
concatLast(placemark, chunk);
} else {
createWayChunk(placemark, firstId, lastId);
}
} else if (containsFirst && containsLast) {
- WayChunk *chunk = wayChunk(placemark, firstId);
- WayChunk *otherChunk = wayChunk(placemark, lastId);
+ auto chunk = wayChunk(placemark, firstId);
+ auto otherChunk = wayChunk(placemark, lastId);
if (chunk != nullptr && otherChunk != nullptr) {
if(chunk == otherChunk) {
@@ -101,11 +101,6 @@ WayConcatenator::WayConcatenator(GeoDataDocument *document) :
addWayChunks();
}
-WayConcatenator::~WayConcatenator()
-{
- qDeleteAll(m_chunks);
-}
-
int WayConcatenator::originalWays() const
{
return m_originalWays;
@@ -122,8 +117,8 @@ void WayConcatenator::addWayChunks()
document()->append(new GeoDataPlacemark(*placemark));
}
- QSet<WayChunk*> chunkSet;
- QVector<WayChunk*>::iterator itr = m_chunks.begin();
+ QSet<WayChunk::Ptr> chunkSet;
+ auto itr = m_chunks.begin();
for (; itr != m_chunks.end(); ++itr) {
if (!chunkSet.contains(*itr)) {
++m_mergedWays;
@@ -148,7 +143,7 @@ void WayConcatenator::prepareDocument()
void WayConcatenator::createWayChunk(const PlacemarkPtr &placemark, qint64 firstId, qint64 lastId)
{
- WayChunk *chunk = new WayChunk(placemark, firstId, lastId);
+ WayChunk::Ptr chunk = WayChunk::Ptr(new WayChunk(placemark, firstId, lastId));
m_hash.insert(firstId, chunk);
if (firstId != lastId) {
m_hash.insert(lastId, chunk);
@@ -156,20 +151,20 @@ void WayConcatenator::createWayChunk(const PlacemarkPtr &placemark, qint64 first
m_chunks.append(chunk);
}
-WayChunk* WayConcatenator::wayChunk(const PlacemarkPtr &placemark, qint64 matchId) const
+WayChunk::Ptr WayConcatenator::wayChunk(const PlacemarkPtr &placemark, qint64 matchId) const
{
- QHash<qint64, WayChunk*>::ConstIterator matchItr = m_hash.find(matchId);
+ QHash<qint64, WayChunk::Ptr>::ConstIterator matchItr = m_hash.find(matchId);
while (matchItr != m_hash.end() && matchItr.key() == matchId) {
- WayChunk *chunk = matchItr.value();
+ auto chunk = matchItr.value();
if (chunk->concatPossible(placemark)) {
return chunk;
}
++matchItr;
}
- return nullptr;
+ return WayChunk::Ptr();
}
-void WayConcatenator::concatFirst(const PlacemarkPtr &placemark, WayChunk *chunk)
+void WayConcatenator::concatFirst(const PlacemarkPtr &placemark, const WayChunk::Ptr &chunk)
{
GeoDataLineString *line = static_cast<GeoDataLineString*>(placemark->geometry());
qint64 firstId = placemark->osmData().nodeReference(line->first()).id();
@@ -192,7 +187,7 @@ void WayConcatenator::concatFirst(const PlacemarkPtr &placemark, WayChunk *chunk
}
}
-void WayConcatenator::concatLast(const PlacemarkPtr &placemark, WayChunk *chunk)
+void WayConcatenator::concatLast(const PlacemarkPtr &placemark, const WayChunk::Ptr &chunk)
{
GeoDataLineString *line = static_cast<GeoDataLineString*>(placemark->geometry());
qint64 firstId = placemark->osmData().nodeReference(line->first()).id();
@@ -212,7 +207,7 @@ void WayConcatenator::concatLast(const PlacemarkPtr &placemark, WayChunk *chunk)
}
}
-void WayConcatenator::concatBoth(const PlacemarkPtr &placemark, WayChunk *chunk, WayChunk *otherChunk)
+void WayConcatenator::concatBoth(const PlacemarkPtr &placemark, const WayChunk::Ptr &chunk, const WayChunk::Ptr &otherChunk)
{
GeoDataLineString *line = static_cast<GeoDataLineString*>(placemark->geometry());
qint64 firstId = placemark->osmData().nodeReference(line->first()).id();
diff --git a/tools/vectorosm-tilecreator/WayConcatenator.h b/tools/vectorosm-tilecreator/WayConcatenator.h
index ae05048..1b1d8cb 100644
--- a/tools/vectorosm-tilecreator/WayConcatenator.h
+++ b/tools/vectorosm-tilecreator/WayConcatenator.h
@@ -13,11 +13,10 @@
#include "BaseFilter.h"
#include "TagsFilter.h"
+#include "WayChunk.h"
namespace Marble {
-class WayChunk;
-
class WayConcatenator: public BaseFilter
{
private:
@@ -25,22 +24,21 @@ private:
public:
WayConcatenator(GeoDataDocument *document);
- ~WayConcatenator();
int originalWays() const;
int mergedWays() const;
private:
void createWayChunk(const PlacemarkPtr &placemark, qint64 firstId, qint64 lastId);
- WayChunk* wayChunk(const PlacemarkPtr &placemark, qint64 matchId) const;
- void concatFirst(const PlacemarkPtr &placemark, WayChunk *chunk);
- void concatLast(const PlacemarkPtr & placemark, WayChunk *chunk);
- void concatBoth(const PlacemarkPtr &placemark, WayChunk *chunk, WayChunk *otherChunk);
+ WayChunk::Ptr wayChunk(const PlacemarkPtr &placemark, qint64 matchId) const;
+ void concatFirst(const PlacemarkPtr &placemark, const WayChunk::Ptr &chunk);
+ void concatLast(const PlacemarkPtr & placemark, const WayChunk::Ptr &chunk);
+ void concatBoth(const PlacemarkPtr &placemark, const WayChunk::Ptr &chunk, const WayChunk::Ptr &otherChunk);
void addWayChunks();
void prepareDocument();
- QMultiHash<qint64, WayChunk*> m_hash;
- QVector<WayChunk*> m_chunks;
+ QMultiHash<qint64, WayChunk::Ptr> m_hash;
+ QVector<WayChunk::Ptr> m_chunks;
QVector<PlacemarkPtr> m_wayPlacemarks;
QVector<GeoDataPlacemark*> m_otherPlacemarks;