Derive-C
Loading...
Searching...
No Matches
mutation_tracker.h File Reference
#include <derive-c/core/prelude.h>
#include <stddef.h>
Include dependency graph for mutation_tracker.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

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 mutation_tracker mutation_tracker_new ()
static void mutation_tracker_mutate (mutation_tracker *self)
static mutation_version mutation_tracker_get (mutation_tracker const *self)
static void mutation_version_check (mutation_version const *self)

Function Documentation

◆ mutation_tracker_get()

mutation_version mutation_tracker_get ( mutation_tracker const * self)
static

Definition at line 42 of file mutation_tracker.h.

42 {
43 ASSERT(self);
44 return (mutation_version){.tracker = self, .count = self->count};
45}
#define ASSERT(expr,...)
Definition macros.h:42
Here is the caller graph for this function:

◆ mutation_tracker_mutate()

void mutation_tracker_mutate ( mutation_tracker * self)
static

Definition at line 37 of file mutation_tracker.h.

37 {
38 ASSERT(self);
39 self->count++;
40}
Here is the caller graph for this function:

◆ mutation_tracker_new()

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...
Here is the caller graph for this function:

◆ mutation_version_check()

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 ASSERT(self->count == self->tracker->count, "No mutations to the tracker's data structure were "
52 "expected... however it has been mutated");
53}
Here is the caller graph for this function: