Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_object_options.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive Framework Object Processing Options
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
14 #include "afw_internal.h"
15 
16 
17 /* Content type options - no options set. */
20 
21 /* Content type options - composite only. */
26 };
27 
28 /* Content type options - checkRequired + composite + normalize + defaults. */
30 afw_object_options_composite_normalize_defaults_required = {
35 };
36 
37 /* Content type options - composite only. */
43 };
44 
45 /* Content type options - include only essential (parentPaths) meta. */
49 };
50 
51 /*
52  * Content type options - include only essential (parentPaths) meta plus
53  * whitespace if available for content type.
54  */
59 };
60 
61 /* Object processing options needed for reconcilable. */
66 };
67 
68 /* Content type options - minimal + objectType. */
73 };
74 
75 /* Content type options - composite + parentPaths. */
81 };
82 
83 
84 /* Whitespace only */
88 };
89 
90 /* Set content type options from options object. */
93  const afw_object_options_t *initial_options,
94  const afw_object_t *options_object,
95  const afw_pool_t *p, afw_xctx_t *xctx)
96 {
97  const afw_iterator_t *iterator;
98  const afw_value_t *v;
99  const afw_utf8_t *name;
100  afw_object_options_t *options;
101 
102  /* Allocate options and initialize to initial options. */
103  options = afw_pool_calloc_type(p, afw_object_options_t, xctx);
104  if (initial_options) {
105  memcpy(options, initial_options, sizeof(afw_object_options_t));
106  }
107 
115  /* Handle other properties in any order. */
116  for (iterator = NULL; ;) {
117  v = afw_object_get_next_property(options_object, &iterator,
118  &name, xctx);
119  if (!v) break;
120 
125  /* checkRequired */
126  if (afw_utf8_equal(name, &afw_s_checkRequired)) {
127  AFW_OBJECT_OPTION_SET(options, checkRequired,
128  afw_value_as_boolean(v, xctx));
129  AFW_OBJECT_OPTION_SET(options, normalize,
130  afw_value_as_boolean(v, xctx));
131  }
132 
133  /* composite */
134  else if (afw_utf8_equal(name, &afw_s_composite)) {
135  AFW_OBJECT_OPTION_SET(options, composite,
136  afw_value_as_boolean(v, xctx));
137  }
138 
139  /* includeDefaultValues */
140  else if (afw_utf8_equal(name, &afw_s_includeDefaultValues)) {
141  AFW_OBJECT_OPTION_SET(options, includeDefaultValues,
142  afw_value_as_boolean(v, xctx));
143  AFW_OBJECT_OPTION_SET(options, normalize,
144  afw_value_as_boolean(v, xctx));
145  }
146 
147  /* includeDescendentObjectTypes */
148  else if (afw_utf8_equal(name, &afw_s_includeDescendentObjectTypes)) {
149  AFW_OBJECT_OPTION_SET(options, includeDescendentObjectTypes,
150  afw_value_as_boolean(v, xctx));
151  }
152 
153  /* inheritedFrom */
154  else if (afw_utf8_equal(name, &afw_s_inheritedFrom)) {
155  AFW_OBJECT_OPTION_SET(options, inheritedFrom,
156  afw_value_as_boolean(v, xctx));
157  }
158 
159  /* integersAsString */
160  else if (afw_utf8_equal(name, &afw_s_integersAsString)) {
161  AFW_OBJECT_OPTION_SET(options, integersAsString,
162  afw_value_as_boolean(v, xctx));
163  }
164 
165  /* largeIntegersAsString */
166  else if (afw_utf8_equal(name, &afw_s_largeIntegersAsString)) {
167  AFW_OBJECT_OPTION_SET(options, largeIntegersAsString,
168  afw_value_as_boolean(v, xctx));
169  }
170 
171  /* metaFull */
172  else if (afw_utf8_equal(name, &afw_s_metaFull)) {
173  AFW_OBJECT_OPTION_SET(options, metaFull,
174  afw_value_as_boolean(v, xctx));
175  if (AFW_OBJECT_OPTION_IS(options, metaFull)) {
176  AFW_OBJECT_OPTION_SET_OFF(options, metaLimited);
177  }
178  }
179 
180  /* metaLimited */
181  else if (afw_utf8_equal(name, &afw_s_metaLimited)) {
182  if (!AFW_OBJECT_OPTION_IS(options, metaFull)) {
183  AFW_OBJECT_OPTION_SET(options, metaLimited,
184  afw_value_as_boolean(v, xctx));
185  }
186  }
187 
188  /* normalize */
189  else if (afw_utf8_equal(name, &afw_s_normalize)) {
190  AFW_OBJECT_OPTION_SET(options, normalize,
191  afw_value_as_boolean(v, xctx));
192  }
193 
194  /* objectId */
195  else if (afw_utf8_equal(name, &afw_s_objectId)) {
196  AFW_OBJECT_OPTION_SET(options, objectId,
197  afw_value_as_boolean(v, xctx));
198  }
199 
200  /* objectType */
201  else if (afw_utf8_equal(name, &afw_s_objectType)) {
202  AFW_OBJECT_OPTION_SET(options, objectType,
203  afw_value_as_boolean(v, xctx));
204  }
205 
206  /* objectTypes */
207  else if (afw_utf8_equal(name, &afw_s_objectTypes)) {
208  AFW_OBJECT_OPTION_SET(options, objectTypes,
209  afw_value_as_boolean(v, xctx));
210  AFW_OBJECT_OPTION_SET(options, normalize,
211  afw_value_as_boolean(v, xctx));
212  }
213 
214  /* path */
215  else if (afw_utf8_equal(name, &afw_s_path)) {
216  AFW_OBJECT_OPTION_SET(options, path,
217  afw_value_as_boolean(v, xctx));
218  }
219 
220  /* pathEmbedded */
221  else if (afw_utf8_equal(name, &afw_s_pathEmbedded)) {
222  AFW_OBJECT_OPTION_SET(options, pathEmbedded,
223  afw_value_as_boolean(v, xctx));
224  }
225 
226  /* reconcilable */
227  else if (afw_utf8_equal(name, &afw_s_reconcilable)) {
228  AFW_OBJECT_OPTION_SET(options, reconcilable,
229  afw_value_as_boolean(v, xctx));
230  AFW_OBJECT_OPTION_SET(options, path,
231  afw_value_as_boolean(v, xctx));
232  AFW_OBJECT_OPTION_SET(options, inheritedFrom,
233  afw_value_as_boolean(v, xctx));
234  }
235 
236  /* resolvedParentPaths */
237  else if (afw_utf8_equal(name, &afw_s_resolvedParentPaths)) {
238  AFW_OBJECT_OPTION_SET(options, resolvedParentPaths,
239  afw_value_as_boolean(v, xctx));
240  }
241 
242  /* typedValues */
243  else if (afw_utf8_equal(name, &afw_s_typedValues)) {
244  AFW_OBJECT_OPTION_SET(options, typedValues,
245  afw_value_as_boolean(v, xctx));
246  }
247 
248  /* whitespace */
249  else if (afw_utf8_equal(name, &afw_s_whitespace)) {
250  AFW_OBJECT_OPTION_SET(options, whitespace,
251  afw_value_as_boolean(v, xctx));
252  }
253 
254  /* If not of above, it's an error. */
255  else {
256  AFW_THROW_ERROR_FZ(general, xctx,
257  "Invalid view option %" AFW_UTF8_FMT,
258  AFW_UTF8_FMT_ARG(name));
259  }
260  }
261 
262  /* Return result. */
263  return options;
264 }
265 
266 
267 
268 /* Create a options. */
271  const afw_object_options_t *initial_options,
272  const afw_object_options_t *options,
273  const afw_pool_t *p, afw_xctx_t *xctx)
274 {
275  afw_object_options_t *result;
276 
277  result = afw_memory_dup(options, sizeof(afw_object_options_t),
278  p, xctx);
279  if (initial_options) {
280  result->mask |= initial_options->mask;
281  }
282 
283  if (AFW_OBJECT_OPTION_IS(result, includeDefaultValues)) {
284  AFW_OBJECT_OPTION_SET_ON(result, normalize);
285  }
286 
287  return result;
288 }
AFW_DEFINE(const afw_object_t *)
#define AFW_DEFINE_CONST_DATA(type)
Define a public afw variable.
Adaptive Framework Core Internal.
afw_value_as_boolean(const afw_value_t *value, afw_xctx_t *xctx)
Typesafe cast of data type boolean.
#define AFW_UTF8_FMT_ARG(A_STRING)
Convenience Macro for use with AFW_UTF8_FMT to specify arg.
Definition: afw_common.h:605
struct afw_iterator_s afw_iterator_t
#define AFW_UTF8_FMT
Format string specifier used for afw_utf8_t.
Definition: afw_common.h:588
#define AFW_THROW_ERROR_FZ(code, xctx, format_z,...)
Macro used to set error and 0 rv in xctx and throw it.
Definition: afw_error.h:319
void * afw_memory_dup(const void *from, apr_size_t size, const afw_pool_t *p, afw_xctx_t *xctx)
Duplicate a block of memory into specified pool.
Definition: afw_memory.h:88
#define afw_object_get_next_property(instance, iterator, property_name, xctx)
Call method get_next_property of interface afw_object.
afw_object_options_essential_with_whitespace
Object processing options - metaLimited + whitespace.
#define AFW_OBJECT_OPTION_IS(_options, _option)
Test mask.
#define AFW_OBJECT_OPTION_whitespace
Indicates content type should include whitespace characters.
afw_object_options_composite_inheritedFrom_resolvedParentPaths
Object processing options - composite + inheritance related.
#define AFW_OBJECT_OPTION_checkRequired
Indicates that object should checked for missing required properties.
#define AFW_OBJECT_OPTION_inheritedFrom
Include inheritedFrom property for all inherited properties.
#define AFW_OBJECT_OPTION_includeDefaultValues
Indicates that object should include default property values.
#define AFW_OBJECT_OPTION_SET(_options, _option, _bool_value)
Set option.
#define AFW_OBJECT_OPTION_composite
Include all inherited properties.
#define AFW_OBJECT_OPTION_SET_ON(_options, _option)
Set option on.
afw_object_options_none
Object processing options - no options set.
afw_object_options_create(const afw_object_options_t *initial_options, const afw_object_options_t *options, const afw_pool_t *p, afw_xctx_t *xctx)
Create a options.
afw_object_options_essential
Object processing options - metaLimited.
afw_object_options_objectType
Object processing options - objectType.
#define AFW_OBJECT_OPTION_metaLimited
Include only requested meta.
afw_object_options_composite
Object processing options - composite only.
#define AFW_OBJECT_OPTION_resolvedParentPaths
Include meta resolvedParentPaths for all objects.
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.
#define AFW_OBJECT_OPTION_path
Include meta path for entity objects.
afw_object_options_whitespace
Whitespace only.
#define AFW_OBJECT_OPTION_normalize
Indicates that object should be normalized based on object type.
#define AFW_OBJECT_OPTION_objectType
Include meta objectType (object id of adaptive object type).
#define AFW_OBJECT_OPTION_SET_OFF(_options, _option)
Set option off.
afw_object_options_reconcilable_meta_property
Object processing options to produce reconcilable meta property.
afw_object_options_composite_and_defaults
Object processing options - composite only and defaults.
#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 object processing options.
Interface afw_object 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.