Derive-C
Loading...
Searching...
No Matches
template.h File Reference

Go to the source code of this file.

Data Structures

struct  SELF
 An allocator that prints to stdout when it allocates or frees memory. More...

Macros

#define SLOT_VALUE_DEBUG   DC_DEFAULT_DEBUG
 A tagged union containing an integer index type.

Functions

static void memory_tracker_empty (SELF const *slot)
static void set_empty (SELF *slot, SLOT_INDEX_TYPE next_free)
static void memory_tracker_present (SELF const *slot)
static void fill (SELF *slot, SLOT_VALUE value)
static void clone_from (SELF const *from_slot, SELF *to_slot)
static void debug (SELF const *self, dc_debug_fmt fmt, FILE *stream)
static void delete (SELF *self)

Macro Definition Documentation

◆ SLOT_VALUE_DEBUG

#define SLOT_VALUE_DEBUG   DC_DEFAULT_DEBUG

A tagged union containing an integer index type.

Definition at line 42 of file template.h.

Function Documentation

◆ clone_from()

void clone_from ( SELF const * from_slot,
SELF * to_slot )
static

Definition at line 83 of file template.h.

83 {
84 to_slot->present = from_slot->present;
85 if (from_slot->present) {
86 to_slot->value = SLOT_VALUE_CLONE(&from_slot->value);
88 } else {
89 to_slot->next_free = from_slot->next_free;
90 NS(SELF, memory_tracker_empty)(to_slot);
91 }
92}
#define SLOT_VALUE_CLONE
Definition template.h:67
#define NS(pre, post)
Definition namespace.h:4
#define SELF
Definition def.h:52
bool present
Definition template.h:45
SLOT_INDEX_TYPE next_free
Definition template.h:48
SLOT_VALUE value
Definition template.h:47
static void memory_tracker_present(SELF const *slot)
Definition template.h:68
static void memory_tracker_empty(SELF const *slot)
Definition template.h:53

◆ debug()

void debug ( SELF const * self,
dc_debug_fmt fmt,
FILE * stream )
static

Definition at line 94 of file template.h.

94 {
95 if (self->present) {
96 fprintf(stream, "[empty] { next_free: %lu}", (size_t)self->next_free);
97 } else {
98 fprintf(stream, "[full] ");
99 SLOT_VALUE_DEBUG(&self->value, fmt, stream);
100 }
101}
#define SLOT_VALUE_DEBUG
A tagged union containing an integer index type.
Definition template.h:42
static FILE * stream(SELF *self)
Opens a file for.
Definition template.h:107

◆ delete()

void delete ( SELF * self)
static

Definition at line 103 of file template.h.

103 {
104 if (self->present) {
105 SLOT_VALUE_DELETE(&self->value);
106 }
107}
#define SLOT_VALUE_DELETE
Definition template.h:69

◆ fill()

void fill ( SELF * slot,
SLOT_VALUE value )
static

Definition at line 77 of file template.h.

77 {
79 slot->present = true;
80 slot->value = value;
81}

◆ memory_tracker_empty()

void memory_tracker_empty ( SELF const * slot)
static

Definition at line 53 of file template.h.

53 {
55 sizeof(SLOT_VALUE));
57 &slot->next_free, sizeof(SLOT_INDEX_TYPE));
59 &slot->present, sizeof(bool));
60}
#define SLOT_INDEX_TYPE
Definition template.h:65
#define SLOT_VALUE
Definition template.h:66
static void dc_memory_tracker_set(dc_memory_tracker_level level, dc_memory_tracker_capability cap, const volatile void *addr, size_t size)
@ DC_MEMORY_TRACKER_LVL_CONTAINER
@ DC_MEMORY_TRACKER_CAP_WRITE
@ DC_MEMORY_TRACKER_CAP_NONE
@ DC_MEMORY_TRACKER_CAP_READ_WRITE

◆ memory_tracker_present()

void memory_tracker_present ( SELF const * slot)
static

◆ set_empty()

void set_empty ( SELF * slot,
SLOT_INDEX_TYPE next_free )
static

Definition at line 62 of file template.h.

62 {
64 slot->present = false;
65 slot->next_free = next_free;
66}