Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_list.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive Framework afw_list interface helpers
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
14 #include "afw_internal.h"
15 
16 
17 /* Get next value from list whose data type cType is afw_utf8_t. */
18 AFW_DEFINE(const afw_utf8_t *)
20  const afw_list_t *instance,
21  const afw_iterator_t * *iterator,
22  afw_xctx_t *xctx)
23 {
24  const void *internal;
25  const afw_data_type_t *data_type;
26 
27  afw_list_get_next_internal(instance, iterator, &data_type, &internal, xctx);
28  if (!internal) {
29  return NULL;
30  }
31 
32  if (!afw_utf8_equal(&data_type->cType, &afw_s_afw_utf8_t))
33  {
34  AFW_THROW_ERROR_Z(general,
35  "cType of list data type is not afw_utf8_t", xctx);
36  }
37  return (const afw_utf8_t *)internal;
38 }
39 
40 
41 
42 /* Set an list to immutable if it is not already. */
43 AFW_DEFINE(void)
45  const afw_list_t *instance, afw_xctx_t *xctx)
46 {
47  const afw_list_setter_t *setter;
48 
49  setter = afw_list_get_setter(instance, xctx);
50 
51  /* If already immutable, ignore, otherwise; set immutable. */
52  if (setter) {
53  afw_list_setter_set_immutable(setter, xctx);
54  }
55 }
56 
57 
58 /* Set an list to immutable and determine data type. */
61  const afw_list_t *instance, afw_xctx_t *xctx)
62 {
63  const afw_list_setter_t *setter;
64 
65  setter = afw_list_get_setter(instance, xctx);
66 
67  if (!setter) {
68  AFW_LIST_ERROR_OBJECT_IMMUTABLE;
69  }
70 
72  setter, xctx);
73 }
74 
75 
76 /* Call method add of interface afw_list_setter */
77 AFW_DEFINE(void)
79  const afw_list_t *instance,
80  const afw_data_type_t *data_type,
81  const void *internal,
82  afw_xctx_t *xctx)
83 {
84  const afw_list_setter_t *setter;
85 
86  setter = afw_list_get_setter(instance, xctx);
87 
88  if (!setter) {
89  AFW_LIST_ERROR_OBJECT_IMMUTABLE;
90  }
91 
92  afw_list_setter_add_internal(setter, data_type, internal, xctx);
93 }
94 
95 
96 
103 AFW_DEFINE(void)
105  const afw_list_t *instance,
106  const afw_value_t *value,
107  afw_xctx_t *xctx)
108 {
109  const afw_list_setter_t *setter;
110 
111  setter = afw_list_get_setter(instance, xctx);
112 
113  if (!setter) {
114  AFW_LIST_ERROR_OBJECT_IMMUTABLE;
115  }
116 
117  afw_list_setter_add_value(setter, value, xctx);
118 }
119 
120 
121 
127 AFW_DEFINE(void)
129  const afw_list_t *instance,
130  afw_xctx_t *xctx)
131 {
132  const afw_list_setter_t *setter;
133 
134  setter = afw_list_get_setter(instance, xctx);
135 
136  if (!setter) {
137  AFW_LIST_ERROR_OBJECT_IMMUTABLE;
138  }
139 
140  afw_list_setter_remove_all_values(setter, xctx);
141 }
142 
143 
144 
145 /* Call method remove of interface afw_list_setter */
146 AFW_DEFINE(void)
148  const afw_list_t *instance,
149  const afw_data_type_t *data_type,
150  const void *internal,
151  afw_xctx_t *xctx)
152 {
153  const afw_list_setter_t *setter;
154 
155  setter = afw_list_get_setter(instance, xctx);
156 
157  if (!setter) {
158  AFW_LIST_ERROR_OBJECT_IMMUTABLE;
159  }
160 
161  afw_list_setter_remove_internal(setter, data_type, internal, xctx);
162 }
163 
164 
165 
166 /* Call method remove_value of interface afw_list_setter */
167 AFW_DEFINE(void)
169  const afw_list_t *instance,
170  const afw_value_t *value,
171  afw_xctx_t *xctx)
172 {
173  const afw_list_setter_t *setter;
174 
175  setter = afw_list_get_setter(instance, xctx);
176 
177  if (!setter) {
178  AFW_LIST_ERROR_OBJECT_IMMUTABLE;
179  }
180 
181  afw_list_setter_remove_value(setter, value, xctx);
182 }
183 
184 
185 
186 /* Call method set_value_by_index of interface afw_list_setter */
187 AFW_DEFINE(void)
189  const afw_list_t *instance,
190  afw_size_t index,
191  const afw_value_t *value,
192  afw_xctx_t *xctx)
193 {
194  const afw_list_setter_t *setter;
195 
196  setter = afw_list_get_setter(instance, xctx);
197 
198  if (!setter) {
199  AFW_LIST_ERROR_OBJECT_IMMUTABLE;
200  }
201 
202  afw_list_setter_set_value_by_index(setter, index, value, xctx);
203 }
AFW_DEFINE(const afw_object_t *)
Adaptive Framework Core Internal.
struct afw_iterator_s afw_iterator_t
apr_size_t afw_size_t
size_t.
Definition: afw_common.h:151
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
Definition: afw_error.h:283
#define afw_list_get_next_internal(instance, iterator, data_type, internal, xctx)
Call method get_next_internal of interface afw_list.
#define afw_list_get_setter(instance, xctx)
Call method get_setter of interface afw_list.
#define afw_list_setter_add_internal(instance, data_type, internal, xctx)
Call method add_internal of interface afw_list_setter.
#define afw_list_setter_set_value_by_index(instance, index, value, xctx)
Call method set_value_by_index of interface afw_list_setter.
#define afw_list_setter_remove_internal(instance, data_type, internal, xctx)
Call method remove_internal of interface afw_list_setter.
#define afw_list_setter_set_immutable(instance, xctx)
Call method set_immutable of interface afw_list_setter.
#define afw_list_setter_determine_data_type_and_set_immutable(instance, xctx)
Call method determine_data_type_and_set_immutable of interface afw_list_setter.
#define afw_list_setter_remove_all_values(instance, xctx)
Call method remove_all_values of interface afw_list_setter.
#define afw_list_setter_remove_value(instance, value, xctx)
Call method remove_value of interface afw_list_setter.
#define afw_list_setter_add_value(instance, value, xctx)
Call method add_value of interface afw_list_setter.
afw_list_remove_all_values(const afw_list_t *instance, afw_xctx_t *xctx)
Call method remove_all_values of interface afw_list_setter.
Definition: afw_list.c:128
afw_list_determine_data_type_and_set_immutable(const afw_list_t *instance, afw_xctx_t *xctx)
Set list to immutable and determine data type of entries.
Definition: afw_list.c:60
afw_list_set_value_by_index(const afw_list_t *instance, afw_size_t index, const afw_value_t *value, afw_xctx_t *xctx)
Call method set_value_by_index of interface afw_list_setter.
Definition: afw_list.c:188
afw_list_remove_value(const afw_list_t *instance, const afw_value_t *value, afw_xctx_t *xctx)
Call method remove_value of interface afw_list_setter.
Definition: afw_list.c:168
afw_list_remove_internal(const afw_list_t *instance, const afw_data_type_t *data_type, const void *internal, afw_xctx_t *xctx)
Call method remove of interface afw_list_setter.
Definition: afw_list.c:147
afw_list_of_utf8_get_next(const afw_list_t *instance, const afw_iterator_t **iterator, afw_xctx_t *xctx)
Get next value from list whose data type cType is afw_utf8_t.
Definition: afw_list.c:19
afw_list_add_internal(const afw_list_t *instance, const afw_data_type_t *data_type, const void *internal, afw_xctx_t *xctx)
Call method add of interface afw_list_setter.
Definition: afw_list.c:78
afw_list_add_value(const afw_list_t *instance, const afw_value_t *value, afw_xctx_t *xctx)
Call method add_value of interface afw_list_setter.
Definition: afw_list.c:104
afw_list_set_immutable(const afw_list_t *instance, afw_xctx_t *xctx)
Set a list to immutable if not already.
Definition: afw_list.c:44
afw_boolean_t afw_utf8_equal(const afw_utf8_t *s1, const afw_utf8_t *s2)
Check to see if a string equals another string.
Interface afw_data_type public struct.
Interface afw_list public struct.
Interface afw_list_setter public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_value public struct.
Interface afw_xctx public struct.