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