-
Notifications
You must be signed in to change notification settings - Fork 0
/
shape.c
62 lines (50 loc) · 1.1 KB
/
shape.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* shape.c
*
* Created on: Mar 30, 2020
* Author: serbay.ozkan
*/
#include <assert.h>
#include "shape.h"
static uint32_t shape_area_(shape_t const * const this_p);
static void shape_draw_(shape_t const * const this_p);
void shape_ctor(shape_t *const this_p, int16_t x, int16_t y)
{
//Vtable of the shape class
static struct shape_vtable const vtable = {
&shape_area_,
&shape_draw_
};
this_p->vptr = &vtable;
this_p->x = x;
this_p->y = y;
}
/*
* Getter Method Imp.
*/
int16_t shape_get_x(shape_t *const this_p)
{
return this_p->x;
}
/*
* Getter Method Imp.
*/
int16_t shape_get_y(shape_t *const this_p)
{
return this_p->y;
}
void shape_move_by(shape_t *const this_p, int16_t x, int16_t y)
{
this_p->x += x;
this_p->y += y;
}
/* Shape class implementations of its virtual functions... */
static uint32_t shape_area_(shape_t const * const this_p)
{
assert(0); /* purely-virtual function should never be called */
return 0U; /* to avoid compiler warnings */
}
static void shape_draw_(shape_t const * const this_p)
{
assert(0); /* purely-virtual function should never be called */
}