Quellcode durchsuchen

Make element definitions const

Michael Ragazzon vor 3 Jahren
Ursprung
Commit
91f6bfc9d9

+ 5 - 5
Include/RmlUi/Core/StyleSheet.h

@@ -61,8 +61,8 @@ class RMLUICORE_API StyleSheet final : public NonCopyMoveable
 public:
 	~StyleSheet();
 
-	using NodeList = Vector< const StyleSheetNode* >;
-	using NodeIndex = UnorderedMap< size_t, NodeList >;
+	using NodeList = Vector<const StyleSheetNode*>;
+	using NodeIndex = UnorderedMap<size_t, NodeList>;
 
 	/// Combines this style sheet with another one, producing a new sheet.
 	UniquePtr<StyleSheet> CombineStyleSheet(const StyleSheet& sheet) const;
@@ -81,7 +81,7 @@ public:
 	const Sprite* GetSprite(const String& name) const;
 
 	/// Returns the compiled element definition for a given element and its hierarchy.
-	SharedPtr<ElementDefinition> GetElementDefinition(const Element* element) const;
+	SharedPtr<const ElementDefinition> GetElementDefinition(const Element* element) const;
 
 	/// Retrieve the hash key used to look-up applicable nodes in the node index.
 	static size_t NodeHash(const String& tag, const String& id);
@@ -115,11 +115,11 @@ private:
 	NodeIndex styled_node_index;
 
 	// Index of node sets to element definitions.
-	using ElementDefinitionCache = UnorderedMap< size_t, SharedPtr<ElementDefinition> >;
+	using ElementDefinitionCache = UnorderedMap<size_t, SharedPtr<const ElementDefinition>>;
 	mutable ElementDefinitionCache node_cache;
 
 	// Cached decorator instances.
-	using DecoratorCache = UnorderedMap< String, Vector<SharedPtr<const Decorator>> >;
+	using DecoratorCache = UnorderedMap<String, Vector<SharedPtr<const Decorator>>>;
 	mutable DecoratorCache decorator_cache;
 
 	friend Rml::StyleSheetParser;

+ 1 - 1
Source/Core/ElementStyle.cpp

@@ -177,7 +177,7 @@ void ElementStyle::UpdateDefinition()
 
 		definition_dirty = false;
 
-		SharedPtr<ElementDefinition> new_definition;
+		SharedPtr<const ElementDefinition> new_definition;
 		
 		if (const StyleSheet* style_sheet = element->GetStyleSheet())
 		{

+ 1 - 1
Source/Core/ElementStyle.h

@@ -165,7 +165,7 @@ private:
 	// Any properties that have been overridden in this element.
 	PropertyDictionary inline_properties;
 	// The definition of this element, provides applicable properties from the stylesheet.
-	SharedPtr<ElementDefinition> definition;
+	SharedPtr<const ElementDefinition> definition;
 	// Set if a new element definition should be fetched from the style.
 	bool definition_dirty;
 

+ 3 - 3
Source/Core/StyleSheet.cpp

@@ -181,7 +181,7 @@ size_t StyleSheet::NodeHash(const String& tag, const String& id)
 }
 
 // Returns the compiled element definition for a given element hierarchy.
-SharedPtr<ElementDefinition> StyleSheet::GetElementDefinition(const Element* element) const
+SharedPtr<const ElementDefinition> StyleSheet::GetElementDefinition(const Element* element) const
 {
 	RMLUI_ASSERT_NONRECURSIVE;
 
@@ -244,12 +244,12 @@ SharedPtr<ElementDefinition> StyleSheet::GetElementDefinition(const Element* ele
 	auto cache_iterator = node_cache.find(seed);
 	if (cache_iterator != node_cache.end())
 	{
-		SharedPtr<ElementDefinition>& definition = (*cache_iterator).second;
+		SharedPtr<const ElementDefinition>& definition = (*cache_iterator).second;
 		return definition;
 	}
 
 	// Create the new definition and add it to our cache.
-	auto new_definition = MakeShared<ElementDefinition>(applicable_nodes);
+	auto new_definition = MakeShared<const ElementDefinition>(applicable_nodes);
 	node_cache[seed] = new_definition;
 
 	return new_definition;