Design Pattern Examples
Overview of object-oriented design patterns
BigResource Class Reference

Represents some big resource. In this case, a text "image" rendered as a list of strings. each entry in the list is the same width. The height of the "image" is the number of entries in the list. This image is provided by the user. More...

#include <Flyweight_Classes.h>

Collaboration diagram for BigResource:
Collaboration graph

Public Types

using unique_ptr_t = std::unique_ptr< BigResource >
 

Public Member Functions

 BigResource (std::vector< std::string > resource, int resourceId)
 Constructor (accessibly only to the class factory).
 
 ~BigResource ()
 
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.
 
int ResourceId ()
 Retrieve the resource ID for this resource.
 
int ImageWidth ()
 Retrieve the "image" width of the resource.
 
int ImageHeight ()
 Retrieve the "image" height of the resource.
 
Flyweight_Class::unique_ptr_t CreateFlyweight (Flyweight_Context context)
 Generate a Flyweight class that will represent this big resource in some context-dependent way.
 

Private Attributes

std::vector< std::string > _resource
 
int _resourceId
 

Detailed Description

Represents some big resource. In this case, a text "image" rendered as a list of strings. each entry in the list is the same width. The height of the "image" is the number of entries in the list. This image is provided by the user.

The resource is represented by an ID. This ID is known by the user and is passed to the Flyweight_Class factory so the Flyweight_Class can get a reference to an instance of this BigResource class. Instances of this BigResource class are managed through the BigResourceManager class.

Definition at line 198 of file Flyweight_Classes.h.

Member Typedef Documentation

◆ unique_ptr_t

using unique_ptr_t = std::unique_ptr<BigResource>

Definition at line 201 of file Flyweight_Classes.h.

Constructor & Destructor Documentation

◆ BigResource()

BigResource ( std::vector< std::string >  resource,
int  resourceId 
)
inline

Constructor (accessibly only to the class factory).

Parameters
resourceThe resource to manage.
resourceIdID of the resource.

Definition at line 213 of file Flyweight_Classes.h.

References BigResource::_resource, and BigResource::_resourceId.

◆ ~BigResource()

~BigResource ( )
inline

Definition at line 219 of file Flyweight_Classes.h.

Member Function Documentation

◆ CreateFlyweight()

Flyweight_Class::unique_ptr_t CreateFlyweight ( Flyweight_Context  context)

Generate a Flyweight class that will represent this big resource in some context-dependent way.

Parameters
contextA Flyweight_Context instance containing the context for the desired Flyweight_Class instance.
Returns
A new instance of the Flyweight_Class.

Definition at line 145 of file Flyweight_Classes.cpp.

Referenced by BigResourceManager::CreateFlyweight().

◆ ImageHeight()

int ImageHeight ( )

Retrieve the "image" height of the resource.

Definition at line 140 of file Flyweight_Classes.cpp.

References BigResource::_resource.

◆ ImageWidth()

int ImageWidth ( )

Retrieve the "image" width of the resource.

Definition at line 131 of file Flyweight_Classes.cpp.

References BigResource::_resource.

◆ Render()

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.

Parameters
displayThe display in which to render.
offset_xOffset from left edge of big resource to the left edge of the image to render.
image_widthWidth of image to render.
image_heightHeight of image to render.
position_xX position where to put upper left corner of resource.
position_yY position where to put upper left corner of resource.

Definition at line 70 of file Flyweight_Classes.cpp.

References BigResource::_resource.

Referenced by Flyweight_Class::Render().

◆ ResourceId()

int ResourceId ( )

Retrieve the resource ID for this resource.

Definition at line 126 of file Flyweight_Classes.cpp.

References BigResource::_resourceId.

Member Data Documentation

◆ _resource

◆ _resourceId

int _resourceId
private

Definition at line 205 of file Flyweight_Classes.h.

Referenced by BigResource::BigResource(), and BigResource::ResourceId().


The documentation for this class was generated from the following files: