Derive-C
Loading...
Searching...
No Matches
template.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <derive-c/core/debug/gdb_marker.h>
#include <derive-c/core/prelude.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 *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 ITEM get_value_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 ASSUME(self);
50 if (self->present) {
51 return NS(SELF, from)(ITEM_CLONE(&self->item));
52 }
53 return NS(SELF, empty)();
54}
static bool empty(ITER const *iter)
Definition template.h:361
#define ITEM_CLONE
Definition template.h:29
#define ASSUME(expr,...)
Definition macros.h:62
#define NS(pre, post)
Definition namespace.h:4
#define SELF
Definition def.h:52
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 93 of file template.h.

93 {
94 ASSUME(self);
95 if (self->present) {
96 ITEM_DELETE(&self->item);
97 }
98}
#define ITEM_DELETE
Definition template.h:27
bool present
Definition template.h:40
ITEM item
Definition template.h:38

◆ 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 ASSUME(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 ASSUME(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 ASSUME(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:

◆ get_value_or()

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

Definition at line 80 of file template.h.

80 {
81 ASSUME(self);
82 if (self->present) {
83 return self->item;
84 }
85 return default_value;
86}
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 88 of file template.h.

88 {
89 ASSUME(self);
90 return self->present;
91}
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 * self)
static

Definition at line 20 of file template.h.

20{ (void)self; }

◆ 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 100 of file template.h.

100 {
101 ASSUME(self);
102 bool was_present;
103 if (self->present) {
104 ITEM_DELETE(&self->item);
105 was_present = true;
106 } else {
107 was_present = false;
108 }
109 self->item = value;
110 self->present = true;
111 return was_present;
112}
Here is the call graph for this function:
Here is the caller graph for this function: