10#ifndef __FLYWEIGHT_CLASSES_H__
11#define __FLYWEIGHT_CLASSES_H__
63 Flyweight_Context(
int offset_x,
int image_width,
int image_height,
double position_x,
double position_y,
double velocity_x,
double velocity_y)
174 void Render(std::vector<std::vector<char>>& display,
int offset_x,
int image_width,
int image_height,
int position_x,
int position_y);
232 void Render(std::vector<std::vector<char>>& display,
int offset_x,
int image_width,
int image_height,
int position_x,
int position_y);
316 static int AddResource(std::vector<std::string> rawResource);
Represents some big resource. In this case, a text "image" rendered as a list of strings....
BigResource(std::vector< std::string > resource, int resourceId)
Constructor (accessibly only to the class factory).
int ResourceId()
Retrieve the resource ID for this resource.
void Render(std::vector< std::vector< char > > &display, int offset_x, int image_width, int image_height, int position_x, int position_y)
Render the big resource into the given display at the given position.
Flyweight_Class::unique_ptr_t CreateFlyweight(Flyweight_Context context)
Generate a Flyweight class that will represent this big resource in some context-dependent way.
std::unique_ptr< BigResource > unique_ptr_t
std::vector< std::string > _resource
int ImageHeight()
Retrieve the "image" height of the resource.
int ImageWidth()
Retrieve the "image" width of the resource.
Represents a manager for big resources. Also provides the class factory for the Flyweight_Class insta...
static int _nextResourceId
The next ID to assign a raw resource for management.
std::vector< std::unique_ptr< BigResource > > BigResourceList
static int GetNextResourceId()
Retrieve the next resource ID that can be used.
static BigResourceList _resources
A list of all big resources managed by this class.
static BigResource * FindResource(int resourceId)
Retrieve the BigResource corresponding to the specified ID.
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,...
Associates a context with a big resource.
Flyweight_Class()
Default constructor.
void Render(std::vector< std::vector< char > > &display, int offset_x, int image_width, int image_height, int position_x, int position_y)
Render the image associated with this flyweight instance into the given display at the given position...
~Flyweight_Class()
Destructor.
Flyweight_Context _context
The context associated with this class. The calling entity uses this context to manipulate the flywei...
BigResource * _resource
The big resource being referenced by this flyweight class. In C#, a class is always a reference to an...
Flyweight_Context Context()
Retrieve the context for this class instance.
void SetContext(Flyweight_Context context)
Set the context for this class instance.
std::unique_ptr< Flyweight_Class > unique_ptr_t
int ImageHeight()
Retrieve the "image" height from underlying big resource.
int ImageWidth()
Retrieve the "image" width from underlying big resource.
The namespace containing all Design Pattern Examples implemented in C++.
std::vector< Flyweight_Class::unique_ptr_t > FlyweightClassList
Represents a big image. Call the BigResource_Clear() function to release the memory used by each inst...
Represents the context for an instance of the Flyweight_Class. In this case, the context includes pos...
Flyweight_Context()
Default constructor.
Flyweight_Context(int offset_x, int image_width, int image_height, double position_x, double position_y, double velocity_x, double velocity_y)
Constructor.