Derive-C
Loading...
Searching...
No Matches
template.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <derive-c/core/helpers.h>
#include <derive-c/core/panic.h>
#include <derive-c/core/self/def.h>
#include <derive-c/core/self/undef.h>
Include dependency graph for template.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  item_t
 A queue comprised of an extendable circular buffer. More...
struct  SELF
 An allocator that prints to stdout when it allocates or frees memory. More...

Macros

#define ITEM   item_t
#define ITEM_DELETE   item_delete
#define ITEM_CLONE   item_clone
#define ITEM_EQ   item_eq

Functions

static void item_delete (item_t *UNUSED(self))
static item_t item_clone (item_t const *self)
static bool item_eq (item_t const *a, item_t const *b)
static SELF from (ITEM value)
static SELF empty ()
static SELF clone (SELF const *self)
static ITEMget (SELF *self)
static ITEM const * get_const (SELF const *self)
static ITEM const * get_const_or (SELF const *self, ITEM const *default_value)
static bool is_present (SELF const *self)
static void delete (SELF *self)
static bool replace (SELF *self, ITEM value)

Macro Definition Documentation

◆ ITEM

#define ITEM   item_t

Definition at line 19 of file template.h.

◆ ITEM_CLONE

#define ITEM_CLONE   item_clone

Definition at line 23 of file template.h.

◆ ITEM_DELETE

#define ITEM_DELETE   item_delete

Definition at line 21 of file template.h.

◆ ITEM_EQ

#define ITEM_EQ   item_eq

Definition at line 25 of file template.h.

Function Documentation

◆ clone()

SELF clone ( SELF const * self)
static

Definition at line 48 of file template.h.

48 {
49 DEBUG_ASSERT(self);
50 if (self->present) {
51 return NS(SELF, from)(ITEM_CLONE(&self->item));
52 }
53 return NS(SELF, empty)();
54}
#define NS(pre, post)
Definition helpers.h:6
#define DEBUG_ASSERT(expr)
Definition panic.h:34
#define SELF
Definition def.h:51
static bool empty(ITER const *iter)
Definition template.h:293
#define ITEM_CLONE
Definition template.h:26
static SELF from(ITEM value)
Definition template.h:44
Here is the call graph for this function:

◆ delete()

void delete ( SELF * self)
static

Definition at line 85 of file template.h.

85 {
86 DEBUG_ASSERT(self);
87 if (self->present) {
88 ITEM_DELETE(&self->item);
89 }
90}
bool present
Definition template.h:40
ITEM item
Definition template.h:38
#define ITEM_DELETE
Definition template.h:24

◆ empty()

SELF empty ( )
static

Definition at line 46 of file template.h.

46{ return (SELF){.present = false}; }
Here is the call graph for this function:

◆ from()

SELF from ( ITEM value)
static

Definition at line 44 of file template.h.

44{ return (SELF){.item = value, .present = true}; }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get()

ITEM * get ( SELF * self)
static

Definition at line 56 of file template.h.

56 {
57 DEBUG_ASSERT(self);
58 if (self->present) {
59 return &self->item;
60 }
61 return NULL;
62}
Here is the call graph for this function:

◆ get_const()

ITEM const * get_const ( SELF const * self)
static

Definition at line 64 of file template.h.

64 {
65 DEBUG_ASSERT(self);
66 if (self->present) {
67 return &self->item;
68 }
69 return NULL;
70}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_const_or()

ITEM const * get_const_or ( SELF const * self,
ITEM const * default_value )
static

Definition at line 72 of file template.h.

72 {
73 DEBUG_ASSERT(self);
74 if (self->present) {
75 return &self->item;
76 }
77 return default_value;
78}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_present()

bool is_present ( SELF const * self)
static

Definition at line 80 of file template.h.

80 {
81 DEBUG_ASSERT(self);
82 return self->present;
83}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ item_clone()

item_t item_clone ( item_t const * self)
static

Definition at line 22 of file template.h.

22{ return *self; }

◆ item_delete()

void item_delete ( item_t * UNUSEDself)
static

Definition at line 20 of file template.h.

20{}

◆ item_eq()

bool item_eq ( item_t const * a,
item_t const * b )
static

Definition at line 24 of file template.h.

24{ return a->x == b->x; }

◆ replace()

bool replace ( SELF * self,
ITEM value )
static

Definition at line 92 of file template.h.

92 {
93 DEBUG_ASSERT(self);
94 bool was_present;
95 if (self->present) {
96 ITEM_DELETE(&self->item);
97 was_present = true;
98 } else {
99 was_present = false;
100 }
101 self->item = value;
102 self->present = true;
103 return was_present;
104}
Here is the call graph for this function:
Here is the caller graph for this function: