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

◆ T_DELETE

#define T_DELETE   derive_c_parameter_t_delete

Definition at line 18 of file template.h.

Function Documentation

◆ delete()

static 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 T_DELETE
Definition template.h:18
#define DEBUG_ASSERT(expr)
Definition panic.h:24
bool present
Definition template.h:29
T value
Definition template.h:27

◆ empty()

static SELF empty ( )
static

Definition at line 35 of file template.h.

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

◆ from()

static SELF from ( T value)
static

Definition at line 33 of file template.h.

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

◆ get()

static T * get ( SELF * self)
static

Definition at line 37 of file template.h.

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

◆ get_const()

static T const * get_const ( SELF const * self)
static

Definition at line 46 of file template.h.

46 {
47 DEBUG_ASSERT(self);
48 if (self->present) {
49 return &self->value;
50 } else {
51 return NULL;
52 }
53}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_present()

static 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()

static 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: