Represents a manager for big resources. Also provides the class factory for the Flyweight_Class instances that are associated with a particular big resource. More...
#include <Flyweight_Classes.h>
Static Public Member Functions | |
static int | AddResource (std::vector< std::string > rawResource) |
Add a new big resource and return the ID of the resource. | |
static Flyweight_Class::unique_ptr_t | CreateFlyweight (int bigResourceId, Flyweight_Context context) |
Create a new instance of the Flyweight_Class associated with the given big resource and a context, in this case an X,Y position. | |
Private Types | |
using | BigResourceList = std::vector< std::unique_ptr< BigResource > > |
Static Private Member Functions | |
static int | GetNextResourceId () |
Retrieve the next resource ID that can be used. | |
static BigResource * | FindResource (int resourceId) |
Retrieve the BigResource corresponding to the specified ID. | |
Static Private Attributes | |
static BigResourceList | _resources |
A list of all big resources managed by this class. | |
static int | _nextResourceId = 1 |
The next ID to assign a raw resource for management. | |
Represents a manager for big resources. Also provides the class factory for the Flyweight_Class instances that are associated with a particular big resource.
Note: The raw resource is provided by the caller and an ID is then associated with it. The ID is returned to the caller who then passes that ID to the Flyweight_Class factory along with a context.
In the exercise, only one big resource is ever created so this class is likely overkill for an example but it fully shows the architectural context in which a flyweight class is utilized.
Definition at line 281 of file Flyweight_Classes.h.
|
private |
Definition at line 284 of file Flyweight_Classes.h.
|
static |
Add a new big resource and return the ID of the resource.
rawResource | The resource to add. |
Definition at line 185 of file Flyweight_Classes.cpp.
References BigResourceManager::_resources, and BigResourceManager::GetNextResourceId().
|
static |
Create a new instance of the Flyweight_Class associated with the given big resource and a context, in this case an X,Y position.
bigResourceId | ID of the big resource to associate with. |
context | A Flyweight_Context instance containing the context for the desired Flyweight_Class instance. |
Definition at line 193 of file Flyweight_Classes.cpp.
References BigResource::CreateFlyweight(), and BigResourceManager::FindResource().
|
staticprivate |
Retrieve the BigResource corresponding to the specified ID.
resourceId | ID of the big resource to find. |
Definition at line 167 of file Flyweight_Classes.cpp.
References BigResourceManager::_resources.
Referenced by BigResourceManager::CreateFlyweight().
|
staticprivate |
Retrieve the next resource ID that can be used.
Definition at line 160 of file Flyweight_Classes.cpp.
References BigResourceManager::_nextResourceId.
Referenced by BigResourceManager::AddResource().
|
staticprivate |
The next ID to assign a raw resource for management.
Definition at line 294 of file Flyweight_Classes.h.
Referenced by BigResourceManager::GetNextResourceId().
|
staticprivate |
A list of all big resources managed by this class.
Definition at line 289 of file Flyweight_Classes.h.
Referenced by BigResourceManager::AddResource(), and BigResourceManager::FindResource().