YetAnotherCoupler 3.5.2
Loading...
Searching...
No Matches
field_data.c
Go to the documentation of this file.
1// Copyright (c) 2024 The YAC Authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#include <stdlib.h>
6
7#include "field_data.h"
8#include "utils_common.h"
9
11 struct {
12 char * name;
13 int * data;
14 } * masks;
18};
19
21
22 struct yac_field_data * field_data = xmalloc(1 * sizeof(*field_data));
23 field_data->masks_count = 0;
24 field_data->masks = NULL;
25 field_data->coordinates_count = 0;
26 field_data->coordinates = NULL;
27 return field_data;
28}
29
31 struct yac_field_data * field_data, int const * mask,
32 char const * mask_name) {
33
34 size_t masks_idx = field_data->masks_count++;
35 field_data->masks =
36 xrealloc(field_data->masks,
37 field_data->masks_count * sizeof(*(field_data->masks)));
38 field_data->masks[masks_idx].name = (char *)mask_name;
39 field_data->masks[masks_idx].data = (int*)mask;
40
41 return masks_idx;
42}
43
46
47 size_t coordinates_idx = field_data->coordinates_count++;
48 field_data->coordinates =
50 field_data->coordinates,
51 field_data->coordinates_count * sizeof(*(field_data->coordinates)));
52 field_data->coordinates[coordinates_idx] = coordinates;
53
54 return coordinates_idx;
55}
56
58
59 return field_data->masks_count;
60}
61
63 struct yac_field_data * field_data, size_t mask_idx) {
64
66 mask_idx < field_data->masks_count,
67 "ERROR(yac_field_data_get_mask_data): invalid mask index");
68
69 return field_data->masks[mask_idx].data;
70}
71
73 struct yac_field_data * field_data, size_t mask_idx, int * mask_data) {
74
76 mask_idx < field_data->masks_count,
77 "ERROR(yac_field_data_set_mask_data): invalid mask index");
78
79 field_data->masks[mask_idx].data = mask_data;
80}
81
83 struct yac_field_data * field_data, size_t mask_idx) {
84
86 mask_idx < field_data->masks_count,
87 "ERROR(yac_field_data_get_mask_name): invalid mask index");
88
89 return field_data->masks[mask_idx].name;
90}
91
93
94 return field_data->coordinates_count;
95}
96
98 struct yac_field_data * field_data, size_t coordinates_idx) {
99
101 coordinates_idx < field_data->coordinates_count,
102 "ERROR(yac_field_data_get_coordinates_data): invalid coordinates index");
103
104 return
105 (yac_const_coordinate_pointer)(field_data->coordinates[coordinates_idx]);
106}
107
109 struct yac_field_data * field_data, size_t coordinates_idx,
110 yac_coordinate_pointer coordinates_data) {
111
113 coordinates_idx < field_data->coordinates_count,
114 "ERROR(yac_field_data_set_coordinates_data): invalid coordinates index");
115
116 field_data->coordinates[coordinates_idx] = coordinates_data;
117}
118
119void yac_field_data_delete(struct yac_field_data * field_data) {
120
121 for (size_t i = 0; i < field_data->masks_count; ++i) {
122 free(field_data->masks[i].name);
123 free(field_data->masks[i].data);
124 }
125 free(field_data->masks);
126 for (size_t i = 0; i < field_data->coordinates_count; ++i)
127 free(field_data->coordinates[i]);
128 free(field_data->coordinates);
129 free(field_data);
130}
size_t yac_field_data_get_masks_count(struct yac_field_data *field_data)
Definition field_data.c:57
void yac_field_data_delete(struct yac_field_data *field_data)
Definition field_data.c:119
void yac_field_data_set_mask_data(struct yac_field_data *field_data, size_t mask_idx, int *mask_data)
Definition field_data.c:72
size_t yac_field_data_get_coordinates_count(struct yac_field_data *field_data)
Definition field_data.c:92
yac_const_coordinate_pointer yac_field_data_get_coordinates_data(struct yac_field_data *field_data, size_t coordinates_idx)
Definition field_data.c:97
int const * yac_field_data_get_mask_data(struct yac_field_data *field_data, size_t mask_idx)
Definition field_data.c:62
char const * yac_field_data_get_mask_name(struct yac_field_data *field_data, size_t mask_idx)
Definition field_data.c:82
void yac_field_data_set_coordinates_data(struct yac_field_data *field_data, size_t coordinates_idx, yac_coordinate_pointer coordinates_data)
Definition field_data.c:108
size_t yac_field_data_add_mask_nocpy(struct yac_field_data *field_data, int const *mask, char const *mask_name)
Definition field_data.c:30
struct yac_field_data * yac_field_data_empty_new()
Definition field_data.c:20
size_t yac_field_data_add_coordinates_nocpy(struct yac_field_data *field_data, yac_coordinate_pointer coordinates)
Definition field_data.c:44
#define xrealloc(ptr, size)
Definition ppm_xfuncs.h:67
#define xmalloc(size)
Definition ppm_xfuncs.h:66
size_t masks_count
Definition field_data.c:15
yac_coordinate_pointer * coordinates
Definition field_data.c:16
struct yac_field_data::@1 * masks
size_t coordinates_count
Definition field_data.c:17
#define YAC_ASSERT(exp, msg)
Definition yac_assert.h:16
double const (* yac_const_coordinate_pointer)[3]
Definition yac_types.h:20
double(* yac_coordinate_pointer)[3]
Definition yac_types.h:19