diff options
| author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-17 15:27:09 +0100 | 
|---|---|---|
| committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-17 15:27:09 +0100 | 
| commit | 97b364112f0c9f3378011d6567433923f9fd8328 (patch) | |
| tree | 719c1282eefa45638d3b978435882558952204b6 | |
| parent | 8992dc8c4359964168da3e9221a31bfe9e4ffe8f (diff) | |
Managed container does not reset owner on move -- this allows the container to be reusable after a move. Adapted unit test accordingly.
| -rw-r--r-- | src/core/managed/ManagedContainer.hpp | 22 | ||||
| -rw-r--r-- | test/core/managed/ManagedContainerTest.cpp | 12 | 
2 files changed, 25 insertions, 9 deletions
| diff --git a/src/core/managed/ManagedContainer.hpp b/src/core/managed/ManagedContainer.hpp index 067a789..bdab38f 100644 --- a/src/core/managed/ManagedContainer.hpp +++ b/src/core/managed/ManagedContainer.hpp @@ -222,7 +222,7 @@ public:  	ManagedContainer(std::initializer_list<value_type> l) : owner(nullptr), c(l)  	{  		initialize(); -	}; +	}  	/**  	 * Constructor of the ManagedContainer class. @@ -322,7 +322,7 @@ public:  	ManagedContainer(own_type &&other)  	    : owner(other.owner), c(std::move(other.c))  	{ -		other.owner = nullptr; +		//other.owner = nullptr;  	}  	/** @@ -338,7 +338,7 @@ public:  	{  		initialize();  		other.finalize(c); -		other.owner = nullptr; +		//other.owner = nullptr;  	}  	/** @@ -356,7 +356,7 @@ public:  	{  		initialize();  		other.finalize(c); -		other.owner = nullptr; +		//other.owner = nullptr;  	}  	/** @@ -413,11 +413,23 @@ public:  		finalize();  		owner = other.owner;  		c = std::move(other.c); -		other.owner = nullptr; +		//other.owner = nullptr;  		return *this;  	}  	/** +	 * Copy assignment while keeping the owner. +	 * +	 * @param other is the collection instance that should be copied. +	 */ +	void assign(const own_type &other) +	{ +		finalize(); +		c = other.c; +		initialize(); +	} + +	/**  	 * Equality operator.  	 */  	bool operator==(const own_type &other) diff --git a/test/core/managed/ManagedContainerTest.cpp b/test/core/managed/ManagedContainerTest.cpp index 643ba2b..1ae14cb 100644 --- a/test/core/managed/ManagedContainerTest.cpp +++ b/test/core/managed/ManagedContainerTest.cpp @@ -106,7 +106,8 @@ TEST(ManagedVector, moveAssignment)  			}  			v1 = std::move(v2); -			ASSERT_EQ(nullptr, v2.getOwner()); +			ASSERT_EQ(root, v2.getOwner()); +			ASSERT_TRUE(v2.empty());  		}  		for (bool v : a) {  			ASSERT_TRUE(v); @@ -172,7 +173,8 @@ TEST(ManagedVector, copyWithNewOwner)  			ManagedVector<TestManaged> v3{root, v2};  			v1 = std::move(v3); -			ASSERT_EQ(nullptr, v3.getOwner()); +			ASSERT_EQ(root, v3.getOwner()); +			ASSERT_TRUE(v3.empty());  			ASSERT_TRUE(v1 != v2);  		}  		for (bool v : a) { @@ -207,8 +209,10 @@ TEST(ManagedVector, moveWithNewOwner)  			ManagedVector<TestManaged> v3{root, std::move(v2)};  			v1 = std::move(v3); -			ASSERT_EQ(nullptr, v2.getOwner()); -			ASSERT_EQ(nullptr, v3.getOwner()); +			ASSERT_EQ(root2, v2.getOwner()); +			ASSERT_TRUE(v2.empty()); +			ASSERT_EQ(root, v3.getOwner()); +			ASSERT_TRUE(v3.empty());  		}  		for (bool v : a) {  			ASSERT_TRUE(v); | 
