Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_function_object.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * afw_function_execute_* functions for object
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
14 #include "afw_internal.h"
15 
16 
17 
18 /*
19  * Adaptive function: add_properties
20  *
21  * afw_function_execute_add_properties
22  *
23  * See afw_function_bindings.h for more information.
24  *
25  * Add the properties of one object to another replacing existing properties by
26  * the same name.
27  *
28  * This function is not pure, so it may return a different result
29  * given exactly the same parameters and has side effects.
30  *
31  * Declaration:
32  *
33  * ```
34  * function add_properties(
35  * target: object,
36  * source_1: object,
37  * ...source_rest: (list of object)
38  * ): object;
39  * ```
40  *
41  * Parameters:
42  *
43  * target - (object) Target object. This object must not be immutable.
44  *
45  * source - (1 or more object) Source object(s).
46  *
47  * Returns:
48  *
49  * (object) The modified target object.
50  */
51 const afw_value_t *
54 {
55  const afw_value_object_t *target;
56  const afw_value_object_t *source;
57  const afw_iterator_t *iterator;
58  const afw_utf8_t *property_name;
59  const afw_value_t *value;
60  afw_size_t count;
61 
63 
64  for (count = 2; count <= x->argc; count++)
65  {
67  source, count, object);
68  for (iterator = NULL;;) {
70  source->internal, &iterator, &property_name, x->xctx);
71  if (!value) break;
72  afw_object_set_property(target->internal,
73  property_name, value, x->xctx);
74  }
75  }
76 
77  return (const afw_value_t *)target;
78 }
79 
80 
81 
82 /*
83  * Adaptive function: apply_object_options
84  *
85  * afw_function_execute_apply_object_options
86  *
87  * See afw_function_bindings.h for more information.
88  *
89  * This will return an object with the specified object options applied.
90  *
91  * This function is not pure, so it may return a different result
92  * given exactly the same parameters.
93  *
94  * Declaration:
95  *
96  * ```
97  * function apply_object_options(
98  * object: object,
99  * options?: (object _AdaptiveObjectOptions_)
100  * ): object;
101  * ```
102  *
103  * Parameters:
104  *
105  * object - (object) Object used to produce result.
106  *
107  * options - (optional object _AdaptiveObjectOptions_) Object options. See
108  * /afw/_AdaptiveObjectType_/_AdaptiveObjectOptions_ for more
109  * information.
110  *
111  * Returns:
112  *
113  * (object) This is an object with object options applied.
114  */
115 const afw_value_t *
118 {
119  const afw_value_object_t *object;
120  const afw_value_object_t *options_object;
121  const afw_object_options_t *options;
122  const afw_object_t *result;
123 
125  AFW_FUNCTION_EVALUATE_REQUIRED_DATA_TYPE_PARAMETER(options_object, 2, object);
126 
127  options = afw_object_options_set_from_object(NULL,
128  options_object->internal, x->p, x->xctx);
129 
130  result = afw_object_view_create(object->internal,
131  NULL, options, x->p, x->xctx);
132 
133  return afw_value_create_object(result, x->p, x->xctx);
134 }
135 
136 
137 
138 /*
139  * Adaptive function: local_object_meta_set_ids
140  *
141  * afw_function_execute_local_object_meta_set_ids
142  *
143  * See afw_function_bindings.h for more information.
144  *
145  * This is used to set the ids in a local mutable object. The ids are used to
146  * construct a local path.
147  *
148  * This function is not pure, so it may return a different result
149  * given exactly the same parameters and has side effects.
150  *
151  * Declaration:
152  *
153  * ```
154  * function local_object_meta_set_ids(
155  * object: object,
156  * adaptorId: string,
157  * objectType: string,
158  * objectId: string
159  * ): null;
160  * ```
161  *
162  * Parameters:
163  *
164  * object - (object) Object to set ids in.
165  *
166  * adaptorId - (string) Adaptor id for object.
167  *
168  * objectType - (string) Object type id for object.
169  *
170  * objectId - (string) Object id for object.
171  *
172  * Returns:
173  *
174  * (null)
175  */
176 const afw_value_t *
179 {
180  const afw_value_object_t *object;
181  const afw_value_string_t *adaptorId;
182  const afw_value_string_t *objectType;
183  const afw_value_string_t *objectId;
184 
189 
190  afw_object_meta_set_ids(object->internal,
191  &adaptorId->internal, &objectType->internal, &objectId->internal,
192  x->xctx);
193 
194  return afw_value_null;
195 }
196 
197 
198 
199 /*
200  * Adaptive function: property_exists
201  *
202  * afw_function_execute_property_exists
203  *
204  * See afw_function_bindings.h for more information.
205  *
206  * Return true if the named property exists in an object.
207  *
208  * This function is not pure, so it may return a different result
209  * given exactly the same parameters.
210  *
211  * Declaration:
212  *
213  * ```
214  * function property_exists(
215  * object: object,
216  * name: string
217  * ): boolean;
218  * ```
219  *
220  * Parameters:
221  *
222  * object - (object) Object to get property from.
223  *
224  * name - (string) Name of property to check.
225  *
226  * Returns:
227  *
228  * (boolean) True if object has named property.
229  */
230 const afw_value_t *
233 {
234  const afw_value_object_t *object;
235  const afw_value_string_t *name;
236  afw_boolean_t has;
237 
240 
241  has = afw_object_has_property(object->internal, &name->internal, x->xctx);
242 
243  return (has) ? afw_value_true : afw_value_false;
244 }
245 
246 
247 
248 /*
249  * Adaptive function: property_get
250  *
251  * afw_function_execute_property_get
252  *
253  * See afw_function_bindings.h for more information.
254  *
255  * Return the value of a property of an object. If property is not available,
256  * return a default or null value.
257  *
258  * This function is not pure, so it may return a different result
259  * given exactly the same parameters.
260  *
261  * Declaration:
262  *
263  * ```
264  * function property_get(
265  * object: object,
266  * name: string,
267  * defaultValue?: any
268  * ): any;
269  * ```
270  *
271  * Parameters:
272  *
273  * object - (object) Object to get property from.
274  *
275  * name - (string) Name of property to get.
276  *
277  * defaultValue - (optional any dataType) The default value of property if it
278  * does not exist in object. If not specified, null value is the default.
279  *
280  * Returns:
281  *
282  * (any dataType) Evaluated property value or default.
283  */
284 const afw_value_t *
287 {
288  const afw_value_object_t *object;
289  const afw_value_string_t *name;
290  const afw_value_t *the_default; /* Can be null. */
291  const afw_value_t *result;
292 
295 
296  the_default = afw_value_null;
298  the_default = afw_value_evaluate(x->argv[3], x->p, x->xctx);
299  }
300 
301  result = afw_object_get_property(object->internal,
302  &name->internal, x->xctx);
303  if (!result) {
304  result = the_default;
305  }
306 
307  return afw_value_evaluate(result, x->p, x->xctx);
308 }
309 
310 
311 
312 /*
313  * Adaptive function: property_is_not_null
314  *
315  * afw_function_execute_property_is_not_null
316  *
317  * See afw_function_bindings.h for more information.
318  *
319  * Return true if the named property exists in an object and is not null.
320  *
321  * This function is not pure, so it may return a different result
322  * given exactly the same parameters.
323  *
324  * Declaration:
325  *
326  * ```
327  * function property_is_not_null(
328  * object: object,
329  * name: string
330  * ): boolean;
331  * ```
332  *
333  * Parameters:
334  *
335  * object - (object) Object to get property from.
336  *
337  * name - (string) Name of property to check.
338  *
339  * Returns:
340  *
341  * (boolean) True if object has named property that is not null.
342  */
343 const afw_value_t *
346 {
347  const afw_value_object_t *object;
348  const afw_value_string_t *name;
349  const afw_value_t *value;
350 
353 
354  value = afw_object_get_property(object->internal, &name->internal,
355  x->xctx);
356 
357  return (value && !afw_value_is_null(value))
359  : afw_value_false;
360 }
Adaptive Framework Core Internal.
#define afw_value_is_null(A_VALUE)
Macro to determine if value is evaluated null.
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_FUNCTION_EVALUATE_REQUIRED_DATA_TYPE_PARAMETER(A_RESULT, A_N, A_TYPE)
Evaluate an arg for a particular data type.
Definition: afw_function.h:328
#define AFW_FUNCTION_PARAMETER_IS_PRESENT(A_N)
Determine if a specific parameter value is present.
Definition: afw_function.h:242
const afw_value_t * afw_function_execute_local_object_meta_set_ids(afw_function_execute_t *x)
Adaptive Function local_object_meta_set_ids
const afw_value_t * afw_function_execute_property_exists(afw_function_execute_t *x)
Adaptive Function property_exists
const afw_value_t * afw_function_execute_property_is_not_null(afw_function_execute_t *x)
Adaptive Function property_is_not_null
const afw_value_t * afw_function_execute_apply_object_options(afw_function_execute_t *x)
Adaptive Function apply_object_options
const afw_value_t * afw_function_execute_add_properties(afw_function_execute_t *x)
Adaptive Function add_properties
const afw_value_t * afw_function_execute_property_get(afw_function_execute_t *x)
Adaptive Function property_get
#define afw_object_get_property(instance, property_name, xctx)
Call method get_property of interface afw_object.
#define afw_object_get_next_property(instance, iterator, property_name, xctx)
Call method get_next_property of interface afw_object.
#define afw_object_has_property(instance, property_name, xctx)
Call method has_property of interface afw_object.
afw_object_meta_set_ids(const afw_object_t *instance, const afw_utf8_t *adaptor_id, const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, afw_xctx_t *xctx)
Set object's ids.
afw_object_options_set_from_object(const afw_object_options_t *initial_options, const afw_object_t *options_object, const afw_pool_t *p, afw_xctx_t *xctx)
Set object processing options from options object.
afw_object_view_create(const afw_object_t *instance, const afw_utf8_t *entity_path, const afw_object_options_t *options, const afw_pool_t *p, afw_xctx_t *xctx)
Create an object view of an object in specified pool.
afw_object_set_property(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_value_t *value, afw_xctx_t *xctx)
Set the value of an object's property.
Definition: afw_object.c:46
#define afw_value_evaluate(value, p, xctx)
Evaluate value if needed using specific pool.
Definition: afw_value.h:841
afw_value_false
Adaptive value false.
Definition: afw_value.h:354
afw_value_null
Adaptive value null.
Definition: afw_value.h:320
afw_value_true
Adaptive value true.
Definition: afw_value.h:348
Function execute parameter.
Definition: afw_function.h:53
const afw_value_t *const * argv
This is the function parameters.
Definition: afw_function.h:86
afw_xctx_t * xctx
The execution context (xctx) of caller.
Definition: afw_function.h:62
const afw_pool_t * p
Pool for result.
Definition: afw_function.h:59
afw_size_t argc
This is the argv count not counting argv[0].
Definition: afw_function.h:89
Struct for object processing options.
Interface afw_object public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
struct for data type object values.
Interface afw_value public struct.
struct for data type string values.