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
|
#include <stdlib.h>
#include <stdio.h>
#include "point.h"
#define TYPE Point
DEFINE_OBJECT_STRUCTURE(TYPE) {
float x;
float y;
};
CONSTRUCTOR_IMPLEMENT(TYPE);
void METHOD(TYPE, init, float x, float y) {
CATCH_SELF_NULL(TYPE_init);
self->x = x;
self->y = y;
}
int METHOD(TYPE, toString, char* buffer) {
CATCH_SELF_NULL(TYPE_toString);
return sprintf(buffer, NAMEOF(TYPE) " { x = %.2f, y = %.2f }", self->x, self->y);
}
GETTER_IMPLEMENT(TYPE, float, x);
SETTER_IMPLEMENT(TYPE, float, x);
GETTER_IMPLEMENT(TYPE, float, y);
SETTER_IMPLEMENT(TYPE, float, y);
#undef TYPE
|