Browse Source

Merge pull request #104 from glockenmeier/dev

Added a method to Factory which allows the template cache to be cleared.
Tom Mason 11 years ago
parent
commit
504ae11b50

+ 2 - 0
Include/Rocket/Core/Factory.h

@@ -146,6 +146,8 @@ public:
 	static StyleSheet* InstanceStyleSheetStream(Stream* stream);
 	/// Clears the style sheet cache. This will force style sheets to be reloaded.
 	static void ClearStyleSheetCache();
+	/// Clears the template cache. This will force template to be reloaded.
+	static void ClearTemplateCache();
 
 	/// Registers an instancer for all events.
 	/// @param[in] instancer The instancer to be called.

+ 7 - 0
Source/Core/Factory.cpp

@@ -45,6 +45,7 @@
 #include "PropertyParserColour.h"
 #include "StreamFile.h"
 #include "StyleSheetFactory.h"
+#include "TemplateCache.h"
 #include "XMLNodeHandlerBody.h"
 #include "XMLNodeHandlerDefault.h"
 #include "XMLNodeHandlerHead.h"
@@ -530,6 +531,12 @@ void Factory::ClearStyleSheetCache()
 	StyleSheetFactory::ClearStyleSheetCache();
 }
 
+/// Clears the template cache. This will force templates to be reloaded.
+void Factory::ClearTemplateCache()
+{
+	TemplateCache::Clear();
+}
+
 // Registers an instancer for all RKTEvents
 EventInstancer* Factory::RegisterEventInstancer(EventInstancer* instancer)
 {

+ 9 - 0
Source/Core/TemplateCache.cpp

@@ -114,5 +114,14 @@ Template* TemplateCache::GetTemplate(const String& name)
 	return NULL;
 }
 
+void TemplateCache::Clear()
+{
+	for (Templates::iterator i = instance->templates.begin(); i != instance->templates.end(); ++i)
+		delete (*i).second;
+
+	instance->templates.clear();
+	instance->template_ids.clear();
+}
+
 }
 }

+ 3 - 0
Source/Core/TemplateCache.h

@@ -53,6 +53,9 @@ public:
 	/// Get the template by id
 	static Template* GetTemplate(const String& id);
 
+	/// Clear the template cache.
+	static void Clear();
+
 private:
 	TemplateCache();
 	~TemplateCache();