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 DC_INTERNAL void memory_tracker_empty (SELF const *slot)
static DC_INTERNAL void set_empty (SELF *slot, SLOT_INDEX_TYPE next_free)
static DC_INTERNAL void memory_tracker_present (SELF const *slot)
static DC_INTERNAL void fill (SELF *slot, SLOT_VALUE value)
static DC_INTERNAL void clone_from (SELF const *from_slot, SELF *to_slot)
static DC_INTERNAL void debug (SELF const *self, dc_debug_fmt fmt, FILE *stream)
static DC_INTERNAL 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 43 of file template.h.

Function Documentation

◆ clone_from()

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

Definition at line 94 of file template.h.

94 {
95 to_slot->present = from_slot->present;
96 if (from_slot->present) {
97 NS(SELF, fill)(to_slot, SLOT_VALUE_CLONE(&from_slot->value));
98 } else {
99 NS(SELF, set_empty)(to_slot, from_slot->next_free);
100 }
101}
#define SLOT_VALUE_CLONE
Definition template.h:69
#define SELF
Definition def.h:52
#define NS(pre, post)
Definition namespace.h:14
bool present
Definition template.h:45
SLOT_INDEX_TYPE next_free
Definition template.h:59
static DC_INTERNAL void set_empty(SELF *slot, SLOT_INDEX_TYPE next_free)
Definition template.h:73
static DC_INTERNAL void fill(SELF *slot, SLOT_VALUE value)
Definition template.h:88

◆ debug()

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

Definition at line 103 of file template.h.

103 {
104 if (self->present) {
105 fprintf(stream, "[empty] { next_free: %lu}", (size_t)self->next_free);
106 } else {
107 fprintf(stream, "[full] ");
108 SLOT_VALUE_DEBUG(&self->value, fmt, stream);
109 }
110}
#define SLOT_VALUE_DEBUG
A tagged union containing an integer index type.
Definition template.h:43
static DC_PUBLIC FILE * stream(SELF *self)
Definition template.h:108

◆ delete()

DC_INTERNAL void delete ( SELF * self)
static

Definition at line 112 of file template.h.

112 {
113 if (self->present) {
114 SLOT_VALUE_DELETE(&self->value);
115 }
116}
#define SLOT_VALUE_DELETE
Definition template.h:71
SLOT_VALUE value
Definition template.h:58

◆ fill()

DC_INTERNAL void fill ( SELF * slot,
SLOT_VALUE value )
static

Definition at line 88 of file template.h.

88 {
90 slot->present = true;
91 slot->value = value;
92}
static DC_INTERNAL void memory_tracker_present(SELF const *slot)
Definition template.h:79

◆ memory_tracker_empty()

DC_INTERNAL void memory_tracker_empty ( SELF const * slot)
static

Definition at line 64 of file template.h.

64 {
66 sizeof(SLOT_VALUE));
68 &slot->next_free, sizeof(SLOT_INDEX_TYPE));
70 &slot->present, sizeof(bool));
71}
#define SLOT_INDEX_TYPE
Definition template.h:67
#define SLOT_VALUE
Definition template.h:68
static DC_PUBLIC 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()

DC_INTERNAL void memory_tracker_present ( SELF const * slot)
static

◆ set_empty()

DC_INTERNAL void set_empty ( SELF * slot,
SLOT_INDEX_TYPE next_free )
static

Definition at line 73 of file template.h.

73 {
75 slot->present = false;
76 slot->next_free = next_free;
77}
static DC_INTERNAL void memory_tracker_empty(SELF const *slot)
Definition template.h:64