Derive-C
Loading...
Searching...
No Matches
mutation_tracker.h File Reference
#include <derive-c/core/prelude.h>
#include <stddef.h>

Go to the source code of this file.

Data Structures

struct  mutation_tracker
 tracks a specific version of a value, so that this can be compared later to check modification For example, checking iterator invalidation in debug mode. More...
struct  mutation_version

Functions

static DC_PUBLIC mutation_tracker mutation_tracker_new ()
static DC_PUBLIC void mutation_tracker_mutate (mutation_tracker *self)
static DC_PUBLIC mutation_version mutation_tracker_get (mutation_tracker const *self)
static DC_PUBLIC void mutation_version_check (mutation_version const *self)

Function Documentation

◆ mutation_tracker_get()

DC_PUBLIC mutation_version mutation_tracker_get ( mutation_tracker const * self)
static

Definition at line 42 of file mutation_tracker.h.

42 {
43 DC_ASSERT(self);
44 return (mutation_version){.tracker = self, .count = self->count};
45}
#define DC_ASSERT(expr,...)
Definition panic.h:37

◆ mutation_tracker_mutate()

DC_PUBLIC void mutation_tracker_mutate ( mutation_tracker * self)
static

Definition at line 37 of file mutation_tracker.h.

37 {
38 DC_ASSERT(self);
39 self->count++;
40}

◆ mutation_tracker_new()

DC_PUBLIC mutation_tracker mutation_tracker_new ( )
static

Definition at line 35 of file mutation_tracker.h.

35{ return (mutation_tracker){.count = 0}; }
tracks a specific version of a value, so that this can be compared later to check modification For ex...

◆ mutation_version_check()

DC_PUBLIC void mutation_version_check ( mutation_version const * self)
static

Throw on the tracker version not matching. For example an iterator over a vector may store the version from it's creation, so that on access it can check it was not invalidated by mutation to the vector.

Definition at line 50 of file mutation_tracker.h.

50 {
51 DC_ASSERT(self->count == self->tracker->count,
52 "No mutations to the tracker's data structure were "
53 "expected... however it has been mutated");
54}