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-2015 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 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #include <aerospike/as_bytes.h>
25 #include <aerospike/as_integer.h>
26 #include <aerospike/as_iterator.h>
27 #include <aerospike/as_string.h>
28 #include <aerospike/as_util.h>
29 #include <aerospike/as_val.h>
30 
31 #include <stdbool.h>
32 #include <stdint.h>
33 
34 /******************************************************************************
35  * TYPES
36  *****************************************************************************/
37 
38 union as_list_iterator_u;
39 
40 struct as_list_hooks_s;
41 
42 /**
43  * Callback function for `as_list_foreach()`. Called for each element in the
44  * list.
45  *
46  * @param value The value of the current element.
47  * @param udata The user-data provided to the `as_list_foreach()`.
48  *
49  * @return true to continue iterating through the list.
50  * false to stop iterating.
51  */
52 typedef bool (* as_list_foreach_callback) (as_val * value, void * udata);
53 
54 /**
55  * as_list is an interface for List based data types.
56  *
57  * Implementations:
58  * - as_arraylist
59  *
60  * @extends as_val
61  * @ingroup aerospike_t
62  */
63 typedef struct as_list_s {
64 
65  /**
66  * @private
67  * as_list is a subtype of as_val.
68  * You can cast as_list to as_val.
69  */
71 
72  /**
73  * Pointer to the data for this list.
74  */
75  void * data;
76 
77  /**
78  * Hooks for subtypes of as_list to implement.
79  */
80  const struct as_list_hooks_s * hooks;
81 
82 } as_list;
83 
84 /**
85  * List Function Hooks
86  */
87 typedef struct as_list_hooks_s {
88 
89  /***************************************************************************
90  * instance hooks
91  **************************************************************************/
92 
93  /**
94  * Releases the subtype of as_list.
95  *
96  * @param map The map instance to destroy.
97  *
98  * @return true on success. Otherwise false.
99  */
100  bool (* destroy)(as_list * list);
101 
102  /***************************************************************************
103  * info hooks
104  **************************************************************************/
105 
106  /**
107  * The hash value of an as_list.
108  *
109  * @param list The list to get the hashcode value for.
110  *
111  * @return The hashcode value.
112  */
113  uint32_t (* hashcode)(const as_list * list);
114 
115  /**
116  * The size of the as_list.
117  *
118  * @param map The map to get the size of.
119  *
120  * @return The number of entries in the map.
121  */
122  uint32_t (* size)(const as_list * list);
123 
124  /***************************************************************************
125  * get hooks
126  **************************************************************************/
127 
128  /**
129  * Get the value at a given index of the list.
130  *
131  * @param list The list to get the value from.
132  * @param index The index of the value.
133  *
134  * @return The value at the given index on success. Otherwie NULL.
135  */
136  as_val * (* get)(const as_list * list, uint32_t index);
137 
138  /**
139  * Get the int64_t value at a given index of the list.
140  *
141  * @param list The list to get the value from.
142  * @param index The index of the value.
143  *
144  * @return The value at the given index on success. Otherwie NULL.
145  */
146  int64_t (* get_int64)(const as_list * list, uint32_t index);
147 
148  /**
149  * Get the NULL-terminated string value at a given index of the list.
150  *
151  * @param list The list to get the value from.
152  * @param index The index of the value.
153  *
154  * @return The value at the given index on success. Otherwie NULL.
155  */
156  char * (* get_str)(const as_list * list, uint32_t index);
157 
158  /***************************************************************************
159  * set hooks
160  **************************************************************************/
161 
162  /**
163  * Set a value at the given index of the list.
164  *
165  * @param list The list to get the value from.
166  * @param index The index of the value.
167  * @param value The value for the given index.
168  *
169  * @return The value at the given index on success. Otherwie NULL.
170  */
171  int (* set)(as_list * list, uint32_t index, as_val * value);
172 
173  /**
174  * Set an int64_t value at the given index of the list.
175  *
176  * @param list The list to get the value from.
177  * @param index The index of the value.
178  * @param value The value for the given index.
179  *
180  * @return The value at the given index on success. Otherwie NULL.
181  */
182  int (* set_int64)(as_list * list, uint32_t index, int64_t value);
183 
184  /**
185  * Set a NULL-terminated string value at the given index of the list.
186  *
187  * @param list The list to get the value from.
188  * @param index The index of the value.
189  * @param value The value for the given index.
190  *
191  * @return The value at the given index on success. Otherwie NULL.
192  */
193  int (* set_str)(as_list * list, uint32_t index, const char * value);
194 
195  /***************************************************************************
196  * insert hooks
197  **************************************************************************/
198 
199  /**
200  * Insert a value at the given index of the list.
201  *
202  * @param list The list to insert the value into.
203  * @param index The index of the value.
204  * @param value The value for the given index.
205  *
206  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
207  */
208  int (* insert)(as_list * list, uint32_t index, as_val * value);
209 
210  /**
211  * Insert an int64_t value at the given index of the list.
212  *
213  * @param list The list to insert the value into.
214  * @param index The index of the value.
215  * @param value The value for the given index.
216  *
217  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
218  */
219  int (* insert_int64)(as_list * list, uint32_t index, int64_t value);
220 
221  /**
222  * Insert a NULL-terminated string value at the given index of the list.
223  *
224  * @param list The list to insert the value into.
225  * @param index The index of the value.
226  * @param value The value for the given index.
227  *
228  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
229  */
230  int (* insert_str)(as_list * list, uint32_t index, const char * value);
231 
232  /***************************************************************************
233  * append hooks
234  **************************************************************************/
235 
236  /**
237  * Append a value to the list.
238  *
239  * @param list The list to append to.
240  * @param value The value to append to the list.
241  *
242  * @return 0 on success. Otherwise an error occurred.
243  */
244  int (* append)(as_list * list, as_val * value);
245 
246  /**
247  * Append an int64_t value to the list.
248  *
249  * @param list The list to append to.
250  * @param value The value to append to the list.
251  *
252  * @return 0 on success. Otherwise an error occurred.
253  */
254  int (* append_int64)(as_list * list, int64_t value);
255 
256  /**
257  * Append a NULL-terminates string value to the list.
258  *
259  * @param list The list to append to.
260  * @param value The value to append to the list.
261  *
262  * @return 0 on success. Otherwise an error occurred.
263  */
264  int (* append_str)(as_list * list, const char * value);
265 
266  /***************************************************************************
267  * prepend hooks
268  **************************************************************************/
269 
270  /**
271  * Prepend the value to the list.
272  *
273  * @param list The list to prepend to.
274  * @param value The value to prepend to the list.
275  *
276  * @return 0 on success. Otherwise an error occurred.
277  */
278  int (* prepend)(as_list * list, as_val * value);
279 
280  /**
281  * Prepend an int64_t value to the list.
282  *
283  * @param list The list to prepend to.
284  * @param value The value to prepend to the list.
285  *
286  * @return 0 on success. Otherwise an error occurred.
287  */
288  int (* prepend_int64)(as_list * list, int64_t value);
289 
290  /**
291  * Prepend a NULL-terminates string value to the list.
292  *
293  * @param list The list to prepend to.
294  * @param value The value to prepend to the list.
295  *
296  * @return 0 on success. Otherwise an error occurred.
297  */
298  int (* prepend_str)(as_list * list, const char * value);
299 
300  /***************************************************************************
301  * remove hook
302  **************************************************************************/
303 
304  /**
305  * Remove element at specified index.
306  *
307  * Any elements beyond specified index will be shifted so their indexes
308  * decrease by 1. The element at specified index will be destroyed.
309  *
310  * @param list The list.
311  * @param index The index of the element to remove.
312  *
313  * @return 0 on success. Otherwise an error occurred.
314  */
315  int (* remove)(as_list * list, uint32_t index);
316 
317  /***************************************************************************
318  * accessor and modifier hooks
319  **************************************************************************/
320 
321  /**
322  * Append all elements of list2, in order, to list. No new list object is
323  * created.
324  *
325  * @param list The list to append to.
326  * @param list2 The list from which to append.
327  *
328  * @return 0 on success. Otherwise an error occurred.
329  */
330  int (* concat)(as_list * list, const as_list * list2);
331 
332  /**
333  * Delete (and destroy) all elements at and beyond specified index. Capacity is
334  * not reduced.
335  *
336  * @param list The list to trim.
337  * @param index The index from which to trim.
338  *
339  * @return 0 on success. Otherwise an error occurred.
340  */
341  int (* trim)(as_list * list, uint32_t index);
342 
343  /**
344  * Return the first element in the list.
345  *
346  * @param list The list to get the value from.
347  *
348  * @return The first value in the list. Otherwise NULL.
349  */
350  as_val * (* head)(const as_list * list);
351 
352  /**
353  * Return all but the first element of the list, returning a new list.
354  *
355  * @param list The list to get the list from.
356  *
357  * @return The tail of the list. Otherwise NULL.
358  */
359  as_list * (* tail)(const as_list * list);
360 
361  /**
362  * Drop the first n element of the list, returning a new list.
363  *
364  * @param list The list.
365  * @param n The number of element to drop.
366  *
367  * @return A new list containing the remaining elements. Otherwise NULL.
368  */
369  as_list * (* drop)(const as_list * list, uint32_t n);
370 
371  /**
372  * Take the first n element of the list, returning a new list.
373  *
374  * @param list The list.
375  * @param n The number of element to take.
376  *
377  * @return A new list containing the remaining elements. Otherwise NULL.
378  */
379  as_list * (* take)(const as_list * list, uint32_t n);
380 
381  /***************************************************************************
382  * iteration hooks
383  **************************************************************************/
384 
385  /**
386  * Iterate over each element in the list can call the callback function.
387  *
388  * @param map The map to iterate.
389  * @param callback The function to call for each element in the list.
390  * @param udata User-data to be passed to the callback.
391  *
392  * @return true on success. Otherwise false.
393  */
394  bool (* foreach)(const as_list * list, as_list_foreach_callback callback, void * udata);
395 
396  /**
397  * Create and initialize a new heap allocated iterator to traverse over the list.
398  *
399  * @param list The list to iterate.
400  *
401  * @return true on success. Otherwise false.
402  */
403  union as_list_iterator_u * (* iterator_new)(const as_list * list);
404 
405  /**
406  * Initializes a stack allocated iterator to traverse over the list.
407  *
408  * @param list The list to iterate.
409  *
410  * @return true on success. Otherwise false.
411  */
412  union as_list_iterator_u * (* iterator_init)(const as_list * list, union as_list_iterator_u * it);
413 
414 } as_list_hooks;
415 
416 /*******************************************************************************
417  * INSTANCE FUNCTIONS
418  ******************************************************************************/
419 
420 /**
421  * @private
422  * Utilized by subtypes of as_list to initialize the parent.
423  *
424  * @param list The list to initialize.
425  * @param free If true, then as_list_destroy() will free the list.
426  * @param data Data for the list.
427  * @param hooks Implementaton for the list interface.
428  *
429  * @return On success, the initialized list. Otherwise NULL.
430  * @relatesalso as_list
431  */
432 as_list * as_list_cons(as_list * list, bool free, void * data, const as_list_hooks * hooks);
433 
434 /**
435  * Initialize a stack allocated list.
436  *
437  * @param list Stack allocated list to initialize.
438  * @param data Data for the list.
439  * @param hooks Implementaton for the list interface.
440  *
441  * @return On succes, the initialized list. Otherwise NULL.
442  * @relatesalso as_list
443  */
444 as_list * as_list_init(as_list * list, void * data, const as_list_hooks * hooks);
445 
446 /**
447  * Create and initialize a new heap allocated list.
448  *
449  * @param data Data for the list.
450  * @param hooks Implementaton for the list interface.
451  *
452  * @return On succes, a new list. Otherwise NULL.
453  * @relatesalso as_list
454  */
455 as_list * as_list_new(void * data, const as_list_hooks * hooks);
456 
457 /**
458  * Destroy the list and associated resources.
459  *
460  * @param list The list to destroy.
461  * @relatesalso as_list
462  */
463 static inline void as_list_destroy(as_list * list)
464 {
465  as_val_destroy((as_val *) list);
466 }
467 
468 /******************************************************************************
469  * INFO FUNCTIONS
470  *****************************************************************************/
471 
472 /**
473  * Get the hashcode value for the list.
474  *
475  * @param list The list.
476  *
477  * @return The hashcode of the list.
478  * @relatesalso as_list
479  */
480 static inline uint32_t as_list_hashcode(as_list * list)
481 {
482  return as_util_hook(hashcode, 0, list);
483 }
484 
485 /**
486  * Number of elements in the list.
487  *
488  * @param list The list.
489  *
490  * @return The size of the list.
491  * @relatesalso as_list
492  */
493 static inline uint32_t as_list_size(as_list * list)
494 {
495  return as_util_hook(size, 0, list);
496 }
497 
498 /******************************************************************************
499  * ACCESSOR AND MODIFIER FUNCTIONS
500  *****************************************************************************/
501 
502 /**
503  * Append all elements of list2, in order, to list. No new list object is
504  * created.
505  *
506  * @param list The list to append to.
507  * @param list2 The list from which to append.
508  *
509  * @return 0 on success. Otherwise an error occurred.
510  * @relatesalso as_list
511  */
512 static inline int as_list_concat(as_list * list, const as_list * list2)
513 {
514  return as_util_hook(concat, 1, list, list2);
515 }
516 
517 /**
518  * Delete (and destroy) all elements at and beyond specified index. Capacity is
519  * not reduced.
520  *
521  * @param list The list to trim.
522  * @param index The index from which to trim.
523  *
524  * @return 0 on success. Otherwise an error occurred.
525  * @relatesalso as_list
526  */
527 static inline int as_list_trim(as_list * list, uint32_t index)
528 {
529  return as_util_hook(trim, 1, list, index);
530 }
531 
532 /**
533  * The first element in the list.
534  *
535  * @param list The list to get the head value from.
536  *
537  * @return The first value of the list on success. Otherwise NULL.
538  * @relatesalso as_list
539  */
540 static inline as_val * as_list_head(const as_list * list)
541 {
542  return as_util_hook(head, NULL, list);
543 }
544 
545 /**
546  * All elements after the first element in the list.
547  *
548  * @param list The list to get the tail from.
549  *
550  * @return On success, the tail of the list. Otherwise NULL.
551  * @relatesalso as_list
552  */
553 static inline as_list * as_list_tail(const as_list * list)
554 {
555  return as_util_hook(tail, NULL, list);
556 }
557 
558 /**
559  * Create a new list containing all elements, except the first n elements, of the list.
560  *
561  * @param list The list to drop elements from.
562  * @param n The number of elements to drop.
563  *
564  * @return On success, a new list containing the remaining elements. Otherwise NULL.
565  * @relatesalso as_list
566  */
567 static inline as_list * as_list_drop(const as_list * list, uint32_t n)
568 {
569  return as_util_hook(drop, NULL, list, n);
570 }
571 
572 /**
573  * Creates a new list containing the first n elements of the list.
574  *
575  * @param list The list to drop elements from.
576  * @param n The number of elements to take.
577  *
578  * @return On success, a new list containing the selected elements. Otherwise NULL.
579  * @relatesalso as_list
580  */
581 static inline as_list * as_list_take(const as_list * list, uint32_t n)
582 {
583  return as_util_hook(take, NULL, list, n);
584 }
585 
586 /******************************************************************************
587  * GET FUNCTIONS
588  *****************************************************************************/
589 
590 /**
591  * Get the value at specified index as an as_val.
592  *
593  * @param list The list to get the value from.
594  * @param i The index of the value to get from the list.
595  *
596  * @return On success, the value at the given index. Otherwise NULL.
597  * @relatesalso as_list
598  */
599 static inline as_val * as_list_get(const as_list * list, uint32_t i)
600 {
601  return as_util_hook(get, NULL, list, i);
602 }
603 
604 /**
605  * Get the value at specified index as an int64_t.
606  *
607  * @param list The list to get the value from.
608  * @param i The index of the value to get from the list.
609  *
610  * @return On success, the value at the given index. Otherwise NULL.
611  * @relatesalso as_list
612  */
613 static inline int64_t as_list_get_int64(const as_list * list, uint32_t i)
614 {
615  return as_util_hook(get_int64, 0, list, i);
616 }
617 
618 /**
619  * Get the value at specified index as an NULL terminated string.
620  *
621  * @param list The list to get the value from.
622  * @param i The index of the value to get from the list.
623  *
624  * @return On success, the value at the given index. Otherwise NULL.
625  * @relatesalso as_list
626  */
627 static inline char * as_list_get_str(const as_list * list, uint32_t i)
628 {
629  return as_util_hook(get_str, NULL, list, i);
630 }
631 
632 /**
633  * Get the value at specified index as an as_integer.
634  *
635  * @param list The list to get the value from.
636  * @param i The index of the value to get from the list.
637  *
638  * @return On success, the value at the given index. Otherwise NULL.
639  * @relatesalso as_list
640  */
641 static inline as_integer * as_list_get_integer(const as_list * list, uint32_t i)
642 {
643  return as_integer_fromval(as_list_get(list, i));
644 }
645 
646 /**
647  * Get the value at specified index as an as_val.
648  *
649  * @param list The list to get the value from.
650  * @param i The index of the value to get from the list.
651  *
652  * @return On success, the value at the given index. Otherwise NULL.
653  * @relatesalso as_list
654  */
655 static inline as_string * as_list_get_string(const as_list * list, uint32_t i)
656 {
657  return as_string_fromval(as_list_get(list, i));
658 }
659 
660 /**
661  * Get the value at specified index as an as_val.
662  *
663  * @param list The list to get the value from.
664  * @param i The index of the value to get from the list.
665  *
666  * @return On success, the value at the given index. Otherwise NULL.
667  * @relatesalso as_list
668  */
669 static inline as_bytes * as_list_get_bytes(const as_list * list, uint32_t i)
670 {
671  return as_bytes_fromval(as_list_get(list, i));
672 }
673 
674 /**
675  * Get the value at specified index as an as_val.
676  *
677  * @param list The list to get the value from.
678  * @param i The index of the value to get from the list.
679  *
680  * @return On success, the value at the given index. Otherwise NULL.
681  * @relatesalso as_list
682  */
683 static inline as_list * as_list_get_list(const as_list * list, uint32_t i)
684 {
685  as_val * v = as_list_get(list, i);
686  return (as_list *) (v && v->type == AS_LIST ? v : NULL);
687 }
688 
689 /**
690  * Get the value at specified index as an as_val.
691  *
692  * @param list The list to get the value from.
693  * @param i The index of the value to get from the list.
694  *
695  * @return On success, the value at the given index. Otherwise NULL.
696  * @relatesalso as_list
697  */
698 static inline struct as_map_s * as_list_get_map(const as_list * list, uint32_t i)
699 {
700  as_val * v = as_list_get(list, i);
701  return (struct as_map_s *) (v && v->type == AS_MAP ? v : NULL);
702 }
703 
704 /******************************************************************************
705  * SET FUNCTIONS
706  *****************************************************************************/
707 
708 /**
709  * Set the value at specified index as an as_val.
710  *
711  * @param list The list.
712  * @param i The index of the value to set in the list.
713  * @param value The value to set at the given index.
714  *
715  * @return 0 on success. Otherwise an error occurred.
716  * @relatesalso as_list
717  */
718 static inline int as_list_set(as_list * list, uint32_t i, as_val * value)
719 {
720  return as_util_hook(set, 1, list, i, value);
721 }
722 
723 /**
724  * Set an int64_t at specified index as an as_val.
725  *
726  * @param list The list.
727  * @param i The index of the value to set in the list.
728  * @param value The value to set at the given index.
729  *
730  * @return 0 on success. Otherwise an error occurred.
731  * @relatesalso as_list
732  */
733 static inline int as_list_set_int64(as_list * list, uint32_t i, int64_t value)
734 {
735  return as_util_hook(set_int64, 1, list, i, value);
736 }
737 
738 /**
739  * Set a NULL-terminated string at specified index as an as_val.
740  *
741  * @param list The list.
742  * @param i The index of the value to set in the list.
743  * @param value The value to set at the given index.
744  *
745  * @return 0 on success. Otherwise an error occurred.
746  * @relatesalso as_list
747  */
748 static inline int as_list_set_str(as_list * list, uint32_t i, const char * value)
749 {
750  return as_util_hook(set_str, 1, list, i, value);
751 }
752 
753 /**
754  * Set an as_integer at specified index as an as_val.
755  *
756  * @param list The list.
757  * @param i The index of the value to set in the list.
758  * @param value The value to set at the given index.
759  *
760  * @return 0 on success. Otherwise an error ocucrred.
761  * @relatesalso as_list
762  */
763 static inline int as_list_set_integer(as_list * list, uint32_t i, as_integer * value)
764 {
765  return as_list_set(list, i, (as_val *) value);
766 }
767 
768 /**
769  * Set an as_string at specified index as an as_val.
770  *
771  * @param list The list.
772  * @param i The index of the value to set in the list.
773  * @param value The value to set at the given index.
774  *
775  * @return 0 on success. Otherwise an error occurred.
776  * @relatesalso as_list
777  */
778 static inline int as_list_set_string(as_list * list, uint32_t i, as_string * value)
779 {
780  return as_list_set(list, i, (as_val *) value);
781 }
782 
783 /**
784  * Set an as_bytes at specified index as an as_val.
785  *
786  * @param list The list.
787  * @param i The index of the value to set in the list.
788  * @param value The value to set at the given index.
789  *
790  * @return 0 on success. Otherwise an error occurred.
791  * @relatesalso as_list
792  */
793 static inline int as_list_set_bytes(as_list * list, uint32_t i, as_bytes * value)
794 {
795  return as_list_set(list, i, (as_val *) value);
796 }
797 
798 /**
799  * Set an as_list at specified index as an as_val.
800  *
801  * @param list The list.
802  * @param i The index of the value to set in the list.
803  * @param value The value to set at the given index.
804  *
805  * @return 0 on success. Otherwise an error occurred.
806  * @relatesalso as_list
807  */
808 static inline int as_list_set_list(as_list * list, uint32_t i, as_list * value)
809 {
810  return as_list_set(list, i, (as_val *) value);
811 }
812 
813 /**
814  * Set an as_map at specified index as an as_val.
815  *
816  * @param list The list.
817  * @param i The index of the value to set in the list.
818  * @param value The value to set at the given index.
819  *
820  * @return 0 on success. Otherwise an error occurred.
821  * @relatesalso as_list
822  */
823 static inline int as_list_set_map(as_list * list, uint32_t i, struct as_map_s * value)
824 {
825  return as_list_set(list, i, (as_val *) value);
826 }
827 
828 /******************************************************************************
829  * INSERT FUNCTIONS
830  *****************************************************************************/
831 
832 /**
833  * Insert a value at the specified index of the list.
834  *
835  * Any elements at and beyond specified index will be shifted so their indexes
836  * increase by 1. It's ok to insert beyond the current end of the list.
837  *
838  * @param list The list.
839  * @param i The index at which to insert.
840  * @param value The value to insert at the given index.
841  *
842  * @return 0 on success. Otherwise an error occurred.
843  * @relatesalso as_list
844  */
845 static inline int as_list_insert(as_list * list, uint32_t i, as_val * value)
846 {
847  return as_util_hook(insert, 1, list, i, value);
848 }
849 
850 /**
851  * Insert an int64_t at specified index as an as_val.
852  *
853  * @param list The list.
854  * @param i The index at which to insert.
855  * @param value The value to insert at the given index.
856  *
857  * @return 0 on success. Otherwise an error occurred.
858  * @relatesalso as_list
859  */
860 static inline int as_list_insert_int64(as_list * list, uint32_t i, int64_t value)
861 {
862  return as_util_hook(insert_int64, 1, list, i, value);
863 }
864 
865 /**
866  * Insert a NULL-terminated string at specified index as an as_val.
867  *
868  * @param list The list.
869  * @param i The index at which to insert.
870  * @param value The value to insert at the given index.
871  *
872  * @return 0 on success. Otherwise an error occurred.
873  * @relatesalso as_list
874  */
875 static inline int as_list_insert_str(as_list * list, uint32_t i, const char * value)
876 {
877  return as_util_hook(insert_str, 1, list, i, value);
878 }
879 
880 /**
881  * Insert an as_integer at specified index as an as_val.
882  *
883  * @param list The list.
884  * @param i The index at which to insert.
885  * @param value The value to insert at the given index.
886  *
887  * @return 0 on success. Otherwise an error ocucrred.
888  * @relatesalso as_list
889  */
890 static inline int as_list_insert_integer(as_list * list, uint32_t i, as_integer * value)
891 {
892  return as_list_insert(list, i, (as_val *) value);
893 }
894 
895 /**
896  * Insert an as_string at specified index as an as_val.
897  *
898  * @param list The list.
899  * @param i The index at which to insert.
900  * @param value The value to insert at the given index.
901  *
902  * @return 0 on success. Otherwise an error occurred.
903  * @relatesalso as_list
904  */
905 static inline int as_list_insert_string(as_list * list, uint32_t i, as_string * value)
906 {
907  return as_list_insert(list, i, (as_val *) value);
908 }
909 
910 /**
911  * Insert an as_bytes at specified index as an as_val.
912  *
913  * @param list The list.
914  * @param i The index at which to insert.
915  * @param value The value to insert at the given index.
916  *
917  * @return 0 on success. Otherwise an error occurred.
918  * @relatesalso as_list
919  */
920 static inline int as_list_insert_bytes(as_list * list, uint32_t i, as_bytes * value)
921 {
922  return as_list_insert(list, i, (as_val *) value);
923 }
924 
925 /**
926  * Insert an as_list at specified index as an as_val.
927  *
928  * @param list The list.
929  * @param i The index at which to insert.
930  * @param value The value to insert at the given index.
931  *
932  * @return 0 on success. Otherwise an error occurred.
933  * @relatesalso as_list
934  */
935 static inline int as_list_insert_list(as_list * list, uint32_t i, as_list * value)
936 {
937  return as_list_insert(list, i, (as_val *) value);
938 }
939 
940 /**
941  * Insert an as_map at specified index as an as_val.
942  *
943  * @param list The list.
944  * @param i The index at which to insert.
945  * @param value The value to insert at the given index.
946  *
947  * @return 0 on success. Otherwise an error occurred.
948  * @relatesalso as_list
949  */
950 static inline int as_list_insert_map(as_list * list, uint32_t i, struct as_map_s * value)
951 {
952  return as_list_insert(list, i, (as_val *) value);
953 }
954 
955 /******************************************************************************
956  * APPEND FUNCTIONS
957  *****************************************************************************/
958 
959 /**
960  * Append a value to the list.
961  *
962  * @param list The list.
963  * @param value The value to append to the list.
964  *
965  * @return 0 on success. Otherwise an error occurred.
966  * @relatesalso as_list
967  */
968 static inline int as_list_append(as_list * list, as_val * value)
969 {
970  return as_util_hook(append, 1, list, value);
971 }
972 
973 /**
974  * Append an int64_t to the list.
975  *
976  * @param list The list.
977  * @param value The value to append to the list.
978  *
979  * @return 0 on success. Otherwise an error occurred.
980  * @relatesalso as_list
981  */
982 static inline int as_list_append_int64(as_list * list, int64_t value)
983 {
984  return as_util_hook(append_int64, 1, list, value);
985 }
986 
987 /**
988  * Append a NULL-terminated string to the list.
989  *
990  * @param list The list.
991  * @param value The value to append to the list.
992  *
993  * @return 0 on success. Otherwise an error occurred.
994  * @relatesalso as_list
995  */
996 static inline int as_list_append_str(as_list * list, const char * value)
997 {
998  return as_util_hook(append_str, 1, list, value);
999 }
1000 
1001 /**
1002  * Append an as_integer to the list.
1003  *
1004  * @param list The list.
1005  * @param value The value to append to the list.
1006  *
1007  * @return 0 on success. Otherwise an error occurred.
1008  * @relatesalso as_list
1009  */
1010 static inline int as_list_append_integer(as_list * list, as_integer * value)
1011 {
1012  return as_list_append(list, (as_val *) value);
1013 }
1014 
1015 /**
1016  * Append an as_string to the list.
1017  *
1018  * @param list The list.
1019  * @param value The value to append to the list.
1020  *
1021  * @return 0 on success. Otherwise an error occurred.
1022  * @relatesalso as_list
1023  */
1024 static inline int as_list_append_string(as_list * list, as_string * value)
1025 {
1026  return as_list_append(list, (as_val *) value);
1027 }
1028 
1029 /**
1030  * Append an as_bytes to the list.
1031  *
1032  * @param list The list.
1033  * @param value The value to append to the list.
1034  *
1035  * @return 0 on success. Otherwise an error occurred.
1036  * @relatesalso as_list
1037  */
1038 static inline int as_list_append_bytes(as_list * list, as_bytes * value)
1039 {
1040  return as_list_append(list, (as_val *) value);
1041 }
1042 
1043 /**
1044  * Append an as_list to the list.
1045  *
1046  * @param list The list.
1047  * @param value The value to append to the list.
1048  *
1049  * @return 0 on success. Otherwise an error occurred.
1050  * @relatesalso as_list
1051  */
1052 static inline int as_list_append_list(as_list * list, as_list * value)
1053 {
1054  return as_list_append(list, (as_val *) value);
1055 }
1056 
1057 /**
1058  * Append an as_map to the list.
1059  *
1060  * @param list The list.
1061  * @param value The value to append to the list.
1062  *
1063  * @return 0 on success. Otherwise an error occurred.
1064  * @relatesalso as_list
1065  */
1066 static inline int as_list_append_map(as_list * list, struct as_map_s * value)
1067 {
1068  return as_list_append(list, (as_val *) value);
1069 }
1070 
1071 /******************************************************************************
1072  * PREPEND FUNCTIONS
1073  *****************************************************************************/
1074 
1075 /**
1076  * Prepend a value to the list.
1077  *
1078  * @param list The list.
1079  * @param value The value to prepend to the list.
1080  *
1081  * @return 0 on success. Otherwise an error occurred.
1082  * @relatesalso as_list
1083  */
1084 static inline int as_list_prepend(as_list * list, as_val * value)
1085 {
1086  return as_util_hook(prepend, 1, list, value);
1087 }
1088 
1089 /**
1090  * Prepend an int64_t value to the list.
1091  *
1092  * @param list The list.
1093  * @param value The value to prepend to the list.
1094  *
1095  * @return 0 on success. Otherwise an error occurred.
1096  * @relatesalso as_list
1097  */
1098 static inline int as_list_prepend_int64(as_list * list, int64_t value)
1099 {
1100  return as_util_hook(prepend_int64, 1, list, value);
1101 }
1102 
1103 /**
1104  * Prepend a NULL-terminated string to the list.
1105  *
1106  * @param list The list.
1107  * @param value The value to prepend to the list.
1108  *
1109  * @return 0 on success. Otherwise an error occurred.
1110  * @relatesalso as_list
1111  */
1112 static inline int as_list_prepend_str(as_list * list, const char * value)
1113 {
1114  return as_util_hook(prepend_str, 1, list, value);
1115 }
1116 
1117 /**
1118  * Prepend an as_integer to the list.
1119  *
1120  * @param list The list.
1121  * @param value The value to prepend to the list.
1122  *
1123  * @return 0 on success. Otherwise an error occurred.
1124  * @relatesalso as_list
1125  */
1126 static inline int as_list_prepend_integer(as_list * list, as_integer * value)
1127 {
1128  return as_list_prepend(list, (as_val *) value);
1129 }
1130 
1131 /**
1132  * Prepend an as_string to the list.
1133  *
1134  * @param list The list.
1135  * @param value The value to prepend to the list.
1136  *
1137  * @return 0 on success. Otherwise an error occurred.
1138  * @relatesalso as_list
1139  */
1140 static inline int as_list_prepend_string(as_list * list, as_string * value)
1141 {
1142  return as_list_prepend(list, (as_val *) value);
1143 }
1144 
1145 /**
1146  * Prepend an as_bytes to the list.
1147  *
1148  * @param list The list.
1149  * @param value The value to prepend to the list.
1150  *
1151  * @return 0 on success. Otherwise an error occurred.
1152  * @relatesalso as_list
1153  */
1154 static inline int as_list_prepend_bytes(as_list * list, as_bytes * value)
1155 {
1156  return as_list_prepend(list, (as_val *) value);
1157 }
1158 
1159 /**
1160  * Prepend an as_list to the list.
1161  *
1162  * @param list The list.
1163  * @param value The value to prepend to the list.
1164  *
1165  * @return 0 on success. Otherwise an error occurred.
1166  * @relatesalso as_list
1167  */
1168 static inline int as_list_prepend_list(as_list * list, as_list * value)
1169 {
1170  return as_list_prepend(list, (as_val *) value);
1171 }
1172 
1173 /**
1174  * Prepend an as_map to the list.
1175  *
1176  * @param list The list.
1177  * @param value The value to prepend to the list.
1178  *
1179  * @return 0 on success. Otherwise an error occurred.
1180  * @relatesalso as_list
1181  */
1182 static inline int as_list_prepend_map(as_list * list, struct as_map_s * value)
1183 {
1184  return as_list_prepend(list, (as_val *) value);
1185 }
1186 
1187 /******************************************************************************
1188  * REMOVE FUNCTION
1189  *****************************************************************************/
1190 
1191 /**
1192  * Remove element at specified index.
1193  *
1194  * Any elements beyond specified index will be shifted so their indexes
1195  * decrease by 1. The element at specified index will be destroyed.
1196  *
1197  * @param list The list.
1198  * @param index The index of the element to remove.
1199  *
1200  * @return 0 on success. Otherwise an error occurred.
1201  * @relatesalso as_list
1202  */
1203 static inline int as_list_remove(as_list * list, uint32_t i)
1204 {
1205  return as_util_hook(remove, 1, list, i);
1206 }
1207 
1208 /******************************************************************************
1209  * ITERATION FUNCTIONS
1210  *****************************************************************************/
1211 
1212 /**
1213  * Call the callback function for each element in the list..
1214  *
1215  * @param list The list to iterate over.
1216  * @param callback The callback function call for each element.
1217  * @param udata User-data to send to the callback.
1218  *
1219  * @return true if iteration completes fully. false if iteration was aborted.
1220  *
1221  * @relatesalso as_list
1222  */
1223 static inline bool as_list_foreach(const as_list * list, as_list_foreach_callback callback, void * udata)
1224 {
1225  return as_util_hook(foreach, false, list, callback, udata);
1226 }
1227 
1228 /**
1229  * Creates and initializes a new heap allocated iterator over the given list.
1230  *
1231  * @param list The list to iterate.
1232  *
1233  * @return On success, a new as_iterator. Otherwise NULL.
1234  * @relatesalso as_list
1235  */
1236 static inline union as_list_iterator_u * as_list_iterator_new(const as_list * list)
1237 {
1238  return as_util_hook(iterator_new, NULL, list);
1239 }
1240 
1241 
1242 /**
1243  * Initializes a stack allocated iterator over the given list.
1244  *
1245  * @param list The list to iterate.
1246  * @param it The iterator to initialize.
1247  *
1248  * @return On success, the initializes as_iterator. Otherwise NULL.
1249  * @relatesalso as_list
1250  */
1251 static inline union as_list_iterator_u * as_list_iterator_init(union as_list_iterator_u * it, const as_list * list)
1252 {
1253  return as_util_hook(iterator_init, NULL, list, it);
1254 }
1255 
1256 /******************************************************************************
1257  * CONVERSION FUNCTIONS
1258  *****************************************************************************/
1259 
1260 /**
1261  * Convert to an as_val.
1262  * @relatesalso as_list
1263  */
1264 static inline as_val * as_list_toval(as_list * list)
1265 {
1266  return (as_val *) list;
1267 }
1268 
1269 /**
1270  * Convert from an as_val.
1271  * @relatesalso as_list
1272  */
1273 static inline as_list * as_list_fromval(as_val * v)
1274 {
1275  return as_util_fromval(v, AS_LIST, as_list);
1276 }
1277 
1278 /******************************************************************************
1279  * as_val FUNCTIONS
1280  *****************************************************************************/
1281 
1282 /**
1283  * @private
1284  * Internal helper function for destroying an as_val.
1285  */
1286 void as_list_val_destroy(as_val * v);
1287 
1288 /**
1289  * @private
1290  * Internal helper function for getting the hashcode of an as_val.
1291  */
1292 uint32_t as_list_val_hashcode(const as_val * v);
1293 
1294 /**
1295  * @private
1296  * Internal helper function for getting the string representation of an as_val.
1297  */
1298 char * as_list_val_tostring(const as_val * v);
1299 
1300 #ifdef __cplusplus
1301 } // end extern "C"
1302 #endif
static void as_list_destroy(as_list *list)
Definition: as_list.h:463
static as_integer * as_integer_fromval(const as_val *v)
Definition: as_integer.h:234
static int as_list_set_string(as_list *list, uint32_t i, as_string *value)
Definition: as_list.h:778
static int as_list_append_string(as_list *list, as_string *value)
Definition: as_list.h:1024
static int as_list_set_integer(as_list *list, uint32_t i, as_integer *value)
Definition: as_list.h:763
static int as_list_set(as_list *list, uint32_t i, as_val *value)
Definition: as_list.h:718
static int as_list_insert_int64(as_list *list, uint32_t i, int64_t value)
Definition: as_list.h:860
static bool as_list_foreach(const as_list *list, as_list_foreach_callback callback, void *udata)
Definition: as_list.h:1223
static char * as_list_get_str(const as_list *list, uint32_t i)
Definition: as_list.h:627
static int as_list_set_bytes(as_list *list, uint32_t i, as_bytes *value)
Definition: as_list.h:793
static int as_list_insert(as_list *list, uint32_t i, as_val *value)
Definition: as_list.h:845
static int as_list_concat(as_list *list, const as_list *list2)
Definition: as_list.h:512
static int as_list_insert_bytes(as_list *list, uint32_t i, as_bytes *value)
Definition: as_list.h:920
static int as_list_prepend_string(as_list *list, as_string *value)
Definition: as_list.h:1140
static int as_list_insert_map(as_list *list, uint32_t i, struct as_map_s *value)
Definition: as_list.h:950
static int as_list_prepend_list(as_list *list, as_list *value)
Definition: as_list.h:1168
#define as_util_fromval(object, type_id, type)
Definition: as_util.h:42
static as_bytes * as_list_get_bytes(const as_list *list, uint32_t i)
Definition: as_list.h:669
static int64_t as_list_get_int64(const as_list *list, uint32_t i)
Definition: as_list.h:613
static int as_list_insert_str(as_list *list, uint32_t i, const char *value)
Definition: as_list.h:875
static int as_list_remove(as_list *list, uint32_t i)
Definition: as_list.h:1203
static union as_list_iterator_u * as_list_iterator_init(union as_list_iterator_u *it, const as_list *list)
Definition: as_list.h:1251
Definition: as_val.h:55
bool(* as_list_foreach_callback)(as_val *value, void *udata)
Definition: as_list.h:52
static as_integer * as_list_get_integer(const as_list *list, uint32_t i)
Definition: as_list.h:641
static int as_list_append(as_list *list, as_val *value)
Definition: as_list.h:968
static int as_list_set_map(as_list *list, uint32_t i, struct as_map_s *value)
Definition: as_list.h:823
static int as_list_prepend(as_list *list, as_val *value)
Definition: as_list.h:1084
static as_list * as_list_tail(const as_list *list)
Definition: as_list.h:553
static as_string * as_list_get_string(const as_list *list, uint32_t i)
Definition: as_list.h:655
static int as_list_insert_integer(as_list *list, uint32_t i, as_integer *value)
Definition: as_list.h:890
#define as_util_hook(hook, default, object, args...)
Definition: as_util.h:36
AS_MAP
Definition: as_val.h:212
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:1264
static int as_list_append_int64(as_list *list, int64_t value)
Definition: as_list.h:982
static int as_list_append_str(as_list *list, const char *value)
Definition: as_list.h:996
static as_val * as_list_get(const as_list *list, uint32_t i)
Definition: as_list.h:599
static int as_list_append_list(as_list *list, as_list *value)
Definition: as_list.h:1052
static union as_list_iterator_u * as_list_iterator_new(const as_list *list)
Definition: as_list.h:1236
enum as_val_t type
Definition: as_val.h:60
static as_val * as_list_head(const as_list *list)
Definition: as_list.h:540
as_val _
Definition: as_list.h:70
static uint32_t as_list_size(as_list *list)
Definition: as_list.h:493
static struct as_map_s * as_list_get_map(const as_list *list, uint32_t i)
Definition: as_list.h:698
static int as_list_prepend_bytes(as_list *list, as_bytes *value)
Definition: as_list.h:1154
static int as_list_prepend_map(as_list *list, struct as_map_s *value)
Definition: as_list.h:1182
static as_bytes * as_bytes_fromval(const as_val *v)
Definition: as_bytes.h:915
static int as_list_insert_string(as_list *list, uint32_t i, as_string *value)
Definition: as_list.h:905
void * data
Definition: as_list.h:75
static int as_list_append_bytes(as_list *list, as_bytes *value)
Definition: as_list.h:1038
static int as_list_append_integer(as_list *list, as_integer *value)
Definition: as_list.h:1010
static uint32_t as_list_hashcode(as_list *list)
Definition: as_list.h:480
static int as_list_prepend_str(as_list *list, const char *value)
Definition: as_list.h:1112
static as_list * as_list_get_list(const as_list *list, uint32_t i)
Definition: as_list.h:683
static as_string * as_string_fromval(const as_val *v)
Definition: as_string.h:296
static int as_list_set_int64(as_list *list, uint32_t i, int64_t value)
Definition: as_list.h:733
static int as_list_insert_list(as_list *list, uint32_t i, as_list *value)
Definition: as_list.h:935
static as_list * as_list_fromval(as_val *v)
Definition: as_list.h:1273
static int as_list_prepend_int64(as_list *list, int64_t value)
Definition: as_list.h:1098
uint8_t data[]
Definition: as_proto.h:767
static as_list * as_list_drop(const as_list *list, uint32_t n)
Definition: as_list.h:567
as_list * as_list_new(void *data, const as_list_hooks *hooks)
AS_LIST
Definition: as_val.h:211
#define as_val_destroy(__v)
Definition: as_val.h:108
const struct as_list_hooks_s * hooks
Definition: as_list.h:80
static int as_list_trim(as_list *list, uint32_t index)
Definition: as_list.h:527
uint32_t as_list_val_hashcode(const as_val *v)
static int as_list_append_map(as_list *list, struct as_map_s *value)
Definition: as_list.h:1066
static int as_list_set_str(as_list *list, uint32_t i, const char *value)
Definition: as_list.h:748
char * as_list_val_tostring(const as_val *v)
static int as_list_set_list(as_list *list, uint32_t i, as_list *value)
Definition: as_list.h:808
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:581
static int as_list_prepend_integer(as_list *list, as_integer *value)
Definition: as_list.h:1126