Design Pattern Examples
Overview of object-oriented design patterns
Flyweight_Image.c
Go to the documentation of this file.
1
6
7#include <stdlib.h>
8
9#include "Flyweight_Image.h"
10
12// Flyweight_ImageList_Clear()
15{
16 if (imageList != NULL && imageList->images != NULL && imageList->images_count != 0)
17 {
18 free(imageList->images);
19 imageList->images = NULL;
20 imageList->images_count = 0;
21 }
22}
23
25// Flyweight_ImageList_Add()
28{
29 Flyweight_Image* new_list = NULL;
30
31 if (imageList != NULL && image != NULL)
32 {
33 if (imageList->images == NULL)
34 {
35 new_list = malloc(sizeof(Flyweight_Image));
36 }
37 else
38 {
39 size_t newSize = (imageList->images_count + 1) * sizeof(Flyweight_Image);
40 new_list = realloc(imageList->images, newSize);
41 }
42
43 if (new_list != NULL)
44 {
45 imageList->images = new_list;
46 imageList->images[imageList->images_count] = *image;
47 imageList->images_count++;
48 }
49 }
50}
51
60//Flyweight_Class(BigResource* resource, Flyweight_Context context);
61//
65//Flyweight_Context Context();
66//
67//
71//void SetContext(Flyweight_Context context);
72//
73//
77//int ImageWidth();
78//
79//
83//int ImageHeight();
84//
105//void Render(std::vector<std::vector<char>>& display, int offset_x, int image_width, int image_height, int position_x, int position_y);
void Flyweight_ImageList_Clear(Flyweight_ImageList *imageList)
Clear the given Flyweight_ImageList object by freeing up all allocated Flyweight_image objects and re...
void Flyweight_ImageList_Add(Flyweight_ImageList *imageList, Flyweight_Image *image)
Add a Flyweight_Image object to the given Flyweight_ImageList object. The list takes ownership of the...
Declaration of the Flyweight_ImageList and Flyweight_Image structures, the latter which wraps the big...
Represents an image that associates a context with a big resource.
Represents an expandable list of Flyweight_Image objects. This is managed by the Flyweight_ImageList_...
size_t images_count
Number of Flyweight_image objects in the list.
Flyweight_Image * images
Dynamic list of Flyweight_Image objects.