#include <universal_manager.h>
Inherits Singleton< ParrentClass >.
Inheritance diagram for UniversalManager< T, ParrentClass >:


Public Types | |
| typedef RefCounterPtr< ManagedItem, T > | TRef |
| reference to managed type T | |
| typedef STL_EXT_NS::hash_map< std::string, ManagedItem * > | TContainer |
| containter of managed items | |
| typedef std::pair< std::string, ManagedItem * > | TPair |
| (key, data)-pair used for inserting into container of managed items | |
| typedef UniversalManager< T, ParrentClass > | TUniversalManager |
| self-type of this manager | |
Public Member Functions | |
| int | size (void) |
| returns the number of items in registry | |
| void | erase (void) |
| destroys all unreferenced registered elements and clears the registry | |
Protected Member Functions | |
| UniversalManager () | |
| protected ctor (singleton) | |
| ~UniversalManager () | |
| virtual ManagedItem * | create (std::string key, T *data) |
| callback for creating new managed item from its key | |
| virtual void | destroyContent (T *data) |
| callback for destroying the data that ManagedItem wraps | |
| virtual void | destroy (ManagedItem *item) |
| destroys given managed item | |
| ManagedItem * | find (std::string key) |
| searches for managed item that is registered with the given key and returns null if not found | |
| ManagedItem * | createAndRegister (std::string key, T *data) |
| creates and registers new item | |
Protected Attributes | |
| TContainer | mRegister |
| register of managed items | |
Private Member Functions | |
| void | OnZeroRefCount (ManagedItem *p) |
Classes | |
| class | ManagedItem |
| a class wrapping some managed-information for UniversalManager More... | |
usage:
class MyManager: public UniversalManager<MyData, MyManager> { // A. Singleton DP stuffs: protected: MyManager(){} ~MyManager(){} friend class Singleton<MyManager>; // B. User's add(...) methods public: TRef add(std::string key, int param1) { // I. FIND ManagedItem * p; if ((p = find(key)) != 0) return p; // II. INIT MyData * pc = new MyData(param1); // III. REGISTER return createAndRegister(key, pc); } // C. User's create(), destroy() and destroyContent() callback-methods overriding // ... }
Derive your own manager from UniversalManager. The first template argument of UniversalManager is the desired managed type, the second *MUST* be the class name of the top-level derived manager due to Singleton stuffs (this "throws polymorphysm out of window", but extensibility is what we need). Define protected (or private) ctor and dtor as well. This is due to Singleton DP and ensures that the creation and destruction of the manager will be handled by the Singleton-class. Define your own add() methods. There you can declare parameters that are needed for adding new items (i.e. the file-name string and the font size int if you'd like to manage fonts). Each add-method should implement three parts - FIND, INIT and REGISTER. FIND-part must test if the item you are trying to add is already registered or not and return the item, if it is already registered. This can be easily done with the find(key_string) method. If the item is not registered, continue to the INIT-part, where you create the item you want to register and initialize it from arguments of add-method. Last thing to do is the registration of the item. Use the createAndRegister() method. You can redefine create(), destroy() and destroyContent() callback methods if you need to. But, in common case, this shouldn't be needed.
Definition at line 68 of file universal_manager.h.
|
|||||
|
containter of managed items
Definition at line 180 of file universal_manager.h. |
|
|||||
|
(key, data)-pair used for inserting into container of managed items
Definition at line 181 of file universal_manager.h. |
|
|||||
|
reference to managed type T
Definition at line 179 of file universal_manager.h. |
|
|||||
|
self-type of this manager
Definition at line 182 of file universal_manager.h. |
|
|||||||||
|
protected ctor (singleton)
Definition at line 202 of file universal_manager.h. |
|
|||||||||
|
Definition at line 215 of file universal_manager.h. |
|
||||||||||||||||
|
callback for creating new managed item from its key This is used by manager when registering the item by createAndRegister()
Definition at line 225 of file universal_manager.h. Referenced by UniversalManager< T, ParrentClass >::createAndRegister(). |
|
||||||||||||||||
|
creates and registers new item
This assumes that the item isn't registered yet. This is supportive method for writing user's own
Definition at line 308 of file universal_manager.h. References UniversalManager< T, ParrentClass >::create(), and UniversalManager< T, ParrentClass >::mRegister. Here is the call graph for this function: ![]() |
|
||||||||||
|
destroys given managed item This is NOT the unregistering itself, but only the destruction routine of managed item and its data. Unregistering is done automatically by the OnZeroRefCount() callback. However, by overriding this method you are able to write your own destruction code.
Definition at line 247 of file universal_manager.h. Referenced by UniversalManager< T, ParrentClass >::erase(), and UniversalManager< T, ParrentClass >::OnZeroRefCount(). |
|
||||||||||
|
callback for destroying the data that ManagedItem wraps It is called by ManagedData::disableManaging() - data is filled by this instance
Definition at line 235 of file universal_manager.h. |
|
||||||||||
|
destroys all unreferenced registered elements and clears the registry However, if there exists some managed items with non-zero reference count, they are NOT deleted, but some warning message is logged for each item and this item becomes a zombie. Zombie means, that data wrapped by this item is destroyed by manager and manager removes this item from registry and gives up ownership (zombie owns itself). Reference counting is still active and when it counts zero, zombie deletes itself. This is used when the manager is being destroyed ( ~UniversalManager() ) or when there is the need of releasing registered items (for example, the graphical subsystem shutdown is the good moment for releasing textures - after that it wouldn't been possible).
Definition at line 328 of file universal_manager.h. References UniversalManager< T, ParrentClass >::destroy(), LOGW, UniversalManager< T, ParrentClass >::mRegister, and TIN. Referenced by UniversalManager< Texture, TextureManager >::~UniversalManager(). Here is the call graph for this function: ![]() |
|
||||||||||
|
searches for managed item that is registered with the given key and returns null if not found
This is a supportive method for writing user's own
Definition at line 317 of file universal_manager.h. References UniversalManager< T, ParrentClass >::mRegister. |
|
||||||||||
|
Definition at line 287 of file universal_manager.h. References assertL, UniversalManager< T, ParrentClass >::destroy(), UniversalManager< T, ParrentClass >::ManagedItem::getKey(), UniversalManager< T, ParrentClass >::mRegister, and TIN. Here is the call graph for this function: ![]() |
|
||||||||||
|
returns the number of items in registry
Definition at line 175 of file universal_manager.h. |
|
|||||
|
register of managed items
Definition at line 272 of file universal_manager.h. Referenced by UniversalManager< T, ParrentClass >::createAndRegister(), UniversalManager< T, ParrentClass >::erase(), UniversalManager< T, ParrentClass >::find(), UniversalManager< T, ParrentClass >::OnZeroRefCount(), and UniversalManager< Texture, TextureManager >::size(). |
1.4.5