All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
as_list.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2014 Aerospike, Inc.
3  *
4  * Portions may be licensed to Aerospike, Inc. under one or more contributor
5  * license agreements.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8  * use this file except in compliance with the License. You may obtain a copy of
9  * the License at http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14  * License for the specific language governing permissions and limitations under
15  * the License.
16  */
17 
18 #pragma once
19 
20 #include <aerospike/as_bytes.h>
21 #include <aerospike/as_integer.h>
22 #include <aerospike/as_iterator.h>
23 #include <aerospike/as_string.h>
24 #include <aerospike/as_util.h>
25 #include <aerospike/as_val.h>
26 
27 #include <stdbool.h>
28 #include <stdint.h>
29 
30 /******************************************************************************
31  * TYPES
32  *****************************************************************************/
33 
34 union as_list_iterator_u;
35 
36 struct as_list_hooks_s;
37 
38 /**
39  * Callback function for `as_list_foreach()`. Called for each element in the
40  * list.
41  *
42  * @param value The value of the current element.
43  * @param udata The user-data provided to the `as_list_foreach()`.
44  *
45  * @return true to continue iterating through the list.
46  * false to stop iterating.
47  */
48 typedef bool (* as_list_foreach_callback) (as_val * value, void * udata);
49 
50 /**
51  * as_list is an interface for List based data types.
52  *
53  * Implementations:
54  * - as_arraylist
55  *
56  * @extends as_val
57  * @ingroup aerospike_t
58  */
59 typedef struct as_list_s {
60 
61  /**
62  * @private
63  * as_list is a subtype of as_val.
64  * You can cast as_list to as_val.
65  */
67 
68  /**
69  * Pointer to the data for this list.
70  */
71  void * data;
72 
73  /**
74  * Hooks for subtypes of as_list to implement.
75  */
76  const struct as_list_hooks_s * hooks;
77 
78 } as_list;
79 
80 /**
81  * List Function Hooks
82  */
83 typedef struct as_list_hooks_s {
84 
85  /***************************************************************************
86  * instance hooks
87  **************************************************************************/
88 
89  /**
90  * Releases the subtype of as_list.
91  *
92  * @param map The map instance to destroy.
93  *
94  * @return true on success. Otherwise false.
95  */
96  bool (* destroy)(as_list * list);
97 
98  /***************************************************************************
99  * info hooks
100  **************************************************************************/
101 
102  /**
103  * The hash value of an as_list.
104  *
105  * @param list The list to get the hashcode value for.
106  *
107  * @return The hashcode value.
108  */
109  uint32_t (* hashcode)(const as_list * list);
110 
111  /**
112  * The size of the as_list.
113  *
114  * @param map The map to get the size of.
115  *
116  * @return The number of entries in the map.
117  */
118  uint32_t (* size)(const as_list * list);
119 
120  /***************************************************************************
121  * get hooks
122  **************************************************************************/
123 
124  /**
125  * Get the value at a given index of the list.
126  *
127  * @param list The list to get the value from.
128  * @param index The index of the value.
129  *
130  * @return The value at the given index on success. Otherwie NULL.
131  */
132  as_val * (* get)(const as_list * list, const uint32_t index);
133 
134  /**
135  * Get the int64_t value at a given index of the list.
136  *
137  * @param list The list to get the value from.
138  * @param index The index of the value.
139  *
140  * @return The value at the given index on success. Otherwie NULL.
141  */
142  int64_t (* get_int64)(const as_list * list, const uint32_t index);
143 
144  /**
145  * Get the NULL-terminated string value at a given index of the list.
146  *
147  * @param list The list to get the value from.
148  * @param index The index of the value.
149  *
150  * @return The value at the given index on success. Otherwie NULL.
151  */
152  char * (* get_str)(const as_list * list, const uint32_t index);
153 
154  /***************************************************************************
155  * set hooks
156  **************************************************************************/
157 
158  /**
159  * Set a value at the given index of the list.
160  *
161  * @param list The list to get the value from.
162  * @param index The index of the value.
163  * @param value The value for the given index.
164  *
165  * @return The value at the given index on success. Otherwie NULL.
166  */
167  int (* set)(as_list * list, const uint32_t index, as_val * value);
168 
169  /**
170  * Set an int64_t value at the given index of the list.
171  *
172  * @param list The list to get the value from.
173  * @param index The index of the value.
174  * @param value The value for the given index.
175  *
176  * @return The value at the given index on success. Otherwie NULL.
177  */
178  int (* set_int64)(as_list * list, const uint32_t index, int64_t value);
179 
180  /**
181  * Set a NULL-terminated string value at the given index of the list.
182  *
183  * @param list The list to get the value from.
184  * @param index The index of the value.
185  * @param value The value for the given index.
186  *
187  * @return The value at the given index on success. Otherwie NULL.
188  */
189  int (* set_str)(as_list * list, const uint32_t index, const char * value);
190 
191  /***************************************************************************
192  * append hooks
193  **************************************************************************/
194 
195  /**
196  * Append a value to the list.
197  *
198  * @param list The list to append to.
199  * @param value The value to append to the list.
200  *
201  * @return 0 on success. Otherwise an error occurred.
202  */
203  int (* append)(as_list * list, as_val * value);
204 
205  /**
206  * Append an int64_t value to the list.
207  *
208  * @param list The list to append to.
209  * @param value The value to append to the list.
210  *
211  * @return 0 on success. Otherwise an error occurred.
212  */
213  int (* append_int64)(as_list * list, int64_t value);
214 
215  /**
216  * Append a NULL-terminates string value to the list.
217  *
218  * @param list The list to append to.
219  * @param value The value to append to the list.
220  *
221  * @return 0 on success. Otherwise an error occurred.
222  */
223  int (* append_str)(as_list * list, const char * value);
224 
225  /***************************************************************************
226  * prepend hooks
227  **************************************************************************/
228 
229  /**
230  * Prepend the value to the list.
231  *
232  * @param list The list to prepend to.
233  * @param value The value to prepend to the list.
234  *
235  * @return 0 on success. Otherwise an error occurred.
236  */
237  int (* prepend)(as_list * list, as_val * value);
238 
239  /**
240  * Prepend an int64_t value to the list.
241  *
242  * @param list The list to prepend to.
243  * @param value The value to prepend to the list.
244  *
245  * @return 0 on success. Otherwise an error occurred.
246  */
247  int (* prepend_int64)(as_list * list, int64_t value);
248 
249  /**
250  * Prepend a NULL-terminates string value to the list.
251  *
252  * @param list The list to prepend to.
253  * @param value The value to prepend to the list.
254  *
255  * @return 0 on success. Otherwise an error occurred.
256  */
257  int (* prepend_str)(as_list * list, const char * value);
258 
259 
260  /***************************************************************************
261  * accessor and modifier hooks
262  **************************************************************************/
263 
264  /**
265  * Return the first element in the list.
266  *
267  * @param list The list to get the value from.
268  *
269  * @return The first value in the list. Otherwise NULL.
270  */
271  as_val * (* head)(const as_list * list);
272 
273  /**
274  * Return all but the first element of the list, returning a new list.
275  *
276  * @param list The list to get the list from.
277  *
278  * @return The tail of the list. Otherwise NULL.
279  */
280  as_list * (* tail)(const as_list * list);
281 
282  /**
283  * Drop the first n element of the list, returning a new list.
284  *
285  * @param list The list.
286  * @param n The number of element to drop.
287  *
288  * @return A new list containing the remaining elements. Otherwise NULL.
289  */
290  as_list * (* drop)(const as_list * list, uint32_t n);
291 
292  /**
293  * Take the first n element of the list, returning a new list.
294  *
295  * @param list The list.
296  * @param n The number of element to take.
297  *
298  * @return A new list containing the remaining elements. Otherwise NULL.
299  */
300  as_list * (* take)(const as_list * list, uint32_t n);
301 
302  /***************************************************************************
303  * iteration hooks
304  **************************************************************************/
305 
306  /**
307  * Iterate over each element in the list can call the callback function.
308  *
309  * @param map The map to iterate.
310  * @param callback The function to call for each element in the list.
311  * @param udata User-data to be passed to the callback.
312  *
313  * @return true on success. Otherwise false.
314  */
315  bool (* foreach)(const as_list * list, as_list_foreach_callback callback, void * udata);
316 
317  /**
318  * Create and initialize a new heap allocated iterator to traverse over the list.
319  *
320  * @param list The list to iterate.
321  *
322  * @return true on success. Otherwise false.
323  */
324  union as_list_iterator_u * (* iterator_new)(const as_list * list);
325 
326  /**
327  * Initializes a stack allocated iterator to traverse over the list.
328  *
329  * @param list The list to iterate.
330  *
331  * @return true on success. Otherwise false.
332  */
333  union as_list_iterator_u * (* iterator_init)(const as_list * list, union as_list_iterator_u * it);
334 
335 } as_list_hooks;
336 
337 /*******************************************************************************
338  * INSTANCE FUNCTIONS
339  ******************************************************************************/
340 
341 /**
342  * @private
343  * Utilized by subtypes of as_list to initialize the parent.
344  *
345  * @param list The list to initialize.
346  * @param free If true, then as_list_destroy() will free the list.
347  * @param data Data for the list.
348  * @param hooks Implementaton for the list interface.
349  *
350  * @return On success, the initialized list. Otherwise NULL.
351  * @relatesalso as_list
352  */
353 as_list * as_list_cons(as_list * list, bool free, void * data, const as_list_hooks * hooks);
354 
355 /**
356  * Initialize a stack allocated list.
357  *
358  * @param list Stack allocated list to initialize.
359  * @param data Data for the list.
360  * @param hooks Implementaton for the list interface.
361  *
362  * @return On succes, the initialized list. Otherwise NULL.
363  * @relatesalso as_list
364  */
365 as_list * as_list_init(as_list * list, void * data, const as_list_hooks * hooks);
366 
367 /**
368  * Create and initialize a new heap allocated list.
369  *
370  * @param data Data for the list.
371  * @param hooks Implementaton for the list interface.
372  *
373  * @return On succes, a new list. Otherwise NULL.
374  * @relatesalso as_list
375  */
376 as_list * as_list_new(void * data, const as_list_hooks * hooks);
377 
378 /**
379  * Destroy the list and associated resources.
380  *
381  * @param list The list to destroy.
382  * @relatesalso as_list
383  */
384 static inline void as_list_destroy(as_list * list)
385 {
386  as_val_destroy((as_val *) list);
387 }
388 
389 /******************************************************************************
390  * INFO FUNCTIONS
391  *****************************************************************************/
392 
393 /**
394  * Get the hashcode value for the list.
395  *
396  * @param list The list.
397  *
398  * @return The hashcode of the list.
399  * @relatesalso as_list
400  */
401 static inline uint32_t as_list_hashcode(as_list * list)
402 {
403  return as_util_hook(hashcode, 0, list);
404 }
405 
406 /**
407  * Number of elements in the list.
408  *
409  * @param list The list.
410  *
411  * @return The size of the list.
412  * @relatesalso as_list
413  */
414 static inline uint32_t as_list_size(as_list * list)
415 {
416  return as_util_hook(size, 0, list);
417 }
418 
419 /******************************************************************************
420  * ACCESSOR AND MODIFIER FUNCTIONS
421  *****************************************************************************/
422 
423 /**
424  * The first element in the list.
425  *
426  * @param list The list to get the head value from.
427  *
428  * @return The first value of the list on success. Otherwise NULL.
429  * @relatesalso as_list
430  */
431 static inline as_val * as_list_head(const as_list * list)
432 {
433  return as_util_hook(head, NULL, list);
434 }
435 
436 /**
437  * All elements after the first element in the list.
438  *
439  * @param list The list to get the tail from.
440  *
441  * @return On success, the tail of the list. Otherwise NULL.
442  * @relatesalso as_list
443  */
444 static inline as_list * as_list_tail(const as_list * list)
445 {
446  return as_util_hook(tail, NULL, list);
447 }
448 
449 /**
450  * Create a new list containing all elements, except the first n elements, of the list.
451  *
452  * @param list The list to drop elements from.
453  * @param n The number of elements to drop.
454  *
455  * @return On success, a new list containing the remaining elements. Otherwise NULL.
456  * @relatesalso as_list
457  */
458 static inline as_list * as_list_drop(const as_list * list, uint32_t n)
459 {
460  return as_util_hook(drop, NULL, list, n);
461 }
462 
463 /**
464  * Creates a new list containing the first n elements of the list.
465  *
466  * @param list The list to drop elements from.
467  * @param n The number of elements to take.
468  *
469  * @return On success, a new list containing the selected elements. Otherwise NULL.
470  * @relatesalso as_list
471  */
472 static inline as_list * as_list_take(const as_list * list, uint32_t n)
473 {
474  return as_util_hook(take, NULL, list, n);
475 }
476 
477 /******************************************************************************
478  * GET FUNCTIONS
479  *****************************************************************************/
480 
481 /**
482  * Get the value at specified index as an as_val.
483  *
484  * @param list The list to get the value from.
485  * @param i The index of the value to get from the list.
486  *
487  * @return On success, the value at the given index. Otherwise NULL.
488  * @relatesalso as_list
489  */
490 static inline as_val * as_list_get(const as_list * list, const uint32_t i)
491 {
492  return as_util_hook(get, NULL, list, i);
493 }
494 
495 /**
496  * Get the value at specified index as an int64_t.
497  *
498  * @param list The list to get the value from.
499  * @param i The index of the value to get from the list.
500  *
501  * @return On success, the value at the given index. Otherwise NULL.
502  * @relatesalso as_list
503  */
504 static inline int64_t as_list_get_int64(const as_list * list, const uint32_t i)
505 {
506  return as_util_hook(get_int64, 0, list, i);
507 }
508 
509 /**
510  * Get the value at specified index as an NULL terminated string.
511  *
512  * @param list The list to get the value from.
513  * @param i The index of the value to get from the list.
514  *
515  * @return On success, the value at the given index. Otherwise NULL.
516  * @relatesalso as_list
517  */
518 static inline char * as_list_get_str(const as_list * list, const uint32_t i)
519 {
520  return as_util_hook(get_str, NULL, list, i);
521 }
522 
523 /**
524  * Get the value at specified index as an as_integer.
525  *
526  * @param list The list to get the value from.
527  * @param i The index of the value to get from the list.
528  *
529  * @return On success, the value at the given index. Otherwise NULL.
530  * @relatesalso as_list
531  */
532 static inline as_integer * as_list_get_integer(const as_list * list, const uint32_t i)
533 {
534  return as_integer_fromval(as_list_get(list, i));
535 }
536 
537 /**
538  * Get the value at specified index as an as_val.
539  *
540  * @param list The list to get the value from.
541  * @param i The index of the value to get from the list.
542  *
543  * @return On success, the value at the given index. Otherwise NULL.
544  * @relatesalso as_list
545  */
546 static inline as_string * as_list_get_string(const as_list * list, const uint32_t i)
547 {
548  return as_string_fromval(as_list_get(list, i));
549 }
550 
551 /**
552  * Get the value at specified index as an as_val.
553  *
554  * @param list The list to get the value from.
555  * @param i The index of the value to get from the list.
556  *
557  * @return On success, the value at the given index. Otherwise NULL.
558  * @relatesalso as_list
559  */
560 static inline as_bytes * as_list_get_bytes(const as_list * list, const uint32_t i)
561 {
562  return as_bytes_fromval(as_list_get(list, i));
563 }
564 
565 /**
566  * Get the value at specified index as an as_val.
567  *
568  * @param list The list to get the value from.
569  * @param i The index of the value to get from the list.
570  *
571  * @return On success, the value at the given index. Otherwise NULL.
572  * @relatesalso as_list
573  */
574 static inline as_list * as_list_get_list(const as_list * list, const uint32_t i)
575 {
576  as_val * v = as_list_get(list, i);
577  return (as_list *) (v && v->type == AS_LIST ? v : NULL);
578 }
579 
580 /**
581  * Get the value at specified index as an as_val.
582  *
583  * @param list The list to get the value from.
584  * @param i The index of the value to get from the list.
585  *
586  * @return On success, the value at the given index. Otherwise NULL.
587  * @relatesalso as_list
588  */
589 static inline struct as_map_s * as_list_get_map(const as_list * list, const uint32_t i)
590 {
591  as_val * v = as_list_get(list, i);
592  return (struct as_map_s *) (v && v->type == AS_MAP ? v : NULL);
593 }
594 
595 
596 /******************************************************************************
597  * SET FUNCTIONS
598  *****************************************************************************/
599 
600 /**
601  * Set the value at specified index as an as_val.
602  *
603  * @param list The list.
604  * @param i The index of the value to set in the list.
605  * @param value The value to set at the given index.
606  *
607  * @return 0 on success. Otherwise an error occurred.
608  * @relatesalso as_list
609  */
610 static inline int as_list_set(as_list * list, const uint32_t i, as_val * value)
611 {
612  return as_util_hook(set, 1, list, i, value);
613 }
614 
615 /**
616  * Set an int64_t at specified index as an as_val.
617  *
618  * @param list The list.
619  * @param i The index of the value to set in the list.
620  * @param value The value to set at the given index.
621  *
622  * @return 0 on success. Otherwise an error occurred.
623  * @relatesalso as_list
624  */
625 static inline int as_list_set_int64(as_list * list, const uint32_t i, int64_t value)
626 {
627  return as_util_hook(set_int64, 1, list, i, value);
628 }
629 
630 /**
631  * Set a NULL-terminated string at specified index as an as_val.
632  *
633  * @param list The list.
634  * @param i The index of the value to set in the list.
635  * @param value The value to set at the given index.
636  *
637  * @return 0 on success. Otherwise an error occurred.
638  * @relatesalso as_list
639  */
640 static inline int as_list_set_str(as_list * list, const uint32_t i, const char * value)
641 {
642  return as_util_hook(set_str, 1, list, i, value);
643 }
644 
645 /**
646  * Set an as_integer at specified index as an as_val.
647  *
648  * @param list The list.
649  * @param i The index of the value to set in the list.
650  * @param value The value to set at the given index.
651  *
652  * @return 0 on success. Otherwise an error ocucrred.
653  * @relatesalso as_list
654  */
655 static inline int as_list_set_integer(as_list * list, const uint32_t i, as_integer * value)
656 {
657  return as_list_set(list, i, (as_val *) value);
658 }
659 
660 /**
661  * Set an as_string at specified index as an as_val.
662  *
663  * @param list The list.
664  * @param i The index of the value to set in the list.
665  * @param value The value to set at the given index.
666  *
667  * @return 0 on success. Otherwise an error occurred.
668  * @relatesalso as_list
669  */
670 static inline int as_list_set_string(as_list * list, const uint32_t i, as_string * value)
671 {
672  return as_list_set(list, i, (as_val *) value);
673 }
674 
675 /**
676  * Set an as_bytes at specified index as an as_val.
677  *
678  * @param list The list.
679  * @param i The index of the value to set in the list.
680  * @param value The value to set at the given index.
681  *
682  * @return 0 on success. Otherwise an error occurred.
683  * @relatesalso as_list
684  */
685 static inline int as_list_set_bytes(as_list * list, const uint32_t i, as_bytes * value)
686 {
687  return as_list_set(list, i, (as_val *) value);
688 }
689 
690 /**
691  * Set an as_list at specified index as an as_val.
692  *
693  * @param list The list.
694  * @param i The index of the value to set in the list.
695  * @param value The value to set at the given index.
696  *
697  * @return 0 on success. Otherwise an error occurred.
698  * @relatesalso as_list
699  */
700 static inline int as_list_set_list(as_list * list, const uint32_t i, as_list * value)
701 {
702  return as_list_set(list, i, (as_val *) value);
703 }
704 
705 /**
706  * Set an as_map at specified index as an as_val.
707  *
708  * @param list The list.
709  * @param i The index of the value to set in the list.
710  * @param value The value to set at the given index.
711  *
712  * @return 0 on success. Otherwise an error occurred.
713  * @relatesalso as_list
714  */
715 static inline int as_list_set_map(as_list * list, const uint32_t i, struct as_map_s * value)
716 {
717  return as_list_set(list, i, (as_val *) value);
718 }
719 
720 /******************************************************************************
721  * APPEND FUNCTIONS
722  *****************************************************************************/
723 
724 /**
725  * Append a value to the list.
726  *
727  * @param list The list.
728  * @param value The value to append to the list.
729  *
730  * @return 0 on success. Otherwise an error occurred.
731  * @relatesalso as_list
732  */
733 static inline int as_list_append(as_list * list, as_val * value)
734 {
735  return as_util_hook(append, 1, list, value);
736 }
737 
738 /**
739  * Append an int64_t to the list.
740  *
741  * @param list The list.
742  * @param value The value to append to the list.
743  *
744  * @return 0 on success. Otherwise an error occurred.
745  * @relatesalso as_list
746  */
747 static inline int as_list_append_int64(as_list * list, int64_t value)
748 {
749  return as_util_hook(append_int64, 1, list, value);
750 }
751 
752 /**
753  * Append a NULL-terminated string to the list.
754  *
755  * @param list The list.
756  * @param value The value to append to the list.
757  *
758  * @return 0 on success. Otherwise an error occurred.
759  * @relatesalso as_list
760  */
761 static inline int as_list_append_str(as_list * list, const char * value)
762 {
763  return as_util_hook(append_str, 1, list, value);
764 }
765 
766 /**
767  * Append an as_integer to the list.
768  *
769  * @param list The list.
770  * @param value The value to append to the list.
771  *
772  * @return 0 on success. Otherwise an error occurred.
773  * @relatesalso as_list
774  */
775 static inline int as_list_append_integer(as_list * list, as_integer * value)
776 {
777  return as_list_append(list, (as_val *) value);
778 }
779 
780 /**
781  * Append an as_string to the list.
782  *
783  * @param list The list.
784  * @param value The value to append to the list.
785  *
786  * @return 0 on success. Otherwise an error occurred.
787  * @relatesalso as_list
788  */
789 static inline int as_list_append_string(as_list * list, as_string * value)
790 {
791  return as_list_append(list, (as_val *) value);
792 }
793 
794 /**
795  * Append an as_bytes to the list.
796  *
797  * @param list The list.
798  * @param value The value to append to the list.
799  *
800  * @return 0 on success. Otherwise an error occurred.
801  * @relatesalso as_list
802  */
803 static inline int as_list_append_bytes(as_list * list, as_bytes * value)
804 {
805  return as_list_append(list, (as_val *) value);
806 }
807 
808 /**
809  * Append an as_list to the list.
810  *
811  * @param list The list.
812  * @param value The value to append to the list.
813  *
814  * @return 0 on success. Otherwise an error occurred.
815  * @relatesalso as_list
816  */
817 static inline int as_list_append_list(as_list * list, as_list * value)
818 {
819  return as_list_append(list, (as_val *) value);
820 }
821 
822 /**
823  * Append an as_map to the list.
824  *
825  * @param list The list.
826  * @param value The value to append to the list.
827  *
828  * @return 0 on success. Otherwise an error occurred.
829  * @relatesalso as_list
830  */
831 static inline int as_list_append_map(as_list * list, struct as_map_s * value)
832 {
833  return as_list_append(list, (as_val *) value);
834 }
835 
836 /******************************************************************************
837  * PREPEND FUNCTIONS
838  *****************************************************************************/
839 
840 /**
841  * Prepend a value to the list.
842  *
843  * @param list The list.
844  * @param value The value to prepend to the list.
845  *
846  * @return 0 on success. Otherwise an error occurred.
847  * @relatesalso as_list
848  */
849 static inline int as_list_prepend(as_list * list, as_val * value)
850 {
851  return as_util_hook(prepend, 1, list, value);
852 }
853 
854 /**
855  * Prepend an int64_t value to the list.
856  *
857  * @param list The list.
858  * @param value The value to prepend to the list.
859  *
860  * @return 0 on success. Otherwise an error occurred.
861  * @relatesalso as_list
862  */
863 static inline int as_list_prepend_int64(as_list * list, int64_t value)
864 {
865  return as_util_hook(prepend_int64, 1, list, value);
866 }
867 
868 /**
869  * Prepend a NULL-terminated string to the list.
870  *
871  * @param list The list.
872  * @param value The value to prepend to the list.
873  *
874  * @return 0 on success. Otherwise an error occurred.
875  * @relatesalso as_list
876  */
877 static inline int as_list_prepend_str(as_list * list, const char * value)
878 {
879  return as_util_hook(prepend_str, 1, list, value);
880 }
881 
882 /**
883  * Prepend an as_integer to the list.
884  *
885  * @param list The list.
886  * @param value The value to prepend to the list.
887  *
888  * @return 0 on success. Otherwise an error occurred.
889  * @relatesalso as_list
890  */
891 static inline int as_list_prepend_integer(as_list * list, as_integer * value)
892 {
893  return as_list_prepend(list, (as_val *) value);
894 }
895 
896 /**
897  * Prepend an as_string to the list.
898  *
899  * @param list The list.
900  * @param value The value to prepend to the list.
901  *
902  * @return 0 on success. Otherwise an error occurred.
903  * @relatesalso as_list
904  */
905 static inline int as_list_prepend_string(as_list * list, as_string * value)
906 {
907  return as_list_prepend(list, (as_val *) value);
908 }
909 
910 /**
911  * Prepend an as_bytes to the list.
912  *
913  * @param list The list.
914  * @param value The value to prepend to the list.
915  *
916  * @return 0 on success. Otherwise an error occurred.
917  * @relatesalso as_list
918  */
919 static inline int as_list_prepend_bytes(as_list * list, as_bytes * value)
920 {
921  return as_list_prepend(list, (as_val *) value);
922 }
923 
924 /**
925  * Prepend an as_list to the list.
926  *
927  * @param list The list.
928  * @param value The value to prepend to the list.
929  *
930  * @return 0 on success. Otherwise an error occurred.
931  * @relatesalso as_list
932  */
933 static inline int as_list_prepend_list(as_list * list, as_list * value)
934 {
935  return as_list_prepend(list, (as_val *) value);
936 }
937 
938 /**
939  * Prepend an as_map to the list.
940  *
941  * @param list The list.
942  * @param value The value to prepend to the list.
943  *
944  * @return 0 on success. Otherwise an error occurred.
945  * @relatesalso as_list
946  */
947 static inline int as_list_prepend_map(as_list * list, struct as_map_s * value)
948 {
949  return as_list_prepend(list, (as_val *) value);
950 }
951 
952 /******************************************************************************
953  * ITERATION FUNCTIONS
954  *****************************************************************************/
955 
956 /**
957  * Call the callback function for each element in the list..
958  *
959  * @param list The list to iterate over.
960  * @param callback The callback function call for each element.
961  * @param udata User-data to send to the callback.
962  *
963  * @return true if iteration completes fully. false if iteration was aborted.
964  *
965  * @relatesalso as_list
966  */
967 static inline bool as_list_foreach(const as_list * list, as_list_foreach_callback callback, void * udata)
968 {
969  return as_util_hook(foreach, false, list, callback, udata);
970 }
971 
972 /**
973  * Creates and initializes a new heap allocated iterator over the given list.
974  *
975  * @param list The list to iterate.
976  *
977  * @return On success, a new as_iterator. Otherwise NULL.
978  * @relatesalso as_list
979  */
980 static inline union as_list_iterator_u * as_list_iterator_new(const as_list * list)
981 {
982  return as_util_hook(iterator_new, NULL, list);
983 }
984 
985 
986 /**
987  * Initializes a stack allocated iterator over the given list.
988  *
989  * @param list The list to iterate.
990  * @param it The iterator to initialize.
991  *
992  * @return On success, the initializes as_iterator. Otherwise NULL.
993  * @relatesalso as_list
994  */
995 static inline union as_list_iterator_u * as_list_iterator_init(union as_list_iterator_u * it, const as_list * list)
996 {
997  return as_util_hook(iterator_init, NULL, list, it);
998 }
999 
1000 /******************************************************************************
1001  * CONVERSION FUNCTIONS
1002  *****************************************************************************/
1003 
1004 /**
1005  * Convert to an as_val.
1006  * @relatesalso as_list
1007  */
1008 static inline as_val * as_list_toval(as_list * list)
1009 {
1010  return (as_val *) list;
1011 }
1012 
1013 /**
1014  * Convert from an as_val.
1015  * @relatesalso as_list
1016  */
1017 static inline as_list * as_list_fromval(as_val * v)
1018 {
1019  return as_util_fromval(v, AS_LIST, as_list);
1020 }
1021 
1022 /******************************************************************************
1023  * as_val FUNCTIONS
1024  *****************************************************************************/
1025 
1026 /**
1027  * @private
1028  * Internal helper function for destroying an as_val.
1029  */
1030 void as_list_val_destroy(as_val * v);
1031 
1032 /**
1033  * @private
1034  * Internal helper function for getting the hashcode of an as_val.
1035  */
1036 uint32_t as_list_val_hashcode(const as_val * v);
1037 
1038 /**
1039  * @private
1040  * Internal helper function for getting the string representation of an as_val.
1041  */
1042 char * as_list_val_tostring(const as_val * v);
1043 
static void as_list_destroy(as_list *list)
Definition: as_list.h:384
static as_integer * as_integer_fromval(const as_val *v)
Definition: as_integer.h:230
static as_string * as_list_get_string(const as_list *list, const uint32_t i)
Definition: as_list.h:546
static int as_list_append_string(as_list *list, as_string *value)
Definition: as_list.h:789
static int as_list_set_integer(as_list *list, const uint32_t i, as_integer *value)
Definition: as_list.h:655
static bool as_list_foreach(const as_list *list, as_list_foreach_callback callback, void *udata)
Definition: as_list.h:967
static struct as_map_s * as_list_get_map(const as_list *list, const uint32_t i)
Definition: as_list.h:589
static int as_list_prepend_string(as_list *list, as_string *value)
Definition: as_list.h:905
static char * as_list_get_str(const as_list *list, const uint32_t i)
Definition: as_list.h:518
static int as_list_prepend_list(as_list *list, as_list *value)
Definition: as_list.h:933
#define as_util_fromval(object, type_id, type)
Definition: as_util.h:38
struct as_list_hooks_s * hooks
Definition: as_list.h:76
static int as_list_set_str(as_list *list, const uint32_t i, const char *value)
Definition: as_list.h:640
static int as_list_set_bytes(as_list *list, const uint32_t i, as_bytes *value)
Definition: as_list.h:685
static int64_t as_list_get_int64(const as_list *list, const uint32_t i)
Definition: as_list.h:504
static union as_list_iterator_u * as_list_iterator_init(union as_list_iterator_u *it, const as_list *list)
Definition: as_list.h:995
Definition: as_val.h:51
bool(* as_list_foreach_callback)(as_val *value, void *udata)
Definition: as_list.h:48
static int as_list_append(as_list *list, as_val *value)
Definition: as_list.h:733
static int as_list_prepend(as_list *list, as_val *value)
Definition: as_list.h:849
static as_list * as_list_tail(const as_list *list)
Definition: as_list.h:444
static int as_list_set_list(as_list *list, const uint32_t i, as_list *value)
Definition: as_list.h:700
#define as_util_hook(hook, default, object, args...)
Definition: as_util.h:32
AS_MAP
Definition: as_val.h:214
as_list * as_list_init(as_list *list, void *data, const as_list_hooks *hooks)
as_list * as_list_cons(as_list *list, bool free, void *data, const as_list_hooks *hooks)
static as_val * as_list_toval(as_list *list)
Definition: as_list.h:1008
static int as_list_append_int64(as_list *list, int64_t value)
Definition: as_list.h:747
static int as_list_append_str(as_list *list, const char *value)
Definition: as_list.h:761
static int as_list_set_map(as_list *list, const uint32_t i, struct as_map_s *value)
Definition: as_list.h:715
static int as_list_append_list(as_list *list, as_list *value)
Definition: as_list.h:817
static union as_list_iterator_u * as_list_iterator_new(const as_list *list)
Definition: as_list.h:980
static as_bytes * as_list_get_bytes(const as_list *list, const uint32_t i)
Definition: as_list.h:560
enum as_val_t type
Definition: as_val.h:56
static as_val * as_list_head(const as_list *list)
Definition: as_list.h:431
as_val _
Definition: as_list.h:66
static uint32_t as_list_size(as_list *list)
Definition: as_list.h:414
static int as_list_set_int64(as_list *list, const uint32_t i, int64_t value)
Definition: as_list.h:625
static int as_list_prepend_bytes(as_list *list, as_bytes *value)
Definition: as_list.h:919
static int as_list_prepend_map(as_list *list, struct as_map_s *value)
Definition: as_list.h:947
static as_bytes * as_bytes_fromval(const as_val *v)
Definition: as_bytes.h:911
void * data
Definition: as_list.h:71
static int as_list_append_bytes(as_list *list, as_bytes *value)
Definition: as_list.h:803
static int as_list_append_integer(as_list *list, as_integer *value)
Definition: as_list.h:775
static uint32_t as_list_hashcode(as_list *list)
Definition: as_list.h:401
static int as_list_prepend_str(as_list *list, const char *value)
Definition: as_list.h:877
static as_string * as_string_fromval(const as_val *v)
Definition: as_string.h:261
static int as_list_set_string(as_list *list, const uint32_t i, as_string *value)
Definition: as_list.h:670
static as_list * as_list_fromval(as_val *v)
Definition: as_list.h:1017
static int as_list_prepend_int64(as_list *list, int64_t value)
Definition: as_list.h:863
static as_list * as_list_drop(const as_list *list, uint32_t n)
Definition: as_list.h:458
as_list * as_list_new(void *data, const as_list_hooks *hooks)
AS_LIST
Definition: as_val.h:213
#define as_val_destroy(__v)
Definition: as_val.h:104
uint32_t as_list_val_hashcode(const as_val *v)
static as_integer * as_list_get_integer(const as_list *list, const uint32_t i)
Definition: as_list.h:532
static int as_list_append_map(as_list *list, struct as_map_s *value)
Definition: as_list.h:831
char * as_list_val_tostring(const as_val *v)
static int as_list_set(as_list *list, const uint32_t i, as_val *value)
Definition: as_list.h:610
void as_list_val_destroy(as_val *v)
static as_list * as_list_take(const as_list *list, uint32_t n)
Definition: as_list.h:472
static as_val * as_list_get(const as_list *list, const uint32_t i)
Definition: as_list.h:490
static int as_list_prepend_integer(as_list *list, as_integer *value)
Definition: as_list.h:891
static as_list * as_list_get_list(const as_list *list, const uint32_t i)
Definition: as_list.h:574