Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_function.h
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive Framework Basic Function Support.
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
9 #ifndef __AFW_FUNCTION_H__
10 #define __AFW_FUNCTION_H__
11 
12 #include "afw_interface.h"
13 
28 
44 #define AFW_FUNCTION_EXECUTE_STANDARD_POLYMORPHIC_FUNCTION_HANDLING NULL
45 
46 
54 
57 
59  const afw_pool_t *p;
60 
63 
72 
75 
78 
86  const afw_value_t * const * argv;
87 
90 
91 };
92 
93 
94 
96 
99 
102 
105 
108 
111 
114 
117 
120 
123 
126 
129 
132 
135 
138 
141 
144 };
145 
146 
147 
159 #define AFW_FUNCTION_ARGV(A_N) \
160 ((A_N <= x->argc) ? x->argv[A_N] : NULL)
161 
162 
163 
172 #define AFW_FUNCTION_ASSERT_PARAMETER_COUNT_IS(n) \
173 do { \
174  if ((x->argc) != (n)) {\
175  AFW_THROW_ERROR_Z(general, "Expecting " #n " parameters.", x->xctx);\
176  } \
177 } while (0)
178 
179 
180 
189 #define AFW_FUNCTION_ASSERT_PARAMETER_COUNT_MIN(n) \
190 do { \
191  if (x->argc < (n)) {\
192  AFW_THROW_ERROR_Z(general, "Expecting at least " #n " parameters.", x->xctx);\
193  } \
194 } while (0)
195 
196 
197 
206 #define AFW_FUNCTION_ASSERT_PARAMETER_COUNT_MAX(n) \
207 do { \
208  if (x->argc > (n)) {\
209  AFW_THROW_ERROR_Z(general, "Expecting no more than " #n " parameters.", x->xctx);\
210  } \
211 } while (0)
212 
213 
214 
223 #define AFW_FUNCTION_ASSERT_VALUE_IS_UTF8(A_VALUE) \
224 if (!(A_VALUE) || !afw_utf8_equal( \
225  &afw_value_get_data_type(((const afw_value_t *)A_VALUE), x->xctx)->cType, \
226  &afw_s_afw_utf8_t)) \
227 { \
228  AFW_THROW_ERROR_Z(arg_error, \
229  "Value's data type not supported for this function", x->xctx); \
230 }
231 
232 
233 
242 #define AFW_FUNCTION_PARAMETER_IS_PRESENT(A_N) \
243  (AFW_FUNCTION_ARGV(A_N) != NULL)
244 
245 
246 
261 #define AFW_FUNCTION_EVALUATE_DATA_TYPE_PARAMETER(A_RESULT, A_N, A_TYPE) \
262 A_RESULT = (const afw_value_##A_TYPE##_t *) \
263  afw_function_evaluate_parameter(x, A_N, afw_data_type_##A_TYPE)
264 
265 
266 
279 #define AFW_FUNCTION_EVALUATE_PARAMETER(A_RESULT, A_N) \
280 A_RESULT = afw_function_evaluate_parameter(x, A_N, NULL)
281 
282 
283 
295 #define AFW_FUNCTION_EVALUATE_REQUIRED_PARAMETER(A_RESULT, A_N) \
296 A_RESULT = afw_function_evaluate_required_parameter(x, A_N, NULL);
297 
298 
299 
309 #define AFW_FUNCTION_EVALUATE_REQUIRED_CONDITION_PARAMETER(A_RESULT, A_N) \
310 A_RESULT = (const afw_value_boolean_t *) \
311  afw_function_evaluate_required_parameter(x, A_N, NULL); \
312  if (!afw_value_is_boolean(A_RESULT)) \
313  AFW_THROW_ERROR_FZ(arg_error, xctx, \
314  "Condition must be boolean (parameter %d)", (A_N))
315 
316 
317 
328 #define AFW_FUNCTION_EVALUATE_REQUIRED_DATA_TYPE_PARAMETER(A_RESULT, A_N, A_TYPE) \
329 A_RESULT = (const afw_value_##A_TYPE##_t *) \
330  afw_function_evaluate_required_parameter(x, A_N, afw_data_type_##A_TYPE)
331 
332 
333 
341 #define AFW_FUNCTION_SOURCE_LOCATION \
342 afw_compile_source_location_of_value( \
343  (const afw_value_t *)x->self, x->p, x->xctx)
344 
345 
346 
347 /*
348  * @brief Evaluate function parameter.
349  * @param function_arg.
350  * @param p Pool to use for result.
351  * @param xctx of caller.
352  * @return function.
353  */
354 AFW_DECLARE(const afw_value_t *)
355 afw_function_evaluate_function_parameter(
356  const afw_value_t *function_arg,
357  const afw_pool_t *p,
358  afw_xctx_t *xctx);
359 
360 
361 
362 /*
363  * @brief Execute whitespace parameter.
364  * @param x function execute struct pointer.
365  * @param n of whitespace parameter in argv.
366  * @return a string containing whitespace to use.
367  *
368  * This parameter can be an integer between 0 and 10 or a string that is used
369  * for indentation. If 0 is specified, no whitespace is added to the resulting
370  * string. If 1 through 10 is specified, that number of spaces is returned.
371  */
372 AFW_DECLARE(const afw_utf8_t *)
373 afw_function_evaluate_whitespace_parameter(
375  afw_size_t n);
376 
377 
393 AFW_DECLARE(const afw_value_t *)
396  afw_size_t parameter_number,
397  const afw_data_type_t *data_type);
398 
399 
400 
414 AFW_DEFINE(const afw_value_t *)
417  afw_size_t parameter_number,
418  const afw_data_type_t *data_type);
419 
420 
421 
434 AFW_DECLARE(const afw_value_t *)
436  const afw_value_t *value,
437  afw_size_t parameter_number,
438  const afw_value_type_t *type,
439  const afw_pool_t *p, afw_xctx_t *xctx);
440 
441 
442 
443 AFW_END_DECLARES
444 
447 #endif /* __AFW_FUNCTION_H__ */
AFW_DEFINE(const afw_object_t *)
#define AFW_BEGIN_DECLARES
#define AFW_DECLARE(type)
Declare a public afw function.
Interfaceafw_interface header.
apr_size_t afw_size_t
size_t.
Definition: afw_common.h:151
afw_function_evaluate_required_parameter(afw_function_execute_t *x, afw_size_t parameter_number, const afw_data_type_t *data_type)
Evaluate an required parameter and convert if necessary.
Definition: afw_function.c:213
const afw_value_t * afw_function_evaluate_parameter_with_type(const afw_value_t *value, afw_size_t parameter_number, const afw_value_type_t *type, const afw_pool_t *p, afw_xctx_t *xctx)
Evaluate a parameter with dataTypeParameter.
Definition: afw_function.c:243
const afw_value_t * afw_function_evaluate_parameter(afw_function_execute_t *x, afw_size_t parameter_number, const afw_data_type_t *data_type)
Evaluate a parameter and convert if necessary.
Definition: afw_function.c:129
Interface afw_data_type public struct.
const afw_value_function_definition_t * divide_operator_function
Divide operator function.
Definition: afw_function.h:107
const afw_value_function_definition_t * or_operator_function
Or operator function.
Definition: afw_function.h:122
const afw_value_function_definition_t * less_than_or_equal_to_function
Less than or equal to operator function.
Definition: afw_function.h:137
const afw_value_function_definition_t * modulus_operator_function
Modulus operator function.
Definition: afw_function.h:110
const afw_value_function_definition_t * multiply_operator_function
Multiply operator function.
Definition: afw_function.h:104
const afw_value_function_definition_t * add_operator_function
Add operator function.
Definition: afw_function.h:98
const afw_value_function_definition_t * unary_not_operator_function
Not operator function.
Definition: afw_function.h:125
const afw_value_function_definition_t * exponentiation_operator_function
Exponentiation operator function.
Definition: afw_function.h:113
const afw_value_function_definition_t * subtract_operator_function
Subtract operator function.
Definition: afw_function.h:101
const afw_value_function_definition_t * less_than_operator_function
Less than operator function.
Definition: afw_function.h:134
const afw_value_function_definition_t * negative_operator_function
Negative operator function.
Definition: afw_function.h:116
const afw_value_function_definition_t * not_equal_to_operator_function
Not equal to operator function.
Definition: afw_function.h:131
const afw_value_function_definition_t * and_operator_function
And operator function.
Definition: afw_function.h:119
const afw_value_function_definition_t * greater_than_operator_function
Greater than operator function.
Definition: afw_function.h:140
const afw_value_function_definition_t * greater_than_or_equal_to_function
Greater than or equal to operator function.
Definition: afw_function.h:143
const afw_value_function_definition_t * equal_to_operator_function
Equal to operator function.
Definition: afw_function.h:128
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
const afw_data_type_t * data_type
This is the <dataType> for data type functions or NULL.
Definition: afw_function.h:74
afw_size_t argc
This is the argv count not counting argv[0].
Definition: afw_function.h:89
const afw_value_t * first_arg
This is the evaluated first parameter if data type function.
Definition: afw_function.h:77
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Struct for function value.
Definition: afw_value.h:102
Interface afw_value public struct.
Type meta (data type, data type parameters, and value meta object.
Interface afw_xctx public struct.