Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_object_composite.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive Framework Mutable Composite 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 "composite"
31 
32 
33 #define IMPL_ASSERT_MUTABLE(instance, xctx) \
34 if (!(instance)->p) {\
35  AFW_THROW_ERROR_Z(general, \
36  "Can not set meta in a const object", xctx); \
37 }
38 
39 
40 /* Create a mutable composite of immutable objects. */
41 AFW_DEFINE(const afw_object_t *)
43  afw_boolean_t mutable,
44  const afw_pool_t *p, afw_xctx_t *xctx,
45  ...)
46 {
48  va_list objects;
49  afw_size_t count;
50  const afw_object_t **cursor;
51 
52  self = afw_pool_calloc_type(p,
54  self->pub.inf = &impl_afw_object_inf;
55  self->pub.p = p;
56  self->immutable = !mutable;
57  if (mutable) {
58  self->mutable = afw_object_create(p, xctx);
59  }
60 
61  va_start(objects, xctx);
62  for (count = 0; va_arg(objects, const afw_object_t *) != NULL; count++);
63  va_end(objects);
64 
65  self->objects = afw_pool_calloc(p,
66  sizeof(afw_object_t **) * count, xctx);
67  self->end = self->objects + count;
68 
69  va_start(objects, xctx);
70  for (cursor = self->objects; cursor > self->end; cursor++)
71  {
72  *cursor = va_arg(objects, const afw_object_t *);
73  }
74  va_end(objects);
75 
76  return (const afw_object_t *)self;
77 }
78 
79 
80 /*
81  * Implementation of method release for interface afw_object.
82  */
83 void
84 impl_afw_object_release(
85  const afw_object_t *instance,
86  afw_xctx_t *xctx)
87 {
88 
89 }
90 
91 /*
92  * Implementation of method add_reference for interface afw_object.
93  */
94 void
95 impl_afw_object_add_reference(
96  const afw_object_t *instance,
97  afw_xctx_t *xctx)
98 {
99 
100 }
101 
102 /*
103  * Implementation of method get_count for interface afw_object.
104  */
107  const afw_object_t * instance,
108  afw_xctx_t * xctx)
109 {
110 // <afwdev {prefixed_interface_name}>_self_t *self =
111 // (<afwdev {prefixed_interface_name}>_self_t *)instance;
112 
114  AFW_THROW_ERROR_Z(general, "Method not implemented.", xctx);
115 
116 }
117 
118 /*
119  * Implementation of method get_property for interface afw_object.
120  */
121 const afw_value_t *
122 impl_afw_object_get_property(
123  const afw_object_t *instance,
124  const afw_utf8_t *property_name,
125  afw_xctx_t *xctx)
126 {
129  const afw_object_t * *e;
130  const afw_object_t *o;
131  const afw_value_t *result;
132 
133  result = NULL;
134 
135  if (self->mutable) {
136  result = afw_object_get_property(self->mutable, property_name, xctx);
137  }
138 
139  if (!result) {
140  for (e = self->objects; e < self->end; e++) {
141  result = afw_object_get_property(*e, property_name, xctx);
142  if (result) {
143  if (afw_value_is_object(result) && !self->immutable) {
144  /*FIXME Need to include other objects with this property. */
146  true, self->pub.p, xctx,
147  ((const afw_value_object_t *)result)->internal, NULL);
148  result = afw_value_create_object(o, self->pub.p, xctx);
149  afw_object_set_property_as_object(self->mutable,
150  property_name, o, xctx);
151  }
152  break;
153  }
154  }
155  }
156 
157  return result;
158 }
159 
160 
161 typedef struct {
162  const afw_iterator_t *iterator;
163  afw_boolean_t on_delta;
165 
166 /*
167  * Implementation of method get_next_property for interface afw_object.
168  */
169 const afw_value_t *
170 impl_afw_object_get_next_property(
171  const afw_object_t *instance,
172  const afw_iterator_t **iterator,
173  const afw_utf8_t **property_name,
174  afw_xctx_t *xctx)
175 {
176  const afw_value_t *result;
177 
178  result = NULL;
179 
180  return result;
181 }
182 
183 /*
184  * Implementation of method has_property for interface afw_object.
185  */
187 impl_afw_object_has_property(
188  const afw_object_t *instance,
189  const afw_utf8_t *property_name,
190  afw_xctx_t *xctx)
191 {
192  afw_boolean_t result;
193 
194  result = impl_afw_object_get_property(instance, property_name, xctx)
195  != NULL;
196 
197  return result;
198 }
199 
200 /*
201  * Implementation of method get_setter for interface afw_object.
202  */
203 const afw_object_setter_t *
204 impl_afw_object_get_setter(
205  const afw_object_t *instance,
206  afw_xctx_t *xctx)
207 {
208  /* Don't allow setting directly to meta object. Use delta. */
209  return NULL;
210 }
AFW_DEFINE(const afw_object_t *)
Adaptive Framework Core Internal.
Interface afw_interface implementation declares.
#define afw_value_is_object(A_VALUE)
Macro to determine if value is evaluated object.
afw_object_set_property_as_object(const afw_object_t *object, const afw_utf8_t *property_name, const afw_object_t *internal, afw_xctx_t *xctx)
Set property function for data type object values.
afw_value_create_object(const afw_object_t *internal, const afw_pool_t *p, afw_xctx_t *xctx)
Create function for unmanaged data type object value.
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
afw_size_t impl_afw_object_get_count(const afw_object_t *instance, afw_xctx_t *xctx)
#define afw_object_get_property(instance, property_name, xctx)
Call method get_property of interface afw_object.
#define afw_object_create(p, xctx)
Create an empty unmanaged object in memory.
Definition: afw_object.h:948
afw_object_create_composite(afw_boolean_t mutable, const afw_pool_t *p, afw_xctx_t *xctx,...)
Create a composite of immutable objects.
#define afw_pool_calloc(instance, size, xctx)
Call method calloc of interface afw_pool.
#define afw_pool_calloc_type(instance, type, xctx)
Macro to allocate cleared memory to hold type in pool.
Definition: afw_pool.h:167
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
struct for data type object values.
Interface afw_value public struct.
Interface afw_xctx public struct.