Derive-C
Loading...
Searching...
No Matches
mutation_tracker.h
Go to the documentation of this file.
1
3
4#pragma once
6#include <stddef.h>
7
8#if defined NDEBUG
9
12
14
15static void mutation_tracker_mutate(mutation_tracker* self) { (void)self; }
16
18 (void)self;
19 return (mutation_version){};
20}
21
22static void mutation_version_check(mutation_version const* self) { (void)self; }
23
24#else
25
26typedef struct {
27 size_t count;
29
30typedef struct {
32 size_t const count;
34
35static mutation_tracker mutation_tracker_new() { return (mutation_tracker){.count = 0}; }
36
38 ASSERT(self);
39 self->count++;
40}
41
43 ASSERT(self);
44 return (mutation_version){.tracker = self, .count = self->count};
45}
46
50static void mutation_version_check(mutation_version const* self) {
51 ASSERT(self->count == self->tracker->count, "No mutations to the tracker's data structure were "
52 "expected... however it has been mutated");
53}
54#endif
#define ASSERT(expr,...)
Definition macros.h:42
static mutation_tracker mutation_tracker_new()
static void mutation_version_check(mutation_version const *self)
static mutation_version mutation_tracker_get(mutation_tracker const *self)
static void mutation_tracker_mutate(mutation_tracker *self)
tracks a specific version of a value, so that this can be compared later to check modification For ex...
mutation_tracker const * tracker
#define ZERO_SIZED(TYPE)
Zero sized types are useful as markers (e.g. for gdb printing, or to replace debug info structs.
Definition zerosized.h:15