1 /*
2 *
testuhr.c
3 *
4 * Autor: H.Drachenfels
5 * Erstellt am: 25.7.2018
6 */
7
8 #include "testuhr.h"
9 #include "uhr_impl.h"
10 #include <stdlib.h>
11
12 struct testuhr
13 {
14 uhr interface; // muss am Anfang stehen
15 unsigned stunde;
16 unsigned minute;
17 };
18
19 static void destruct(uhr * const u);
20 static void ablesen(const uhr * const u, unsigned *s, unsigned *m);
21
22 uhr *new_testuhr()
23 {
24 struct testuhr *this_p = (struct testuhr*) malloc(sizeof (struct testuhr));
25 if (!this_p) return NULL;
26
27 this_p->interface.destruct = destruct;
28 this_p->interface.ablesen = ablesen;
29
30 this_p->stunde = 0;
31 this_p->minute = 0;
32
33 return &this_p->interface;
34 }
35
36 void testuhr_stellen(uhr * const u, unsigned s, unsigned m)
37 {
38 struct testuhr * const this_p = (struct testuhr *) u; // Downcast
39 this_p->stunde = (s + m / 60) % 24;
40 this_p->minute = m % 60;
41 }
42
43 static void destruct(uhr * const u)
44 {
45 free(u);
46 }
47
48 static void ablesen(const uhr * const u, unsigned *s, unsigned *m)
49 {
50 const struct testuhr * const this_p = (const struct testuhr *) u; // Downcast
51 *s = this_p->stunde;
52 if (m) *m = this_p->minute;
53 }
54