28 #ifndef _CEGUINamedXMLResourceManager_h_
29 #define _CEGUINamedXMLResourceManager_h_
31 #include "CEGUIEventSet.h"
32 #include "CEGUIString.h"
33 #include "CEGUIExceptions.h"
34 #include "CEGUILogger.h"
35 #include "CEGUIInputEvent.h"
36 #include "CEGUISystem.h"
108 template<
typename T,
typename U>
185 T&
get(
const String& object_name)
const;
210 template<
typename T,
typename U>
212 const String& resource_type) :
213 d_resourceType(resource_type)
218 template<
typename T,
typename U>
224 template<
typename T,
typename U>
226 const String& resource_group,
229 U xml_loader(xml_filename, resource_group);
230 return doExistingObjectAction(xml_loader.getObjectName(),
231 &xml_loader.getObject(), action);
235 template<
typename T,
typename U>
238 typename ObjectRegistry::iterator i(d_objects.find(object_name));
241 if (i == d_objects.end())
248 template<
typename T,
typename U>
253 typename ObjectRegistry::iterator i(d_objects.begin());
254 for (; i != d_objects.end(); ++i)
255 if (i->second == &
object)
263 template<
typename T,
typename U>
266 while (!d_objects.empty())
267 destroyObject(d_objects.begin());
271 template<
typename T,
typename U>
274 typename ObjectRegistry::const_iterator i(d_objects.find(object_name));
276 if (i == d_objects.end())
278 "No object of type '" + d_resourceType +
"' named '" + object_name +
279 "' is present in the collection."));
285 template<
typename T,
typename U>
288 return d_objects.find(object_name) != d_objects.end();
292 template<
typename T,
typename U>
294 typename ObjectRegistry::iterator ob)
297 sprintf(addr_buff,
"(%p)", static_cast<void*>(ob->second));
298 Logger::getSingleton().logEvent(
"Object of type '" + d_resourceType +
299 "' named '" + ob->first +
"' has been destroyed. " +
309 fireEvent(EventResourceDestroyed, args, EventNamespace);
313 template<
typename T,
typename U>
321 if (isDefined(object_name))
326 Logger::getSingleton().logEvent(
"---- Returning existing instance "
327 "of " + d_resourceType +
" named '" + object_name +
"'.");
331 return *d_objects[object_name];
334 Logger::getSingleton().logEvent(
"---- Replacing existing instance "
335 "of " + d_resourceType +
" named '" + object_name +
337 destroy(object_name);
338 event_name = EventResourceReplaced;
344 "NamedXMLResourceManager::checkExistingObjectAction: "
345 "an object of type '" + d_resourceType +
"' named '" +
346 object_name +
"' already exists in the collection."));
351 "NamedXMLResourceManager::checkExistingObjectAction: "
352 "Invalid CEGUI::XMLResourceExistsAction was specified."));
356 event_name = EventResourceCreated;
358 d_objects[object_name] = object;
359 doPostObjectAdditionAction(*
object);
363 fireEvent(event_name, args, EventNamespace);
369 template<
typename T,
typename U>
376 template<
typename T,
typename U>
378 const String& resource_group)
380 std::vector<String> names;
382 getResourceGroupFileNames(names, pattern, resource_group);
384 for (
size_t i = 0; i < num; ++i)
385 create(names[i], resource_group);
392 #endif // end of guard _CEGUINamedXMLResourceManager_h_
Exception class used when a request was made for an unknown object.
Definition: CEGUIExceptions.h:189
EventArgs based class that is used for notifications regarding resources.
Definition: CEGUIInputEvent.h:357
static System & getSingleton(void)
Return singleton System object.
Exception class used when an attempt is made create a named object of a particular type when an objec...
Definition: CEGUIExceptions.h:406
void destroyAll()
Destroy all objects.
Definition: CEGUINamedXMLResourceManager.h:264
virtual void doPostObjectAdditionAction(T &object)
Function called each time a new object is added to the collection.
Definition: CEGUINamedXMLResourceManager.h:370
Useful tracing (object creations etc) information will be logged.
Definition: CEGUILogger.h:62
static const String EventNamespace
Namespace name for all resource managers.
Definition: CEGUINamedXMLResourceManager.h:60
T & get(const String &object_name) const
Return a reference to the object named object_name.
Definition: CEGUINamedXMLResourceManager.h:272
void createAll(const String &pattern, const String &resource_group)
Create a new T object from files with names matching pattern in resource_group.
Definition: CEGUINamedXMLResourceManager.h:377
T & doExistingObjectAction(const String object_name, T *object, const XMLResourceExistsAction action)
function to enforce XMLResourceExistsAction policy.
Definition: CEGUINamedXMLResourceManager.h:314
Destroy the existing instance and replace with the newly loaded one.
Definition: CEGUINamedXMLResourceManager.h:48
std::map< String, T *, String::FastLessCompare > ObjectRegistry
type of collection used to store and manage objects
Definition: CEGUINamedXMLResourceManager.h:195
static const String EventResourceReplaced
Definition: CEGUINamedXMLResourceManager.h:81
void destroyObject(typename ObjectRegistry::iterator ob)
implementation of object destruction.
Definition: CEGUINamedXMLResourceManager.h:293
T & create(const String &xml_filename, const String &resource_group="", XMLResourceExistsAction action=XREA_RETURN)
Creates a new T object from an XML file and adds it to the collection.
Definition: CEGUINamedXMLResourceManager.h:225
NamedXMLResourceManager(const String &resource_type)
Constructor.
Definition: CEGUINamedXMLResourceManager.h:211
static const String EventResourceCreated
Definition: CEGUINamedXMLResourceManager.h:67
void destroy(const String &object_name)
Destroy the object named object_name, or do nothing if such an object does not exist in the collectio...
Definition: CEGUINamedXMLResourceManager.h:236
Class that collects together a set of Event objects.
Definition: CEGUIEventSet.h:66
Templatised manager class that loads and manages named XML based resources.
Definition: CEGUINamedXMLResourceManager.h:109
static const String EventResourceDestroyed
Definition: CEGUINamedXMLResourceManager.h:74
Exception class used when some impossible request was made of the system.
Definition: CEGUIExceptions.h:242
XMLResourceExistsAction
Possible actions when loading an XML resource that already exists.
Definition: CEGUINamedXMLResourceManager.h:43
ResourceProvider * getResourceProvider(void) const
Return a pointer to the ResourceProvider being used within the GUI system.
Do not load the resource, return the existing instance.
Definition: CEGUINamedXMLResourceManager.h:46
implementation class to gather EventSet parts for all template instances.
Definition: CEGUINamedXMLResourceManager.h:56
virtual ~NamedXMLResourceManager()
Destructor.
Definition: CEGUINamedXMLResourceManager.h:219
bool isDefined(const String &object_name) const
Return whether an object named object_name exists.
Definition: CEGUINamedXMLResourceManager.h:286
const String d_resourceType
String holding the text for the resource type managed.
Definition: CEGUINamedXMLResourceManager.h:204
Throw an AlreadyExistsException.
Definition: CEGUINamedXMLResourceManager.h:50
String class used within the GUI system.
Definition: CEGUIString.h:57
ObjectRegistry d_objects
the collection of objects
Definition: CEGUINamedXMLResourceManager.h:206