Maelstrom: Allow loading multiple UI template files

https://github.com/libsdl-org/Maelstrom/commit/6b13573d32f69a3de625d29015ddbb89237ebe0a

From 6b13573d32f69a3de625d29015ddbb89237ebe0a Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 11 Nov 2012 01:32:41 -0800
Subject: [PATCH] Allow loading multiple UI template files

---
 screenlib/UITemplates.cpp | 18 ++++++++----------
 screenlib/UITemplates.h   |  3 ++-
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/screenlib/UITemplates.cpp b/screenlib/UITemplates.cpp
index 9c3c0aab..7cadf3dc 100644
--- a/screenlib/UITemplates.cpp
+++ b/screenlib/UITemplates.cpp
@@ -29,7 +29,6 @@
 
 UITemplates::UITemplates()
 {
-	m_data = NULL;
 	m_hashTable = NULL;
 }
 
@@ -38,34 +37,33 @@ UITemplates::~UITemplates()
 	if (m_hashTable) {
 		hash_destroy(m_hashTable);
 	}
-	if (m_data) {
-		SDL_free(m_data);
+	for (int i = 0; i < m_data.length(); ++i) {
+		SDL_free(m_data[i]);
 	}
 }
 
 bool
 UITemplates::Load(const char *file)
 {
+	char *data;
 	rapidxml::xml_node<> *node;
 	rapidxml::xml_attribute<> *attr;
 
-	if (m_data) {
-		SDL_free(m_data);
-	}
-	m_data = LoadFile(file);
-	if (!m_data) {
+	data = LoadFile(file);
+	if (!data) {
 		return false;
 	}
+	m_data.add(data);
 
 #ifdef RAPIDXML_NO_EXCEPTIONS
 	gLoadXMLError = NULL;
-	m_doc.parse<0>(m_data);
+	m_doc.parse<0>(data);
 	if (gLoadXMLError) {
 		return false;
 	}
 #else
 	try {
-		m_doc.parse<0>(m_data);
+		m_doc.parse<0>(data);
 	} catch (rapidxml::parse_error e) {
 		return false;
 	}
diff --git a/screenlib/UITemplates.h b/screenlib/UITemplates.h
index bb6c46e0..fd3ff94d 100644
--- a/screenlib/UITemplates.h
+++ b/screenlib/UITemplates.h
@@ -22,6 +22,7 @@
 #ifndef _UITemplates_h
 #define _UITemplates_h
 
+#include "../utils/array.h"
 #include "../utils/hashtable.h"
 #include "../utils/rapidxml.h"
 
@@ -37,7 +38,7 @@ class UITemplates
 	rapidxml::xml_node<> *GetTemplate(const char *type, const char *name) const;
 
 protected:
-	char *m_data;
+	array<char*> m_data;
 	rapidxml::xml_document<> m_doc;
 	struct HashKey {
 		const char *type;