Browse Source

Replace custom shared reference with std::shared_ptr

Michael 7 years ago
parent
commit
26a22f0a6d

+ 0 - 96
Include/Rocket/Core/Reference.h

@@ -1,96 +0,0 @@
-/*
- * This source file is part of libRocket, the HTML/CSS Interface Middleware
- *
- * For the latest information, see http://www.librocket.com
- *
- * Copyright (c) 2014 Markus Schöngart
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-
-#ifndef ROCKETCOREREFERENCE_H
-#define ROCKETCOREREFERENCE_H
-
-#include "Header.h"
-#include <algorithm>
-
-namespace Rocket {
-namespace Core {
-
-template< class ReferenceCountable >
-class ROCKETCORE_API SharedReference;
-
-/**
-	A smart pointer class template that manages ReferenceCountables.
-	SharedReference allows unrestricted access to the shared object via every reference.
-	@author Markus Schöngart
-	@see ReferenceCountable
-*/
-template< class ReferenceCountable >
-class ROCKETCORE_API SharedReference
-{
-public:
-	typedef ReferenceCountable ReferenceType;
-	typedef SharedReference< ReferenceCountable > ThisType;
-
-	/// Constructor. Does not increase the object's reference count.
-	/// @param[in] object The object to refer to.
-	SharedReference(ReferenceType* object = 0) : object(object)
-		{ /*if (object) object->AddReference();*/ }
-	/// Copy constructor. Increases the object's reference count.
-	/// @param[in] other The other Reference.
-	SharedReference(const ThisType& other) : object(other.object)
-		{ if (object) object->AddReference(); }
-	/// Destructor. Decrements the stored object's reference count.
-	~SharedReference()
-		{ if (object) object->RemoveReference(); }
-
-	/// Swaps the contents of two References.
-	void Swap(ThisType& other) throw()
-		{ std::swap(object, other.object); }
-
-	/// Assign another referenced object to this smart pointer
-	const ThisType& operator=(ReferenceType* ref)
-		{ ThisType tmp(ref); Swap(tmp); return *this; }
-	/// Assign another referenced object to this smart pointer
-	const ThisType& operator=(const ThisType& other)
-		{ ThisType tmp(other); Swap(tmp); return *this; }
-
-	const ReferenceType& operator*() const throw()
-		{ return *object; }
-	ReferenceType& operator*() throw()
-		{ return *object; }
-
-	const ReferenceType* operator->() const throw()
-		{ return object; }
-	ReferenceType* operator->() throw()
-		{ return object; }
-
-	bool operator==(const ThisType& other) const { return object == other.object; }
-	bool operator!=(const ThisType& other) const { return object != other.object; }
-private:
-	mutable ReferenceType *object;
-};
-
-
-}
-}
-
-#endif

+ 1 - 17
Include/Rocket/Core/Transform.h

@@ -48,7 +48,7 @@ class Property;
 	@see Rocket::Core::Variant
  */
 
-class ROCKETCORE_API Transform : public ReferenceCountable
+class ROCKETCORE_API Transform
 {
 public:
 	typedef std::vector< Transforms::Primitive > Primitives;
@@ -61,18 +61,6 @@ public:
 
 	/// Helper function to create a Property with TransformRef from list of primitives
 	static Property MakeProperty(std::vector<Transforms::Primitive> primitives);
-	
-	/// Copy constructor
-	Transform(const Transform& other);
-
-	/// Destructor
-	~Transform();
-
-	/// Swap the content of two Transform instances
-	void Swap(Transform& other);
-
-	/// Assignment operator
-	const Transform& operator=(const Transform& other);
 
 	/// Remove all Primitives from this Transform
 	void ClearPrimitives();
@@ -89,10 +77,6 @@ public:
 	Primitives& GetPrimitives() noexcept { return primitives; }
 	const Primitives& GetPrimitives() const noexcept { return primitives; }
 
-protected:
-	void OnReferenceDeactivate()
-		{ delete this; }
-
 private:
 	Primitives primitives;
 };

+ 1 - 2
Include/Rocket/Core/Types.h

@@ -71,7 +71,6 @@ typedef unsigned __int64 uint64_t;
 #include "Vector4.h"
 #include "Matrix4.h"
 #include "String.h"
-#include "Reference.h"
 #include "Transform.h"
 
 namespace Rocket {
@@ -110,7 +109,7 @@ typedef Dictionary ElementAttributes;
 typedef std::vector< ElementAnimation > ElementAnimationList;
 
 // Reference types
-typedef SharedReference< Transform > TransformRef;
+typedef std::shared_ptr< Transform > TransformRef;
 
 struct Transition;
 struct TransitionList;

+ 1 - 1
Samples/basic/animation/data/animation.rml

@@ -98,7 +98,7 @@
 		} 
 		#transition_class {
 			margin-left: 50px;
-			transition: all 0.5s cubic-out;
+			transition: margin-left background-color 0.5s cubic-out;
 		}
 		#transition_class.move_me {
 			margin-left: -50px;

+ 2 - 2
Source/Core/ElementAnimation.cpp

@@ -117,7 +117,7 @@ static Property InterpolateProperties(const Property & p0, const Property& p1, f
 		using namespace Rocket::Core::Transforms;
 
 		// Build the new, interpolating transform
-		auto t = TransformRef{ new Transform };
+		auto t = std::make_unique<Transform>();
 
 		auto t0 = p0.value.Get<TransformRef>();
 		auto t1 = p1.value.Get<TransformRef>();
@@ -142,7 +142,7 @@ static Property InterpolateProperties(const Property & p0, const Property& p1, f
 			t->AddPrimitive(p);
 		}
 
-		return Property{ t, Property::TRANSFORM };
+		return Property{ TransformRef(std::move(t)), Property::TRANSFORM };
 	}
 
 	return alpha < 0.5f ? p0 : p1;

+ 3 - 3
Source/Core/PropertyParserTransform.cpp

@@ -46,7 +46,7 @@ PropertyParserTransform::~PropertyParserTransform()
 // Called to parse a RCSS transform declaration.
 bool PropertyParserTransform::ParseValue(Property& property, const String& value, const ParameterMap& parameters) const
 {
-	SharedReference< Transform > transform(new Transform);
+	auto transform = std::make_unique<Transform>();
 
 	char const* next = value.CString();
 
@@ -167,8 +167,8 @@ bool PropertyParserTransform::ParseValue(Property& property, const String& value
 			return false;
 		}
 	}
-
-	property.value = Variant(TransformRef(transform));
+	
+	property.value = Variant(TransformRef(std::move(transform)));
 	property.unit = Property::TRANSFORM;
 
 	return true;

+ 1 - 23
Source/Core/Transform.cpp

@@ -34,9 +34,9 @@
 namespace Rocket {
 namespace Core {
 
+
 // Default constructor, initializes an identity transform
 Transform::Transform()
-	: primitives()
 {
 }
 
@@ -52,28 +52,6 @@ Property Transform::MakeProperty(std::vector<Transforms::Primitive> primitives)
 	return p;
 }
 
-Transform::Transform(const Transform& other)
-{
-	primitives = other.primitives;
-}
-
-Transform::~Transform()
-{
-	primitives.clear();
-}
-
-void Transform::Swap(Transform& other)
-{
-	primitives.swap(other.primitives);
-}
-
-const Transform& Transform::operator=(const Transform& other)
-{
-	Transform result(other);
-	Swap(result);
-	return *this;
-}
-
 void Transform::ClearPrimitives() 
 {
 	primitives.clear();