diff options
author | Tobias Markmann <tm@ayena.de> | 2018-07-31 15:42:11 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2018-07-31 15:42:11 (GMT) |
commit | 0007bbfa11e74f2a76aebc83995843ee8f6840ab (patch) | |
tree | 809fdb606a6bf37acfd800742dd0aeee72d2dbbf /Swiften/StreamStack | |
parent | 9d88d2c7130ebccdec12abf6420843d0f5e08e8e (diff) | |
download | swift-0007bbfa11e74f2a76aebc83995843ee8f6840ab.zip swift-0007bbfa11e74f2a76aebc83995843ee8f6840ab.tar.bz2 |
Have StreamStack own intermediate layers via std::unique_ptr
Test-Information:
`./scons test=all` passes with no errors on macOS with clang
7 master.
Change-Id: I31765ac15750dc5af7b70d1a85171dc8e3590181
Diffstat (limited to 'Swiften/StreamStack')
-rw-r--r-- | Swiften/StreamStack/StreamStack.cpp | 16 | ||||
-rw-r--r-- | Swiften/StreamStack/StreamStack.h | 12 | ||||
-rw-r--r-- | Swiften/StreamStack/UnitTest/StreamStackTest.cpp | 30 |
3 files changed, 29 insertions, 29 deletions
diff --git a/Swiften/StreamStack/StreamStack.cpp b/Swiften/StreamStack/StreamStack.cpp index 44a018d..f14f95c 100644 --- a/Swiften/StreamStack/StreamStack.cpp +++ b/Swiften/StreamStack/StreamStack.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2016 Isode Limited. + * Copyright (c) 2010-2018 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -22,16 +22,16 @@ StreamStack::StreamStack(XMPPLayer* xmppLayer, LowLayer* physicalLayer) : xmppLa StreamStack::~StreamStack() { } -void StreamStack::addLayer(StreamLayer* newLayer) { - LowLayer* lowLayer = layers_.empty() ? physicalLayer_ : *layers_.rbegin(); +void StreamStack::addLayer(std::unique_ptr<StreamLayer> streamLayer) { + LowLayer* lowLayer = layers_.empty() ? physicalLayer_ : layers_.rbegin()->get(); - xmppLayer_->setChildLayer(newLayer); - newLayer->setParentLayer(xmppLayer_); + xmppLayer_->setChildLayer(streamLayer.get()); + streamLayer->setParentLayer(xmppLayer_); - lowLayer->setParentLayer(newLayer); - newLayer->setChildLayer(lowLayer); + lowLayer->setParentLayer(streamLayer.get()); + streamLayer->setChildLayer(lowLayer); - layers_.push_back(newLayer); + layers_.emplace_back(std::move(streamLayer)); } } diff --git a/Swiften/StreamStack/StreamStack.h b/Swiften/StreamStack/StreamStack.h index b12a69f..5b77085 100644 --- a/Swiften/StreamStack/StreamStack.h +++ b/Swiften/StreamStack/StreamStack.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2016 Isode Limited. + * Copyright (c) 2010-2018 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -24,15 +24,15 @@ namespace Swift { StreamStack(XMPPLayer* xmppLayer, LowLayer* physicalLayer); ~StreamStack(); - void addLayer(StreamLayer*); + void addLayer(std::unique_ptr<StreamLayer> /* streamLayer */); XMPPLayer* getXMPPLayer() const { return xmppLayer_; } - template<typename T> T* getLayer() { - for (auto& i : layers_) { - T* layer = dynamic_cast<T*>(i); + template<typename T> T* getLayer() const { + for (const auto& i : layers_) { + T* layer = dynamic_cast<T*>(i.get()); if (layer) { return layer; } @@ -43,6 +43,6 @@ namespace Swift { private: XMPPLayer* xmppLayer_; LowLayer* physicalLayer_; - std::vector<StreamLayer*> layers_; + std::vector<std::unique_ptr<StreamLayer>> layers_; }; } diff --git a/Swiften/StreamStack/UnitTest/StreamStackTest.cpp b/Swiften/StreamStack/UnitTest/StreamStackTest.cpp index f0f82c9..0b520f1 100644 --- a/Swiften/StreamStack/UnitTest/StreamStackTest.cpp +++ b/Swiften/StreamStack/UnitTest/StreamStackTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2016 Isode Limited. + * Copyright (c) 2010-2018 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -61,8 +61,8 @@ class StreamStackTest : public CppUnit::TestFixture { void testWriteData_OneIntermediateStream() { StreamStack testling(xmppStream_, physicalStream_); - std::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("X")); - testling.addLayer(xStream.get()); + std::unique_ptr<MyStreamLayer> xStream(new MyStreamLayer("X")); + testling.addLayer(std::move(xStream)); xmppStream_->writeData("foo"); @@ -72,10 +72,10 @@ class StreamStackTest : public CppUnit::TestFixture { void testWriteData_TwoIntermediateStreamStack() { StreamStack testling(xmppStream_, physicalStream_); - std::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("X")); - std::shared_ptr<MyStreamLayer> yStream(new MyStreamLayer("Y")); - testling.addLayer(xStream.get()); - testling.addLayer(yStream.get()); + std::unique_ptr<MyStreamLayer> xStream(new MyStreamLayer("X")); + std::unique_ptr<MyStreamLayer> yStream(new MyStreamLayer("Y")); + testling.addLayer(std::move(xStream)); + testling.addLayer(std::move(yStream)); xmppStream_->writeData("foo"); @@ -95,8 +95,8 @@ class StreamStackTest : public CppUnit::TestFixture { void testReadData_OneIntermediateStream() { StreamStack testling(xmppStream_, physicalStream_); xmppStream_->onElement.connect(boost::bind(&StreamStackTest::handleElement, this, _1)); - std::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("<")); - testling.addLayer(xStream.get()); + std::unique_ptr<MyStreamLayer> xStream(new MyStreamLayer("<")); + testling.addLayer(std::move(xStream)); physicalStream_->onDataRead(createSafeByteArray("stream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>")); @@ -106,10 +106,10 @@ class StreamStackTest : public CppUnit::TestFixture { void testReadData_TwoIntermediateStreamStack() { StreamStack testling(xmppStream_, physicalStream_); xmppStream_->onElement.connect(boost::bind(&StreamStackTest::handleElement, this, _1)); - std::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("s")); - std::shared_ptr<MyStreamLayer> yStream(new MyStreamLayer("<")); - testling.addLayer(xStream.get()); - testling.addLayer(yStream.get()); + std::unique_ptr<MyStreamLayer> xStream(new MyStreamLayer("s")); + std::unique_ptr<MyStreamLayer> yStream(new MyStreamLayer("<")); + testling.addLayer(std::move(xStream)); + testling.addLayer(std::move(yStream)); physicalStream_->onDataRead(createSafeByteArray("tream:stream xmlns:stream='http://etherx.jabber.org/streams'><presence/>")); @@ -119,8 +119,8 @@ class StreamStackTest : public CppUnit::TestFixture { void testAddLayer_ExistingOnWriteDataSlot() { StreamStack testling(xmppStream_, physicalStream_); xmppStream_->onWriteData.connect(boost::bind(&StreamStackTest::handleWriteData, this, _1)); - std::shared_ptr<MyStreamLayer> xStream(new MyStreamLayer("X")); - testling.addLayer(xStream.get()); + std::unique_ptr<MyStreamLayer> xStream(new MyStreamLayer("X")); + testling.addLayer(std::move(xStream)); xmppStream_->writeData("foo"); |