Browse Source

Remove ElementReference

Michael Ragazzon 6 years ago
parent
commit
186eaefcd2

+ 0 - 2
Cmake/FileList.cmake

@@ -131,7 +131,6 @@ set(Core_PUB_HDR_FILES
     ${PROJECT_SOURCE_DIR}/Include/RmlUi/Core/ElementInstancer.h
     ${PROJECT_SOURCE_DIR}/Include/RmlUi/Core/ElementInstancerGeneric.h
     ${PROJECT_SOURCE_DIR}/Include/RmlUi/Core/ElementInstancerGeneric.inl
-    ${PROJECT_SOURCE_DIR}/Include/RmlUi/Core/ElementReference.h
     ${PROJECT_SOURCE_DIR}/Include/RmlUi/Core/ElementScroll.h
     ${PROJECT_SOURCE_DIR}/Include/RmlUi/Core/ElementText.h
     ${PROJECT_SOURCE_DIR}/Include/RmlUi/Core/ElementUtilities.h
@@ -242,7 +241,6 @@ set(Core_SRC_FILES
     ${PROJECT_SOURCE_DIR}/Source/Core/ElementHandle.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/ElementImage.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/ElementInstancer.cpp
-    ${PROJECT_SOURCE_DIR}/Source/Core/ElementReference.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/ElementScroll.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/ElementStyle.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/ElementText.cpp

+ 2 - 3
Include/RmlUi/Core/Context.h

@@ -32,7 +32,6 @@
 #include "Header.h"
 #include "Types.h"
 #include "ReferenceCountable.h"
-#include "ElementReference.h"
 #include "Input.h"
 #include "String.h"
 #include "ScriptInterface.h"
@@ -232,8 +231,8 @@ private:
 
 	SharedPtr<ContextInstancer> instancer;
 
-	typedef SmallOrderedSet< ElementReference > ElementSet;
-	typedef std::vector< ElementReference > ElementList;
+	using ElementSet = SmallOrderedSet< Element* > ;
+	using ElementList = std::vector< Element* >;
 	// Set of elements that are currently in hover state.
 	ElementSet hover_chain;
 	// List of elements that are currently in active state.

+ 0 - 1
Include/RmlUi/Core/Core.h

@@ -43,7 +43,6 @@
 #include "ElementDocument.h"
 #include "ElementInstancer.h"
 #include "ElementInstancerGeneric.h"
-#include "ElementReference.h"
 #include "ElementScroll.h"
 #include "ElementText.h"
 #include "ElementUtilities.h"

+ 0 - 104
Include/RmlUi/Core/ElementReference.h

@@ -1,104 +0,0 @@
-/*
- * This source file is part of RmlUi, the HTML/CSS Interface Middleware
- *
- * For the latest information, see http://github.com/mikke89/RmlUi
- *
- * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
- * Copyright (c) 2019 The RmlUi Team, and contributors
- *
- * 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 RMLUICOREELEMENTREFERENCE_H
-#define RMLUICOREELEMENTREFERENCE_H
-
-#include "Header.h"
-
-namespace Rml {
-namespace Core {
-
-class Element;
-
-/**
-	A smart pointer for elements.
-
-	@author Peter Curry
- */
-
- // TODO: Remove class
-
-class RMLUICORE_API ElementReference
-{
-public:
-	ElementReference(Element* element = NULL);
-	ElementReference(const ElementReference& copy);
-	~ElementReference();
-
-	/// Returns true if this reference is bound to an element.
-	/// @return True if this reference points to a non-NULL element, false otherwise.
-	operator bool() const;
-
-	/// Assigns a new element for this reference to point to.
-	/// @param element[in] The new element.
-	/// @return This element reference.
-	ElementReference& operator=(Element* element);
-	/// Assigns a new element for this reference, from another reference.
-	/// @param element_reference[in] The element reference to copy.
-	/// @return This element reference.
-	ElementReference& operator=(const ElementReference& element_reference);
-
-	/// Returns a reference to the underlying element.
-	/// @return The underlying element. This may be NULL.
-	Element* operator*();
-	/// Returns a reference to the underlying element.
-	/// @return The underlying element. This may be NULL.
-	Element* operator->();
-
-	/// Equality operator for the reference. Used for STL containers.
-	/// @param rhs[in] The other element to use in the comparison.
-	/// @return True if the elements are equivalent, false otherwise.
-	bool operator==(const ElementReference& rhs) const;
-	/// Equality operator for the reference.
-	/// @param rhs[in] The other element to use in the comparison.
-	/// @return True if the elements are equivalent, false otherwise.
-	bool operator==(const Element* rhs) const;
-
-	/// Less-than operator for the reference. Used for STL containers.
-	/// @param rhs[in] The other element to use in the comparison.
-	/// @return True if this element is less than the other element, false otherwise.
-	bool operator<(const ElementReference& rhs) const;
-
-	/// Inequality operator for the reference.
-	/// @param rhs[in] The other element to use in the comparison.
-	/// @return False if the elements are equivalent, true otherwise.
-	bool operator!=(const ElementReference& rhs) const;
-	/// Inequality operator for the reference.
-	/// @param rhs[in] A raw element to use in the comparison.
-	/// @return False if the elements are equivalent, true otherwise.
-	bool operator!=(const Element* rhs) const;
-
-private:
-	Element* element;
-};
-
-}
-}
-
-#endif

+ 1 - 5
Source/Core/Context.cpp

@@ -353,11 +353,7 @@ void Context::UnloadAllDocuments()
 	while (root->GetNumChildren(true) > 0)
 		UnloadDocument(root->GetChild(0)->GetOwnerDocument());
 
-	// Also need to clear containers that keep ElementReference pointers to elements belonging to removed documents,
-	// essentially preventing them from being released in correct order (before context destroys render interface,
-	// which causes access violation for elements that try to release geometry after context is released)
-	// I don't bother checking what's in chain because we unload all documents, so there shouldn't be any element
-	// that remains here (could check for element->owner == nullptr, but that's probably guaranteed)
+	// The element lists may point to elements that are getting removed.
 	active_chain.clear();
 	hover_chain.clear();
 	drag_hover_chain.clear();

+ 0 - 122
Source/Core/ElementReference.cpp

@@ -1,122 +0,0 @@
-/*
- * This source file is part of RmlUi, the HTML/CSS Interface Middleware
- *
- * For the latest information, see http://github.com/mikke89/RmlUi
- *
- * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
- * Copyright (c) 2019 The RmlUi Team, and contributors
- *
- * 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.
- *
- */
-
-#include "precompiled.h"
-#include "../../Include/RmlUi/Core/ElementReference.h"
-#include "../../Include/RmlUi/Core/Element.h"
-
-namespace Rml {
-namespace Core {
-
-ElementReference::ElementReference(Element* _element)
-{
-	element = NULL;
-	*this = _element;
-}
-
-ElementReference::ElementReference(const ElementReference& copy)
-{
-	element = NULL;
-	*this = copy;
-}
-
-ElementReference::~ElementReference()
-{
-	*this = NULL;
-}
-
-// Returns true if this reference is bound to an element.
-ElementReference::operator bool() const
-{
-	return (element != NULL);
-}
-
-// Assigns a new element for this reference to point to.
-ElementReference& ElementReference::operator=(Element* _element)
-{
-	/*if (_element != NULL)
-		_element->AddReference();
-
-	if (element != NULL)
-		element->RemoveReference();*/
-
-	element = _element;
-	return *this;
-}
-
-// Assigns a new element for this reference, from another reference.
-ElementReference& ElementReference::operator=(const ElementReference& element_reference)
-{
-	*this = (element_reference.element);
-	return *this;
-}
-
-// Returns a reference to the underlying element.
-Element* ElementReference::operator*()
-{
-	return element;
-}
-
-// Returns a reference to the underlying element.
-Element* ElementReference::operator->()
-{
-	return element;
-}
-
-// Equality operator for the reference. Used for STL containers.
-bool ElementReference::operator==(const ElementReference& rhs) const
-{
-	return element == rhs.element;
-}
-
-// Equality operator for the reference.
-bool ElementReference::operator==(const Element* rhs) const
-{
-	return element == rhs;
-}
-
-// Less-than operator for the reference. Used for STL containers.
-bool ElementReference::operator<(const ElementReference& rhs) const
-{
-	return element < rhs.element;
-}
-
-// Inequality operator for the reference.
-bool ElementReference::operator!=(const ElementReference& rhs) const
-{
-	return element != rhs.element;
-}
-
-// Inequality operator for the reference.
-bool ElementReference::operator!=(const Element* rhs) const
-{
-	return element != rhs;
-}
-
-}
-}

+ 2 - 3
Source/Core/EventIterators.h

@@ -29,7 +29,6 @@
 #ifndef RMLUICOREEVENTITERATORS_H
 #define RMLUICOREEVENTITERATORS_H
 
-#include "../../Include/RmlUi/Core/ElementReference.h"
 #include "../../Include/RmlUi/Core/Element.h"
 
 namespace Rml {
@@ -46,7 +45,7 @@ class RmlEventFunctor
 public:
 	RmlEventFunctor(EventId id, const Dictionary& parameters) : id(id), parameters(&parameters) {}
 
-	void operator()(ElementReference& element)
+	void operator()(Element* element)
 	{
 		element->DispatchEvent(id, *parameters);
 	}
@@ -70,7 +69,7 @@ class PseudoClassFunctor
 			this->set = set;
 		}
 
-		void operator()(ElementReference& element)
+		void operator()(Element* element)
 		{
 			element->SetPseudoClass(pseudo_class, set);
 		}