Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_object_properties_callback.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive Framework Properties Callback Object Implementation
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
14 #include "afw_internal.h"
15 
16 
17 
18 #define impl_afw_object_get_meta \
19  afw_object_impl_internal_get_meta
20 
21 #define impl_afw_object_get_property_meta \
22  afw_object_impl_internal_get_property_meta
23 
24 #define impl_afw_object_get_next_property_meta \
25  afw_object_impl_internal_get_next_property_meta
26 
27 
28 /* Declares and rti/inf defines for interface afw_object */
29 #define AFW_IMPLEMENTATION_ID "properties_callback"
32 
33 
34 #define IMPL_ASSERT_MUTABLE(instance, xctx) \
35 if (!(instance)->p) {\
36  AFW_THROW_ERROR_Z(general, \
37  "Can not set meta in a const object", xctx); \
38 }
39 
40 
41 /* Create a mutable composite of immutable objects. */
42 AFW_DEFINE(const afw_object_t *)
44  void *data,
45  afw_size_t count,
47  const afw_pool_t *p, afw_xctx_t *xctx)
48 {
50 
51  self = afw_pool_calloc_type(p,
53  self->pub.inf = &impl_afw_object_inf;
54  self->pub.p = p;
55  self->setter.inf = &impl_afw_object_setter_inf;
56  self->setter.object = (const afw_object_t *)self;
57  self->data = data;
58  self->callbacks = &callbacks[0];
59  self->end = &callbacks[count];
60  return (const afw_object_t *)self;
61 }
62 
63 
64 /*
65  * Implementation of method release for interface afw_object.
66  */
67 void
69  const afw_object_t *instance,
70  afw_xctx_t *xctx)
71 {
72 
73 }
74 
75 /*
76  * Implementation of method add_reference for interface afw_object.
77  */
78 void
80  const afw_object_t *instance,
81  afw_xctx_t *xctx)
82 {
83 
84 }
85 
86 /*
87  * Implementation of method get_count for interface afw_object.
88  */
91  const afw_object_t * instance,
92  afw_xctx_t * xctx)
93 {
94 // <afwdev {prefixed_interface_name}>_self_t *self =
95 // (<afwdev {prefixed_interface_name}>_self_t *)instance;
96 
98  AFW_THROW_ERROR_Z(general, "Method not implemented.", xctx);
99 
100 }
101 
102 /*
103  * Implementation of method get_property for interface afw_object.
104  */
105 const afw_value_t *
107  const afw_object_t *instance,
108  const afw_utf8_t *property_name,
109  afw_xctx_t *xctx)
110 {
114  const afw_value_t *result;
115 
116  result = NULL;
117  for (e = self->callbacks; e < self->end; e++)
118  {
119  if (afw_utf8_equal(e->property_name, property_name)) {
120  result = e->get(self, property_name, xctx);
121  break;
122  }
123  }
124 
125  return result;
126 }
127 
128 /*
129  * Implementation of method get_next_property for interface afw_object.
130  */
131 const afw_value_t *
133  const afw_object_t *instance,
134  const afw_iterator_t **iterator,
135  const afw_utf8_t **property_name,
136  afw_xctx_t *xctx)
137 {
140  const afw_value_t *result;
142 
143  result = NULL;
144  if (property_name) {
145  *property_name = NULL;
146  }
147 
148  if (!*iterator) {
149  *iterator = (afw_iterator_t *)self->callbacks;
150  }
151 
152  for (e = self->callbacks; e < self->end; e++)
153  {
154  result = e->get(self, e->property_name, xctx);
155  if (result) {
156  *iterator = (afw_iterator_t *)(e + 1);
157  if (property_name) {
158  *property_name = e->property_name;
159  }
160  break;
161  }
162  }
163 
164  return result;
165 }
166 
167 /*
168  * Implementation of method has_property for interface afw_object.
169  */
172  const afw_object_t *instance,
173  const afw_utf8_t *property_name,
174  afw_xctx_t *xctx)
175 {
176  afw_boolean_t result;
177 
178  result = impl_afw_object_get_property(instance, property_name, xctx)
179  != NULL;
180 
181  return result;
182 }
183 
184 /*
185  * Implementation of method get_setter for interface afw_object.
186  */
187 const afw_object_setter_t *
189  const afw_object_t *instance,
190  afw_xctx_t *xctx)
191 {
194 
195  return (self->immutable) ? NULL : &self->setter;
196 }
197 
198 /*
199  * Implementation of method set_immutable for interface afw_object_setter.
200  */
201 void
203  const afw_object_setter_t * instance,
204  afw_xctx_t *xctx)
205 {
208 
209  self->immutable = true;
210 }
211 
212 /*
213  * Implementation of method set_property for interface afw_object_setter.
214  */
215 void
217  const afw_object_setter_t * instance,
218  const afw_utf8_t * property_name,
219  const afw_value_t * value,
220  afw_xctx_t *xctx)
221 {
225 
226  if (!self->immutable) {
227  for (e = self->callbacks; e < self->end; e++)
228  {
229  if (afw_utf8_equal(e->property_name, property_name)) {
230  if (!e->set) {
231  break;
232  }
233  e->set(self->data, property_name, value, xctx);
234  return;
235  }
236  }
237  }
238 
239  AFW_OBJECT_ERROR_PROPERTY_IMMUTABLE(property_name);
240 }
AFW_DEFINE(const afw_object_t *)
Adaptive Framework Core Internal.
Interface afw_interface implementation declares.
Interface afw_interface implementation declares.
struct afw_iterator_s afw_iterator_t
_Bool afw_boolean_t
Definition: afw_common.h:373
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
const afw_object_setter_t * impl_afw_object_get_setter(const afw_object_t *instance, afw_xctx_t *xctx)
void impl_afw_object_add_reference(const afw_object_t *instance, afw_xctx_t *xctx)
const afw_value_t * impl_afw_object_get_next_property(const afw_object_t *instance, const afw_iterator_t **iterator, const afw_utf8_t **property_name, afw_xctx_t *xctx)
void impl_afw_object_release(const afw_object_t *instance, afw_xctx_t *xctx)
const afw_value_t * impl_afw_object_get_property(const afw_object_t *instance, const afw_utf8_t *property_name, afw_xctx_t *xctx)
afw_boolean_t impl_afw_object_has_property(const afw_object_t *instance, const afw_utf8_t *property_name, afw_xctx_t *xctx)
afw_size_t impl_afw_object_get_count(const afw_object_t *instance, afw_xctx_t *xctx)
void impl_afw_object_setter_set_immutable(const afw_object_setter_t *instance, afw_xctx_t *xctx)
void impl_afw_object_setter_set_property(const afw_object_setter_t *instance, const afw_utf8_t *property_name, const afw_value_t *value, afw_xctx_t *xctx)
afw_object_create_properties_callback(void *data, afw_size_t count, const afw_object_properties_callback_entry_t callbacks[], const afw_pool_t *p, afw_xctx_t *xctx)
Create a mutable composite of unmutable objects.
#define afw_pool_calloc_type(instance, type, xctx)
Macro to allocate cleared memory to hold type in pool.
Definition: afw_pool.h:167
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.
Struct for afw_object_properties_callback_entry_t.
Definition: afw_object.h:839
Interface afw_object public struct.
Interface afw_object_setter public struct.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_value public struct.
Interface afw_xctx public struct.