Derive-C
Loading...
Searching...
No Matches
template.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <derive-c/core.h>
#include <derive-c/panic.h>
#include <derive-c/self.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  SELF

Macros

#define T   derive_c_parameter_t
#define T_DELETE   derive_c_parameter_t_delete

Functions

static SELF from (T value)
static SELF empty ()
static Tget (SELF *self)
static T const * get_const (SELF const *self)
static bool is_present (SELF const *self)
static void delete (SELF *self)
static bool replace (SELF *self, T value)

Macro Definition Documentation

◆ T

#define T   derive_c_parameter_t

Definition at line 18 of file template.h.

◆ T_DELETE

#define T_DELETE   derive_c_parameter_t_delete

Definition at line 20 of file template.h.

Function Documentation

◆ delete()

void delete ( SELF * self)
static

Definition at line 60 of file template.h.

60 {
61 DEBUG_ASSERT(self);
62 if (self->present) {
63 T_DELETE(&self->value);
64 }
65}
#define DEBUG_ASSERT(expr)
Definition panic.h:23
bool present
Definition template.h:31
T value
Definition template.h:29
#define T_DELETE
Definition template.h:20

◆ empty()

SELF empty ( )
static

Definition at line 37 of file template.h.

37{ return (SELF){.present = false}; }
#define SELF
Definition template.h:70
Here is the call graph for this function:

◆ from()

SELF from ( T value)
static

Definition at line 35 of file template.h.

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

◆ get()

T * get ( SELF * self)
static

Definition at line 39 of file template.h.

39 {
40 DEBUG_ASSERT(self);
41 if (self->present) {
42 return &self->value;
43 }
44 return NULL;
45}
Here is the call graph for this function:

◆ get_const()

T const * get_const ( SELF const * self)
static

Definition at line 47 of file template.h.

47 {
48 DEBUG_ASSERT(self);
49 if (self->present) {
50 return &self->value;
51 }
52 return NULL;
53}
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 55 of file template.h.

55 {
56 DEBUG_ASSERT(self);
57 return self->present;
58}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ replace()

bool replace ( SELF * self,
T value )
static

Definition at line 67 of file template.h.

67 {
68 DEBUG_ASSERT(self);
69 bool was_present;
70 if (self->present) {
71 T_DELETE(&self->value);
72 was_present = true;
73 } else {
74 was_present = false;
75 }
76 self->value = value;
77 self->present = true;
78 return was_present;
79}
Here is the call graph for this function:
Here is the caller graph for this function: