Associates a context with a big resource. More...
#include <Flyweight_Classes.h>
Public Types | |
using | unique_ptr_t = std::unique_ptr< Flyweight_Class > |
Public Member Functions | |
Flyweight_Class () | |
Default constructor. | |
Flyweight_Class (BigResource *resource, Flyweight_Context context) | |
Constructor (accessible only to the class factory). | |
~Flyweight_Class () | |
Destructor. | |
Flyweight_Context | Context () |
Retrieve the context for this class instance. | |
void | SetContext (Flyweight_Context context) |
Set the context for this class instance. | |
int | ImageWidth () |
Retrieve the "image" width from underlying big resource. | |
int | ImageHeight () |
Retrieve the "image" height from underlying big 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 image associated with this flyweight instance into the given display at the given position. | |
Private Attributes | |
BigResource * | _resource |
The big resource being referenced by this flyweight class. In C#, a class is always a reference to an instance of the class so we take advantage of that here. In other languages, this would be a pointer to the big resource or a handle from which a pointer could be obtained. | |
Flyweight_Context | _context |
The context associated with this class. The calling entity uses this context to manipulate the flyweight class. | |
Associates a context with a big resource.
Definition at line 86 of file Flyweight_Classes.h.
using unique_ptr_t = std::unique_ptr<Flyweight_Class> |
Definition at line 89 of file Flyweight_Classes.h.
|
inline |
Default constructor.
Definition at line 111 of file Flyweight_Classes.h.
Flyweight_Class | ( | BigResource * | resource, |
Flyweight_Context | context | ||
) |
Constructor (accessible only to the class factory).
resource | The resource being represented by this class. This takes advantage of the fact that C# classes are always passed by reference so no actual copying of the resource is done. |
context | A Flyweight_Context instance containing the context for this Flyweight_Class instance. |
Definition at line 16 of file Flyweight_Classes.cpp.
References Flyweight_Class::_context, and Flyweight_Class::_resource.
~Flyweight_Class | ( | ) |
Destructor.
Definition at line 22 of file Flyweight_Classes.cpp.
Flyweight_Context Context | ( | ) |
Retrieve the context for this class instance.
Definition at line 26 of file Flyweight_Classes.cpp.
References Flyweight_Class::_context.
int ImageHeight | ( | ) |
Retrieve the "image" height from underlying big resource.
Definition at line 47 of file Flyweight_Classes.cpp.
References Flyweight_Class::_context, Flyweight_Class::_resource, and Flyweight_Context::ImageHeight.
int ImageWidth | ( | ) |
Retrieve the "image" width from underlying big resource.
Definition at line 37 of file Flyweight_Classes.cpp.
References Flyweight_Class::_context, Flyweight_Class::_resource, and Flyweight_Context::ImageWidth.
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.
display | A list of character arrays representing the display. |
offset_x | Offset from left edge of big resource to the left edge of the image to render. |
image_width | Width of image to render. |
image_height | Height of image to render. |
position_x | leftmost position within the display to place the upper left corner of the image, |
position_y | topmost position within the display to place the upper left corner of the image. |
Note that although this class has access to the context, it really shouldn't so as to keep a loose coupling between the context and this class. Therefore, the entity calling Render() will pass the position in as parameters even though that position is likely coming from the context.
Definition at line 56 of file Flyweight_Classes.cpp.
References Flyweight_Class::_resource, and BigResource::Render().
void SetContext | ( | Flyweight_Context | context | ) |
Set the context for this class instance.
Definition at line 31 of file Flyweight_Classes.cpp.
References Flyweight_Class::_context.
|
private |
The context associated with this class. The calling entity uses this context to manipulate the flyweight class.
Definition at line 105 of file Flyweight_Classes.h.
Referenced by Flyweight_Class::Context(), Flyweight_Class::Flyweight_Class(), Flyweight_Class::ImageHeight(), Flyweight_Class::ImageWidth(), and Flyweight_Class::SetContext().
|
private |
The big resource being referenced by this flyweight class. In C#, a class is always a reference to an instance of the class so we take advantage of that here. In other languages, this would be a pointer to the big resource or a handle from which a pointer could be obtained.
Definition at line 99 of file Flyweight_Classes.h.
Referenced by Flyweight_Class::Flyweight_Class(), Flyweight_Class::ImageHeight(), BigResource::ImageHeight(), Flyweight_Class::ImageWidth(), BigResource::ImageWidth(), BigResource::Render(), and Flyweight_Class::Render().