Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_function_logical.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 Logical
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
14 #include "afw_internal.h"
15 
16 
17 
18 /*
19  * Adaptive function: and
20  *
21  * afw_function_execute_and
22  *
23  * See afw_function_bindings.h for more information.
24  *
25  * Evaluates 0 or more boolean conditions returning boolean true if there are
26  * no conditions and boolean false if any condition evaluate to false. All
27  * conditions after the first false remain unevaluated.
28  *
29  * This function is pure, so it will always return the same result
30  * given exactly the same parameters and has no side effects.
31  *
32  * Declaration:
33  *
34  * ```
35  * function and(
36  * ...conditions: (list of boolean)
37  * ): boolean;
38  * ```
39  *
40  * Parameters:
41  *
42  * conditions - (0 or more boolean)
43  *
44  * Returns:
45  *
46  * (boolean)
47  */
48 const afw_value_t *
51 {
52  const afw_value_boolean_t *v;
53  afw_size_t n;
54 
55  /* Return false if any arg evaluates to false. */
56  for (n = 1; n <= x->argc; n++) {
58  if (!v->internal) {
59  return afw_value_false;
60  }
61  }
62 
63  /* Return true if no args evaluated to false. */
64  return afw_value_true;
65 }
66 
67 
68 
69 /*
70  * Adaptive function: n_of
71  *
72  * afw_function_execute_n_of
73  *
74  * See afw_function_bindings.h for more information.
75  *
76  * integer n specifies the number of boolean conditions that follow that must
77  * evaluate to true for boolean true to be returned. If n is 0, true is
78  * returned. Once n conditions evaluate to true, true is returned and the
79  * remaining conditions remain unevaluated.
80  *
81  * This function is pure, so it will always return the same result
82  * given exactly the same parameters and has no side effects.
83  *
84  * Declaration:
85  *
86  * ```
87  * function n_of(
88  * n: integer,
89  * ...conditions: (list of boolean)
90  * ): boolean;
91  * ```
92  *
93  * Parameters:
94  *
95  * n - (integer)
96  *
97  * conditions - (0 or more boolean)
98  *
99  * Returns:
100  *
101  * (boolean)
102  *
103  * Errors thrown:
104  *
105  * arg_error - there are less than n conditions
106  */
107 const afw_value_t *
110 {
111  const afw_value_integer_t *n;
112  const afw_value_boolean_t *v;
113  afw_size_t i;
114  afw_integer_t trues;
115 
117 
118  /* Evaluated args until end or there are enough trues. */
119  for (i = 2, trues = 0; i <= x->argc &&
120  trues < n->internal; i++)
121  {
123  if (v->internal) {
124  trues++;
125  }
126  }
127 
128  /* Return true if there were enough trues. */
129  return (trues >= n->internal)
131  : afw_value_false;
132 }
133 
134 
135 
136 /*
137  * Adaptive function: not
138  *
139  * afw_function_execute_not
140  *
141  * See afw_function_bindings.h for more information.
142  *
143  * Evaluates boolean condition returning boolean true if condition evaluates to
144  * false and false if condition evaluates to true.
145  *
146  * This function is pure, so it will always return the same result
147  * given exactly the same parameters and has no side effects.
148  *
149  * Declaration:
150  *
151  * ```
152  * function not(
153  * condition: boolean
154  * ): boolean;
155  * ```
156  *
157  * Parameters:
158  *
159  * condition - (boolean)
160  *
161  * Returns:
162  *
163  * (boolean)
164  */
165 const afw_value_t *
168 {
169  const afw_value_boolean_t *condition;
170 
172 
173  return (condition->internal)
175  : afw_value_true;
176 }
177 
178 
179 
180 /*
181  * Adaptive function: or
182  *
183  * afw_function_execute_or
184  *
185  * See afw_function_bindings.h for more information.
186  *
187  * Evaluates 0 or more boolean conditions returning boolean false if there are
188  * no conditions and boolean true if any condition evaluate to true. All
189  * conditions after the first true remain unevaluated.
190  *
191  * This function is pure, so it will always return the same result
192  * given exactly the same parameters and has no side effects.
193  *
194  * Declaration:
195  *
196  * ```
197  * function or(
198  * ...conditions: (list of boolean)
199  * ): boolean;
200  * ```
201  *
202  * Parameters:
203  *
204  * conditions - (0 or more boolean)
205  *
206  * Returns:
207  *
208  * (boolean)
209  */
210 const afw_value_t *
213 {
214  const afw_value_boolean_t *v;
215  afw_size_t n;
216 
217  /* Return true if any arg evaluates to true. */
218  for (n = 1; n <= x->argc; n++) {
220  if (v->internal) {
221  return afw_value_true;
222  }
223  }
224 
225  /* Return false if no args evaluated to true. */
226  return afw_value_false;
227 }
Adaptive Framework Core Internal.
apr_size_t afw_size_t
size_t.
Definition: afw_common.h:151
apr_int64_t afw_integer_t
typedef for big signed int.
Definition: afw_common.h:321
#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
const afw_value_t * afw_function_execute_n_of(afw_function_execute_t *x)
Adaptive Function n_of
const afw_value_t * afw_function_execute_not(afw_function_execute_t *x)
Adaptive Function not
const afw_value_t * afw_function_execute_or(afw_function_execute_t *x)
Adaptive Function or
const afw_value_t * afw_function_execute_and(afw_function_execute_t *x)
Adaptive Function and
afw_value_false
Adaptive value false.
Definition: afw_value.h:354
afw_value_true
Adaptive value true.
Definition: afw_value.h:348
Function execute parameter.
Definition: afw_function.h:53
afw_size_t argc
This is the argv count not counting argv[0].
Definition: afw_function.h:89
struct for data type boolean values.
struct for data type integer values.
Interface afw_value public struct.