1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
<html xmlns="http://www.w3.org/1999/xhtml">
4
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5
<title>Crazy Eddies GUI System: CEGUINamedXMLResourceManager.h Source File</title>
6
<link href="tabs.css" rel="stylesheet" type="text/css"/>
7
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
10
<!-- Generated by Doxygen 1.7.2 -->
11
<script type="text/javascript">
12
function hasClass(ele,cls) {
13
return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
16
function addClass(ele,cls) {
17
if (!this.hasClass(ele,cls)) ele.className += " "+cls;
20
function removeClass(ele,cls) {
21
if (hasClass(ele,cls)) {
22
var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
23
ele.className=ele.className.replace(reg,' ');
27
function toggleVisibility(linkObj) {
28
var base = linkObj.getAttribute('id');
29
var summary = document.getElementById(base + '-summary');
30
var content = document.getElementById(base + '-content');
31
var trigger = document.getElementById(base + '-trigger');
32
if ( hasClass(linkObj,'closed') ) {
33
summary.style.display = 'none';
34
content.style.display = 'block';
35
trigger.src = 'open.png';
36
removeClass(linkObj,'closed');
37
addClass(linkObj,'opened');
38
} else if ( hasClass(linkObj,'opened') ) {
39
summary.style.display = 'block';
40
content.style.display = 'none';
41
trigger.src = 'closed.png';
42
removeClass(linkObj,'opened');
43
addClass(linkObj,'closed');
48
<div class="navigation" id="top">
51
<li><a href="index.html"><span>Main Page</span></a></li>
52
<li><a href="pages.html"><span>Related Pages</span></a></li>
53
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
54
<li><a href="annotated.html"><span>Classes</span></a></li>
55
<li class="current"><a href="files.html"><span>Files</span></a></li>
60
<li><a href="files.html"><span>File List</span></a></li>
64
<div class="headertitle">
65
<h1>CEGUINamedXMLResourceManager.h</h1> </div>
67
<div class="contents">
68
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/***********************************************************************</span>
69
<a name="l00002"></a>00002 <span class="comment"> filename: CEGUINamedXMLResourceManager.h</span>
70
<a name="l00003"></a>00003 <span class="comment"> created: Fri Jul 17 2009</span>
71
<a name="l00004"></a>00004 <span class="comment"> author: Paul D Turner <paul@cegui.org.uk></span>
72
<a name="l00005"></a>00005 <span class="comment">*************************************************************************/</span>
73
<a name="l00006"></a>00006 <span class="comment">/***************************************************************************</span>
74
<a name="l00007"></a>00007 <span class="comment"> * Copyright (C) 2004 - 2009 Paul D Turner & The CEGUI Development Team</span>
75
<a name="l00008"></a>00008 <span class="comment"> *</span>
76
<a name="l00009"></a>00009 <span class="comment"> * Permission is hereby granted, free of charge, to any person obtaining</span>
77
<a name="l00010"></a>00010 <span class="comment"> * a copy of this software and associated documentation files (the</span>
78
<a name="l00011"></a>00011 <span class="comment"> * "Software"), to deal in the Software without restriction, including</span>
79
<a name="l00012"></a>00012 <span class="comment"> * without limitation the rights to use, copy, modify, merge, publish,</span>
80
<a name="l00013"></a>00013 <span class="comment"> * distribute, sublicense, and/or sell copies of the Software, and to</span>
81
<a name="l00014"></a>00014 <span class="comment"> * permit persons to whom the Software is furnished to do so, subject to</span>
82
<a name="l00015"></a>00015 <span class="comment"> * the following conditions:</span>
83
<a name="l00016"></a>00016 <span class="comment"> *</span>
84
<a name="l00017"></a>00017 <span class="comment"> * The above copyright notice and this permission notice shall be</span>
85
<a name="l00018"></a>00018 <span class="comment"> * included in all copies or substantial portions of the Software.</span>
86
<a name="l00019"></a>00019 <span class="comment"> *</span>
87
<a name="l00020"></a>00020 <span class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,</span>
88
<a name="l00021"></a>00021 <span class="comment"> * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF</span>
89
<a name="l00022"></a>00022 <span class="comment"> * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.</span>
90
<a name="l00023"></a>00023 <span class="comment"> * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR</span>
91
<a name="l00024"></a>00024 <span class="comment"> * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,</span>
92
<a name="l00025"></a>00025 <span class="comment"> * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR</span>
93
<a name="l00026"></a>00026 <span class="comment"> * OTHER DEALINGS IN THE SOFTWARE.</span>
94
<a name="l00027"></a>00027 <span class="comment"> ***************************************************************************/</span>
95
<a name="l00028"></a>00028 <span class="preprocessor">#ifndef _CEGUINamedXMLResourceManager_h_</span>
96
<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define _CEGUINamedXMLResourceManager_h_</span>
97
<a name="l00030"></a>00030 <span class="preprocessor"></span>
98
<a name="l00031"></a>00031 <span class="preprocessor">#include "CEGUIEventSet.h"</span>
99
<a name="l00032"></a>00032 <span class="preprocessor">#include "CEGUIString.h"</span>
100
<a name="l00033"></a>00033 <span class="preprocessor">#include "CEGUIExceptions.h"</span>
101
<a name="l00034"></a>00034 <span class="preprocessor">#include "CEGUILogger.h"</span>
102
<a name="l00035"></a>00035 <span class="preprocessor">#include "CEGUIInputEvent.h"</span>
103
<a name="l00036"></a>00036 <span class="preprocessor">#include "CEGUISystem.h"</span>
104
<a name="l00037"></a>00037 <span class="preprocessor">#include <map></span>
105
<a name="l00038"></a>00038
106
<a name="l00039"></a>00039 <span class="comment">// Start of CEGUI namespace section</span>
107
<a name="l00040"></a>00040 <span class="keyword">namespace </span>CEGUI
108
<a name="l00041"></a>00041 {
109
<a name="l00043"></a><a class="code" href="namespaceCEGUI.html#a9944966045296e1d2533fe15ee865359">00043</a> <span class="keyword">enum</span> <a class="code" href="namespaceCEGUI.html#a9944966045296e1d2533fe15ee865359" title="Possible actions when loading an XML resource that already exists.">XMLResourceExistsAction</a>
110
<a name="l00044"></a>00044 {
111
<a name="l00046"></a><a class="code" href="namespaceCEGUI.html#a9944966045296e1d2533fe15ee865359a5a7a4f246d437106d7232792b62aafc0">00046</a> <a class="code" href="namespaceCEGUI.html#a9944966045296e1d2533fe15ee865359a5a7a4f246d437106d7232792b62aafc0" title="Do not load the resource, return the existing instance.">XREA_RETURN</a>,
112
<a name="l00048"></a><a class="code" href="namespaceCEGUI.html#a9944966045296e1d2533fe15ee865359a7831e48c1f8853f6d0258257cb596f71">00048</a> <a class="code" href="namespaceCEGUI.html#a9944966045296e1d2533fe15ee865359a7831e48c1f8853f6d0258257cb596f71" title="Destroy the existing instance and replace with the newly loaded one.">XREA_REPLACE</a>,
113
<a name="l00050"></a><a class="code" href="namespaceCEGUI.html#a9944966045296e1d2533fe15ee865359a27b0097397915ccf62de2355fa7b8000">00050</a> <a class="code" href="namespaceCEGUI.html#a9944966045296e1d2533fe15ee865359a27b0097397915ccf62de2355fa7b8000" title="Throw an AlreadyExistsException.">XREA_THROW</a>
114
<a name="l00051"></a>00051 };
115
<a name="l00052"></a>00052
116
<a name="l00053"></a>00053 <span class="comment">//----------------------------------------------------------------------------//</span>
117
<a name="l00054"></a>00054
118
<a name="l00056"></a><a class="code" href="classCEGUI_1_1ResourceEventSet.html">00056</a> <span class="keyword">class </span>CEGUIEXPORT <a class="code" href="classCEGUI_1_1ResourceEventSet.html" title="implementation class to gather EventSet parts for all template instances.">ResourceEventSet</a> : <span class="keyword">public</span> <a class="code" href="classCEGUI_1_1EventSet.html" title="Class that collects together a set of Event objects.">EventSet</a>
119
<a name="l00057"></a>00057 {
120
<a name="l00058"></a>00058 <span class="keyword">public</span>:
121
<a name="l00060"></a><a class="code" href="classCEGUI_1_1ResourceEventSet.html#a14459ea09df304c015a1356b86c50ca0">00060</a> <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a> <a class="code" href="classCEGUI_1_1ResourceEventSet.html#a14459ea09df304c015a1356b86c50ca0" title="Namespace name for all resource managers.">EventNamespace</a>;
122
<a name="l00067"></a><a class="code" href="classCEGUI_1_1ResourceEventSet.html#a3d228a7a40b5083ad02168fefbcbc8a0">00067</a> <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a> <a class="code" href="classCEGUI_1_1ResourceEventSet.html#a3d228a7a40b5083ad02168fefbcbc8a0">EventResourceCreated</a>;
123
<a name="l00074"></a><a class="code" href="classCEGUI_1_1ResourceEventSet.html#abba9c610930535739711c1c445122cf7">00074</a> <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a> <a class="code" href="classCEGUI_1_1ResourceEventSet.html#abba9c610930535739711c1c445122cf7">EventResourceDestroyed</a>;
124
<a name="l00081"></a><a class="code" href="classCEGUI_1_1ResourceEventSet.html#aa94e76312d3e4b5f64dfd7900e59f8c2">00081</a> <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a> <a class="code" href="classCEGUI_1_1ResourceEventSet.html#aa94e76312d3e4b5f64dfd7900e59f8c2">EventResourceReplaced</a>;
125
<a name="l00082"></a>00082 };
126
<a name="l00083"></a>00083
127
<a name="l00084"></a>00084 <span class="comment">//----------------------------------------------------------------------------//</span>
128
<a name="l00085"></a>00085
129
<a name="l00108"></a>00108 <span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span> U>
130
<a name="l00109"></a><a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html">00109</a> <span class="keyword">class </span><a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html" title="Templatised manager class that loads and manages named XML based resources.">NamedXMLResourceManager</a> : <span class="keyword">public</span> <a class="code" href="classCEGUI_1_1ResourceEventSet.html" title="implementation class to gather EventSet parts for all template instances.">ResourceEventSet</a>
131
<a name="l00110"></a>00110 {
132
<a name="l00111"></a>00111 <span class="keyword">public</span>:
133
<a name="l00121"></a>00121 <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a2ae558736f18e758f1c1b6f1c6d6b70e" title="Constructor.">NamedXMLResourceManager</a>(<span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a>& resource_type);
134
<a name="l00122"></a>00122
135
<a name="l00124"></a>00124 <span class="keyword">virtual</span> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#aa5a3293c828c5643d71b898a6c29afa0" title="Destructor.">~NamedXMLResourceManager</a>();
136
<a name="l00125"></a>00125
137
<a name="l00148"></a>00148 T& <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a13093b377ff84b3cfbd285aaa83ee166" title="Creates a new T object from an XML file and adds it to the collection.">create</a>(<span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a>& xml_filename, <span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a>& resource_group = <span class="stringliteral">""</span>,
138
<a name="l00149"></a>00149 <a class="code" href="namespaceCEGUI.html#a9944966045296e1d2533fe15ee865359" title="Possible actions when loading an XML resource that already exists.">XMLResourceExistsAction</a> action = <a class="code" href="namespaceCEGUI.html#a9944966045296e1d2533fe15ee865359a5a7a4f246d437106d7232792b62aafc0" title="Do not load the resource, return the existing instance.">XREA_RETURN</a>);
139
<a name="l00150"></a>00150
140
<a name="l00159"></a>00159 <span class="keywordtype">void</span> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a22df87b9b35eb05b773d198fdfc49ea1" title="Destroy the object named object_name, or do nothing if such an object does not exist in the collectio...">destroy</a>(<span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a>& object_name);
141
<a name="l00160"></a>00160
142
<a name="l00170"></a>00170 <span class="keywordtype">void</span> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a22df87b9b35eb05b773d198fdfc49ea1" title="Destroy the object named object_name, or do nothing if such an object does not exist in the collectio...">destroy</a>(<span class="keyword">const</span> T& <span class="keywordtype">object</span>);
143
<a name="l00171"></a>00171
144
<a name="l00173"></a>00173 <span class="keywordtype">void</span> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a99f9ff914c3e562a24b06417130f1f45" title="Destroy all objects.">destroyAll</a>();
145
<a name="l00174"></a>00174
146
<a name="l00185"></a>00185 T& <span class="keyword">get</span>(<span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a>& object_name) <span class="keyword">const</span>;
147
<a name="l00186"></a>00186
148
<a name="l00188"></a>00188 <span class="keywordtype">bool</span> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a05e36d9d715d209ab1fe6658c9202934" title="Return whether an object named object_name exists.">isDefined</a>(<span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a>& object_name) <span class="keyword">const</span>;
149
<a name="l00189"></a>00189
150
<a name="l00191"></a>00191 <span class="keywordtype">void</span> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a4dfa49b0b241426ee3f5dcb39663c301" title="Create a new T object from files with names matching pattern in resource_group.">createAll</a>(<span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a>& pattern, <span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a>& resource_group);
151
<a name="l00192"></a>00192
152
<a name="l00193"></a>00193 <span class="keyword">protected</span>:
153
<a name="l00195"></a><a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a785c2f0127133c3232d6da4673d93080">00195</a> <span class="keyword">typedef</span> std::map<String, T*, String::FastLessCompare> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a785c2f0127133c3232d6da4673d93080" title="type of collection used to store and manage objects">ObjectRegistry</a>;
154
<a name="l00197"></a>00197 <span class="keywordtype">void</span> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a15b34969f913a302e3e6067318563059" title="implementation of object destruction.">destroyObject</a>(<span class="keyword">typename</span> ObjectRegistry::iterator ob);
155
<a name="l00199"></a>00199 T& <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#aec9e54bb6b310d8062cc90b0dc7692b8" title="function to enforce XMLResourceExistsAction policy.">doExistingObjectAction</a>(<span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a> object_name, T* <span class="keywordtype">object</span>,
156
<a name="l00200"></a>00200 <span class="keyword">const</span> <a class="code" href="namespaceCEGUI.html#a9944966045296e1d2533fe15ee865359" title="Possible actions when loading an XML resource that already exists.">XMLResourceExistsAction</a> action);
157
<a name="l00202"></a>00202 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a02e49a7870cc78742253c1bb43a03cd7" title="Function called each time a new object is added to the collection.">doPostObjectAdditionAction</a>(T& <span class="keywordtype">object</span>);
158
<a name="l00204"></a><a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a42964e958b8b29c2a10b87e97e0b06b0">00204</a> <span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a42964e958b8b29c2a10b87e97e0b06b0" title="String holding the text for the resource type managed.">d_resourceType</a>;
159
<a name="l00206"></a><a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a61dfea8cd7ed559ac8cfc7354d835c09">00206</a> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a785c2f0127133c3232d6da4673d93080" title="type of collection used to store and manage objects">ObjectRegistry</a> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a61dfea8cd7ed559ac8cfc7354d835c09" title="the collection of objects">d_objects</a>;
160
<a name="l00207"></a>00207 };
161
<a name="l00208"></a>00208
162
<a name="l00209"></a>00209 <span class="comment">//----------------------------------------------------------------------------//</span>
163
<a name="l00210"></a>00210 <span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span> U>
164
<a name="l00211"></a><a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a2ae558736f18e758f1c1b6f1c6d6b70e">00211</a> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a2ae558736f18e758f1c1b6f1c6d6b70e" title="Constructor.">NamedXMLResourceManager<T, U>::NamedXMLResourceManager</a>(
165
<a name="l00212"></a>00212 <span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a>& resource_type) :
166
<a name="l00213"></a>00213 d_resourceType(resource_type)
167
<a name="l00214"></a>00214 {
168
<a name="l00215"></a>00215 }
169
<a name="l00216"></a>00216
170
<a name="l00217"></a>00217 <span class="comment">//----------------------------------------------------------------------------//</span>
171
<a name="l00218"></a>00218 <span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span> U>
172
<a name="l00219"></a><a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#aa5a3293c828c5643d71b898a6c29afa0">00219</a> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#aa5a3293c828c5643d71b898a6c29afa0" title="Destructor.">NamedXMLResourceManager<T, U>::~NamedXMLResourceManager</a>()
173
<a name="l00220"></a>00220 {
174
<a name="l00221"></a>00221 }
175
<a name="l00222"></a>00222
176
<a name="l00223"></a>00223 <span class="comment">//----------------------------------------------------------------------------//</span>
177
<a name="l00224"></a>00224 <span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span> U>
178
<a name="l00225"></a><a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a13093b377ff84b3cfbd285aaa83ee166">00225</a> T& <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a13093b377ff84b3cfbd285aaa83ee166" title="Creates a new T object from an XML file and adds it to the collection.">NamedXMLResourceManager<T, U>::create</a>(<span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a>& xml_filename,
179
<a name="l00226"></a>00226 <span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a>& resource_group,
180
<a name="l00227"></a>00227 <a class="code" href="namespaceCEGUI.html#a9944966045296e1d2533fe15ee865359" title="Possible actions when loading an XML resource that already exists.">XMLResourceExistsAction</a> action)
181
<a name="l00228"></a>00228 {
182
<a name="l00229"></a>00229 U xml_loader(xml_filename, resource_group);
183
<a name="l00230"></a>00230 <span class="keywordflow">return</span> doExistingObjectAction(xml_loader.getObjectName(),
184
<a name="l00231"></a>00231 &xml_loader.getObject(), action);
185
<a name="l00232"></a>00232 }
186
<a name="l00233"></a>00233
187
<a name="l00234"></a>00234 <span class="comment">//----------------------------------------------------------------------------//</span>
188
<a name="l00235"></a>00235 <span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span> U>
189
<a name="l00236"></a><a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a22df87b9b35eb05b773d198fdfc49ea1">00236</a> <span class="keywordtype">void</span> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a22df87b9b35eb05b773d198fdfc49ea1" title="Destroy the object named object_name, or do nothing if such an object does not exist in the collectio...">NamedXMLResourceManager<T, U>::destroy</a>(<span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a>& object_name)
190
<a name="l00237"></a>00237 {
191
<a name="l00238"></a>00238 <span class="keyword">typename</span> ObjectRegistry::iterator i(d_objects.find(object_name));
192
<a name="l00239"></a>00239
193
<a name="l00240"></a>00240 <span class="comment">// exit if no such object.</span>
194
<a name="l00241"></a>00241 <span class="keywordflow">if</span> (i == d_objects.end())
195
<a name="l00242"></a>00242 <span class="keywordflow">return</span>;
196
<a name="l00243"></a>00243
197
<a name="l00244"></a>00244 destroyObject(i);
198
<a name="l00245"></a>00245 }
199
<a name="l00246"></a>00246
200
<a name="l00247"></a>00247 <span class="comment">//----------------------------------------------------------------------------//</span>
201
<a name="l00248"></a>00248 <span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span> U>
202
<a name="l00249"></a><a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#aff2ebd2f107a1de1e0143540d508431d">00249</a> <span class="keywordtype">void</span> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a22df87b9b35eb05b773d198fdfc49ea1" title="Destroy the object named object_name, or do nothing if such an object does not exist in the collectio...">NamedXMLResourceManager<T, U>::destroy</a>(<span class="keyword">const</span> T& <span class="keywordtype">object</span>)
203
<a name="l00250"></a>00250 {
204
<a name="l00251"></a>00251 <span class="comment">// don't want to force a 'getName' function on T here, so we'll look for the</span>
205
<a name="l00252"></a>00252 <span class="comment">// object the hard way.</span>
206
<a name="l00253"></a>00253 <span class="keyword">typename</span> ObjectRegistry::iterator i(d_objects.begin());
207
<a name="l00254"></a>00254 <span class="keywordflow">for</span> (; i != d_objects.end(); ++i)
208
<a name="l00255"></a>00255 <span class="keywordflow">if</span> (i->second == &<span class="keywordtype">object</span>)
209
<a name="l00256"></a>00256 {
210
<a name="l00257"></a>00257 destroyObject(i);
211
<a name="l00258"></a>00258 <span class="keywordflow">return</span>;
212
<a name="l00259"></a>00259 }
213
<a name="l00260"></a>00260 }
214
<a name="l00261"></a>00261
215
<a name="l00262"></a>00262 <span class="comment">//----------------------------------------------------------------------------//</span>
216
<a name="l00263"></a>00263 <span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span> U>
217
<a name="l00264"></a><a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a99f9ff914c3e562a24b06417130f1f45">00264</a> <span class="keywordtype">void</span> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a99f9ff914c3e562a24b06417130f1f45" title="Destroy all objects.">NamedXMLResourceManager<T, U>::destroyAll</a>()
218
<a name="l00265"></a>00265 {
219
<a name="l00266"></a>00266 <span class="keywordflow">while</span> (!d_objects.empty())
220
<a name="l00267"></a>00267 destroyObject(d_objects.begin());
221
<a name="l00268"></a>00268 }
222
<a name="l00269"></a>00269
223
<a name="l00270"></a>00270 <span class="comment">//----------------------------------------------------------------------------//</span>
224
<a name="l00271"></a>00271 <span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span> U>
225
<a name="l00272"></a><a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a1e14c66d9ab6df184eedeaf3ffcf1655">00272</a> T& <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a1e14c66d9ab6df184eedeaf3ffcf1655" title="Return a reference to the object named object_name.">NamedXMLResourceManager<T, U>::get</a>(<span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a>& object_name)<span class="keyword"> const</span>
226
<a name="l00273"></a>00273 <span class="keyword"></span>{
227
<a name="l00274"></a>00274 <span class="keyword">typename</span> ObjectRegistry::const_iterator i(d_objects.find(object_name));
228
<a name="l00275"></a>00275
229
<a name="l00276"></a>00276 <span class="keywordflow">if</span> (i == d_objects.end())
230
<a name="l00277"></a>00277 CEGUI_THROW(<a class="code" href="classCEGUI_1_1UnknownObjectException.html" title="Exception class used when a request was made for an unknown object.">UnknownObjectException</a>(<span class="stringliteral">"NamedXMLResourceManager::get: "</span>
231
<a name="l00278"></a>00278 <span class="stringliteral">"No object of type '"</span> + d_resourceType + <span class="stringliteral">"' named '"</span> + object_name +
232
<a name="l00279"></a>00279 <span class="stringliteral">"' is present in the collection."</span>));
233
<a name="l00280"></a>00280
234
<a name="l00281"></a>00281 <span class="keywordflow">return</span> *i->second;
235
<a name="l00282"></a>00282 }
236
<a name="l00283"></a>00283
237
<a name="l00284"></a>00284 <span class="comment">//----------------------------------------------------------------------------//</span>
238
<a name="l00285"></a>00285 <span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span> U>
239
<a name="l00286"></a><a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a05e36d9d715d209ab1fe6658c9202934">00286</a> <span class="keywordtype">bool</span> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a05e36d9d715d209ab1fe6658c9202934" title="Return whether an object named object_name exists.">NamedXMLResourceManager<T, U>::isDefined</a>(<span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a>& object_name)<span class="keyword"> const</span>
240
<a name="l00287"></a>00287 <span class="keyword"></span>{
241
<a name="l00288"></a>00288 <span class="keywordflow">return</span> d_objects.find(object_name) != d_objects.end();
242
<a name="l00289"></a>00289 }
243
<a name="l00290"></a>00290
244
<a name="l00291"></a>00291 <span class="comment">//----------------------------------------------------------------------------//</span>
245
<a name="l00292"></a>00292 <span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span> U>
246
<a name="l00293"></a><a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a15b34969f913a302e3e6067318563059">00293</a> <span class="keywordtype">void</span> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a15b34969f913a302e3e6067318563059" title="implementation of object destruction.">NamedXMLResourceManager<T, U>::destroyObject</a>(
247
<a name="l00294"></a>00294 <span class="keyword">typename</span> ObjectRegistry::iterator ob)
248
<a name="l00295"></a>00295 {
249
<a name="l00296"></a>00296 <span class="keywordtype">char</span> addr_buff[32];
250
<a name="l00297"></a>00297 sprintf(addr_buff, <span class="stringliteral">"(%p)"</span>, static_cast<void*>(ob->second));
251
<a name="l00298"></a>00298 Logger::getSingleton().logEvent(<span class="stringliteral">"Object of type '"</span> + d_resourceType +
252
<a name="l00299"></a>00299 <span class="stringliteral">"' named '"</span> + ob->first + <span class="stringliteral">"' has been destroyed. "</span> +
253
<a name="l00300"></a>00300 addr_buff, <a class="code" href="namespaceCEGUI.html#a9e0443bad079b8ad1a6dd35f85595adda30a9a6fa07645407a29be1937cc3847b" title="Useful tracing (object creations etc) information will be logged.">Informative</a>);
254
<a name="l00301"></a>00301
255
<a name="l00302"></a>00302 <span class="comment">// Set up event args for event notification</span>
256
<a name="l00303"></a>00303 <a class="code" href="classCEGUI_1_1ResourceEventArgs.html" title="EventArgs based class that is used for notifications regarding resources.">ResourceEventArgs</a> args(d_resourceType, ob->first);
257
<a name="l00304"></a>00304
258
<a name="l00305"></a>00305 <span class="keyword">delete</span> ob->second;
259
<a name="l00306"></a>00306 d_objects.erase(ob);
260
<a name="l00307"></a>00307
261
<a name="l00308"></a>00308 <span class="comment">// fire event signalling an object has been destroyed</span>
262
<a name="l00309"></a>00309 fireEvent(EventResourceDestroyed, args, EventNamespace);
263
<a name="l00310"></a>00310 }
264
<a name="l00311"></a>00311
265
<a name="l00312"></a>00312 <span class="comment">//----------------------------------------------------------------------------//</span>
266
<a name="l00313"></a>00313 <span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span> U>
267
<a name="l00314"></a><a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#aec9e54bb6b310d8062cc90b0dc7692b8">00314</a> T& <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#aec9e54bb6b310d8062cc90b0dc7692b8" title="function to enforce XMLResourceExistsAction policy.">NamedXMLResourceManager<T, U>::doExistingObjectAction</a>(
268
<a name="l00315"></a>00315 <span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a> object_name,
269
<a name="l00316"></a>00316 T* <span class="keywordtype">object</span>,
270
<a name="l00317"></a>00317 <span class="keyword">const</span> <a class="code" href="namespaceCEGUI.html#a9944966045296e1d2533fe15ee865359" title="Possible actions when loading an XML resource that already exists.">XMLResourceExistsAction</a> action)
271
<a name="l00318"></a>00318 {
272
<a name="l00319"></a>00319 <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a> event_name;
273
<a name="l00320"></a>00320
274
<a name="l00321"></a>00321 <span class="keywordflow">if</span> (isDefined(object_name))
275
<a name="l00322"></a>00322 {
276
<a name="l00323"></a>00323 <span class="keywordflow">switch</span> (action)
277
<a name="l00324"></a>00324 {
278
<a name="l00325"></a>00325 <span class="keywordflow">case</span> <a class="code" href="namespaceCEGUI.html#a9944966045296e1d2533fe15ee865359a5a7a4f246d437106d7232792b62aafc0" title="Do not load the resource, return the existing instance.">XREA_RETURN</a>:
279
<a name="l00326"></a>00326 Logger::getSingleton().logEvent(<span class="stringliteral">"---- Returning existing instance "</span>
280
<a name="l00327"></a>00327 <span class="stringliteral">"of "</span> + d_resourceType + <span class="stringliteral">" named '"</span> + object_name + <span class="stringliteral">"'."</span>);
281
<a name="l00328"></a>00328 <span class="comment">// delete any new object we already had created</span>
282
<a name="l00329"></a>00329 <span class="keyword">delete</span> object;
283
<a name="l00330"></a>00330 <span class="comment">// return existing instance of object.</span>
284
<a name="l00331"></a>00331 <span class="keywordflow">return</span> *d_objects[object_name];
285
<a name="l00332"></a>00332
286
<a name="l00333"></a>00333 <span class="keywordflow">case</span> <a class="code" href="namespaceCEGUI.html#a9944966045296e1d2533fe15ee865359a7831e48c1f8853f6d0258257cb596f71" title="Destroy the existing instance and replace with the newly loaded one.">XREA_REPLACE</a>:
287
<a name="l00334"></a>00334 Logger::getSingleton().logEvent(<span class="stringliteral">"---- Replacing existing instance "</span>
288
<a name="l00335"></a>00335 <span class="stringliteral">"of "</span> + d_resourceType + <span class="stringliteral">" named '"</span> + object_name +
289
<a name="l00336"></a>00336 <span class="stringliteral">"' (DANGER!)."</span>);
290
<a name="l00337"></a>00337 destroy(object_name);
291
<a name="l00338"></a>00338 event_name = EventResourceReplaced;
292
<a name="l00339"></a>00339 <span class="keywordflow">break</span>;
293
<a name="l00340"></a>00340
294
<a name="l00341"></a>00341 <span class="keywordflow">case</span> <a class="code" href="namespaceCEGUI.html#a9944966045296e1d2533fe15ee865359a27b0097397915ccf62de2355fa7b8000" title="Throw an AlreadyExistsException.">XREA_THROW</a>:
295
<a name="l00342"></a>00342 <span class="keyword">delete</span> object;
296
<a name="l00343"></a>00343 CEGUI_THROW(<a class="code" href="classCEGUI_1_1AlreadyExistsException.html" title="Exception class used when an attempt is made create a named object of a particular type when an objec...">AlreadyExistsException</a>(
297
<a name="l00344"></a>00344 <span class="stringliteral">"NamedXMLResourceManager::checkExistingObjectAction: "</span>
298
<a name="l00345"></a>00345 <span class="stringliteral">"an object of type '"</span> + d_resourceType + <span class="stringliteral">"' named '"</span> +
299
<a name="l00346"></a>00346 object_name + <span class="stringliteral">"' already exists in the collection."</span>));
300
<a name="l00347"></a>00347
301
<a name="l00348"></a>00348 <span class="keywordflow">default</span>:
302
<a name="l00349"></a>00349 <span class="keyword">delete</span> object;
303
<a name="l00350"></a>00350 CEGUI_THROW(<a class="code" href="classCEGUI_1_1InvalidRequestException.html" title="Exception class used when some impossible request was made of the system.">InvalidRequestException</a>(
304
<a name="l00351"></a>00351 <span class="stringliteral">"NamedXMLResourceManager::checkExistingObjectAction: "</span>
305
<a name="l00352"></a>00352 <span class="stringliteral">"Invalid CEGUI::XMLResourceExistsAction was specified."</span>));
306
<a name="l00353"></a>00353 }
307
<a name="l00354"></a>00354 }
308
<a name="l00355"></a>00355 <span class="keywordflow">else</span>
309
<a name="l00356"></a>00356 event_name = EventResourceCreated;
310
<a name="l00357"></a>00357
311
<a name="l00358"></a>00358 d_objects[object_name] = object;
312
<a name="l00359"></a>00359 doPostObjectAdditionAction(*<span class="keywordtype">object</span>);
313
<a name="l00360"></a>00360
314
<a name="l00361"></a>00361 <span class="comment">// fire event about this resource change</span>
315
<a name="l00362"></a>00362 <a class="code" href="classCEGUI_1_1ResourceEventArgs.html" title="EventArgs based class that is used for notifications regarding resources.">ResourceEventArgs</a> args(d_resourceType, object_name);
316
<a name="l00363"></a>00363 fireEvent(event_name, args, EventNamespace);
317
<a name="l00364"></a>00364
318
<a name="l00365"></a>00365 <span class="keywordflow">return</span> *object;
319
<a name="l00366"></a>00366 }
320
<a name="l00367"></a>00367
321
<a name="l00368"></a>00368 <span class="comment">//----------------------------------------------------------------------------//</span>
322
<a name="l00369"></a>00369 <span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span> U>
323
<a name="l00370"></a><a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a02e49a7870cc78742253c1bb43a03cd7">00370</a> <span class="keywordtype">void</span> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a02e49a7870cc78742253c1bb43a03cd7" title="Function called each time a new object is added to the collection.">NamedXMLResourceManager<T, U>::doPostObjectAdditionAction</a>(T& <span class="comment">/*object*/</span>)
324
<a name="l00371"></a>00371 {
325
<a name="l00372"></a>00372 <span class="comment">// do nothing by default.</span>
326
<a name="l00373"></a>00373 }
327
<a name="l00374"></a>00374
328
<a name="l00375"></a>00375 <span class="comment">//----------------------------------------------------------------------------//</span>
329
<a name="l00376"></a>00376 <span class="keyword">template</span><<span class="keyword">typename</span> T, <span class="keyword">typename</span> U>
330
<a name="l00377"></a><a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a4dfa49b0b241426ee3f5dcb39663c301">00377</a> <span class="keywordtype">void</span> <a class="code" href="classCEGUI_1_1NamedXMLResourceManager.html#a4dfa49b0b241426ee3f5dcb39663c301" title="Create a new T object from files with names matching pattern in resource_group.">NamedXMLResourceManager<T, U>::createAll</a>(<span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a>& pattern,
331
<a name="l00378"></a>00378 <span class="keyword">const</span> <a class="code" href="classCEGUI_1_1String.html" title="String class used within the GUI system.">String</a>& resource_group)
332
<a name="l00379"></a>00379 {
333
<a name="l00380"></a>00380 std::vector<String> names;
334
<a name="l00381"></a>00381 <span class="keyword">const</span> <span class="keywordtype">size_t</span> num = <a class="code" href="classCEGUI_1_1System.html#a8d059b018d621be0e4b98d069421426f" title="Return singleton System object.">System::getSingleton</a>().<a class="code" href="classCEGUI_1_1System.html#a994b4c72aba1a456ba1a5fad469e93ed" title="Return a pointer to the ResourceProvider being used within the GUI system.">getResourceProvider</a>()->
335
<a name="l00382"></a>00382 getResourceGroupFileNames(names, pattern, resource_group);
336
<a name="l00383"></a>00383
337
<a name="l00384"></a>00384 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i < num; ++i)
338
<a name="l00385"></a>00385 create(names[i], resource_group);
339
<a name="l00386"></a>00386 }
340
<a name="l00387"></a>00387
341
<a name="l00388"></a>00388 <span class="comment">//----------------------------------------------------------------------------//</span>
342
<a name="l00389"></a>00389
343
<a name="l00390"></a>00390 } <span class="comment">// End of CEGUI namespace section</span>
344
<a name="l00391"></a>00391
345
<a name="l00392"></a>00392 <span class="preprocessor">#endif // end of guard _CEGUINamedXMLResourceManager_h_</span>
348
<hr class="footer"/><address class="footer"><small>Generated on Fri Nov 19 2010 12:01:19 for Crazy Eddies GUI System by 
349
<a href="http://www.doxygen.org/index.html">
350
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>