Derive-C
Loading...
Searching...
No Matches
option.c File Reference
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <derive-c/structures/option/template.h>
Include dependency graph for option.c:

Go to the source code of this file.

Classes

struct  complex_data

Macros

#define ITEM   struct complex_data
#define ITEM_DELETE   complex_data_delete
#define ITEM_CLONE   complex_data_clone
#define NAME   complex_data_option

Functions

void complex_data_delete (struct complex_data *self)
struct complex_data complex_data_clone (struct complex_data const *self)
void option_example ()
int main ()

Macro Definition Documentation

◆ ITEM

#define ITEM   struct complex_data

Definition at line 24 of file option.c.

◆ ITEM_CLONE

#define ITEM_CLONE   complex_data_clone

Definition at line 26 of file option.c.

◆ ITEM_DELETE

#define ITEM_DELETE   complex_data_delete

Definition at line 25 of file option.c.

◆ NAME

#define NAME   complex_data_option

Definition at line 27 of file option.c.

Function Documentation

◆ complex_data_clone()

struct complex_data complex_data_clone ( struct complex_data const * self)
Examples
structures/option.c.

Definition at line 16 of file option.c.

16 {
17 return (struct complex_data){
18 .x = self->x,
19 .y = self->y,
20 .description = strdup(self->description),
21 };
22}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ complex_data_delete()

void complex_data_delete ( struct complex_data * self)
Examples
structures/option.c, and structures/vector.c.

Definition at line 15 of file option.c.

15{ free(self->description); }
static void free(SELF *self, void *ptr)
Definition template.h:56
char * description
Definition option.c:12
Here is the call graph for this function:

◆ main()

int main ( )

Definition at line 53 of file option.c.

53{ option_example(); }
void option_example()
Definition option.c:30
Here is the call graph for this function:

◆ option_example()

void option_example ( )
Examples
structures/option.c.

Definition at line 30 of file option.c.

30 {
31 complex_data_option opt = complex_data_option_empty();
32 assert(!complex_data_option_is_present(&opt));
33
34 // when accessing a value, you get a pointer. Not present = NULL
35 assert(!complex_data_option_get(&opt));
36 assert(!complex_data_option_get_const(&opt));
37
38 bool was_present_1 = complex_data_option_replace(
39 &opt, (struct complex_data){.x = 42, .y = 3.14, .description = strdup("A complex data")});
40 assert(!was_present_1);
41
42 assert(complex_data_option_is_present(&opt));
43 assert(complex_data_option_get(&opt));
44
45 bool was_present_2 = complex_data_option_replace(
46 &opt,
47 (struct complex_data){.x = 100, .y = 2.71, .description = strdup("Another complex data")});
48 assert(was_present_2);
49
50 complex_data_option_delete(&opt);
51}
Here is the caller graph for this function: