2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "maps_error.h"
19 #include "maps_extra_types.h"
20 #include "maps_util.h"
21 #include "maps_condition.h"
23 typedef struct _maps_item_list_s
28 EXPORT_API int maps_item_list_create(maps_item_list_h *list)
30 if (!maps_condition_check_maps_feature())
31 return MAPS_ERROR_NOT_SUPPORTED;
33 return MAPS_ERROR_INVALID_PARAMETER;
34 maps_item_list_s *l = g_slice_new0(maps_item_list_s);
38 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
39 return MAPS_ERROR_OUT_OF_MEMORY;
45 *list = (maps_item_list_h *) l;
46 return MAPS_ERROR_NONE;
49 EXPORT_API int maps_item_list_destroy(maps_item_list_h list)
51 if (!maps_condition_check_maps_feature())
52 return MAPS_ERROR_NOT_SUPPORTED;
54 return MAPS_ERROR_INVALID_PARAMETER;
55 maps_item_list_s *l = (maps_item_list_s *) list;
58 g_slice_free(maps_item_list_s, l);
59 return MAPS_ERROR_NONE;
62 EXPORT_API int maps_item_list_append(maps_item_list_h list, const void *data,
63 maps_item_list_clone_cb clone_func)
65 if (!maps_condition_check_maps_feature())
66 return MAPS_ERROR_NOT_SUPPORTED;
68 return MAPS_ERROR_INVALID_PARAMETER;
71 const int error = clone_func((void *) data, &p);
72 if (error != MAPS_ERROR_NONE)
77 maps_item_list_s *l = (maps_item_list_s *) list;
78 l->l = g_list_append(l->l, (gpointer) p);
79 return MAPS_ERROR_NONE;
82 EXPORT_API int maps_item_list_foreach(maps_item_list_h list,
83 maps_item_list_clone_cb clone_func,
84 maps_item_list_foreach_cb callback,
87 if (!maps_condition_check_maps_feature())
88 return MAPS_ERROR_NOT_SUPPORTED;
89 if (!list || !callback)
90 return MAPS_ERROR_INVALID_PARAMETER;
91 maps_item_list_s *l = (maps_item_list_s *) list;
93 return MAPS_ERROR_NOT_FOUND;
95 const int total = g_list_length(l->l);
96 GList *head = g_list_first(l->l);
99 void *data = head->data;
103 if (clone_func(data, &clone) != MAPS_ERROR_NONE)
104 continue; //LCOV_EXCL_LINE
108 if (!callback(index++, total, clone, user_data))
112 return MAPS_ERROR_NONE;
115 EXPORT_API int maps_item_list_remove(maps_item_list_h list,
117 maps_item_list_free_cb free_func)
119 if (!maps_condition_check_maps_feature())
120 return MAPS_ERROR_NOT_SUPPORTED;
122 return MAPS_ERROR_INVALID_PARAMETER;
123 maps_item_list_s *l = (maps_item_list_s *) list;
125 l->l = g_list_remove(l->l, item);
129 return MAPS_ERROR_NONE;
132 EXPORT_API int maps_item_list_foreach_noclone(maps_item_list_h list, maps_item_list_foreach_noclone_cb callback, void *user_data)
134 if (!maps_condition_check_maps_feature())
135 return MAPS_ERROR_NOT_SUPPORTED;
136 if (!list || !callback)
137 return MAPS_ERROR_INVALID_PARAMETER;
138 maps_item_list_s *l = (maps_item_list_s *) list;
141 return MAPS_ERROR_NOT_FOUND;
143 GList *head = g_list_first(l->l);
146 void *data = head->data;
148 if (!callback(index++, data, user_data))
151 return MAPS_ERROR_NONE;
154 EXPORT_API int maps_item_list_remove_all(maps_item_list_h list,
155 maps_item_list_free_cb free_func)
157 if (!maps_condition_check_maps_feature())
158 return MAPS_ERROR_NOT_SUPPORTED;
160 return MAPS_ERROR_INVALID_PARAMETER;
162 maps_item_list_s *l = (maps_item_list_s *) list;
164 GList *head = g_list_first(l->l);
167 free_func(head->data);
174 return MAPS_ERROR_NONE;
177 EXPORT_API int maps_item_list_clone(const maps_item_list_h origin,
178 maps_item_list_clone_cb clone_func,
179 maps_item_list_h *cloned)
181 if (!maps_condition_check_maps_feature())
182 return MAPS_ERROR_NOT_SUPPORTED;
183 if (!cloned || !origin || !clone_func)
184 return MAPS_ERROR_INVALID_PARAMETER;
186 int error = MAPS_ERROR_NONE;
188 error = maps_item_list_create(cloned);
189 if (!(*cloned) || (error != MAPS_ERROR_NONE))
192 maps_item_list_s *l = (maps_item_list_s *) origin;
194 return MAPS_ERROR_NONE;
196 maps_item_list_s *l_cloned = (maps_item_list_s *) (*cloned);
198 /* It would be cool when we will have glib v 2.34 */
199 /*l_cloned->l = g_list_copy_deep(l->l, clone_func, NULL); */
201 GList *head = g_list_first(l->l);
203 void *cloned_item = NULL;
204 const int error = clone_func(head->data, &cloned_item);
205 if (error == MAPS_ERROR_NONE)
207 g_list_append(l_cloned->l,
208 (gpointer) cloned_item);
211 return MAPS_ERROR_NONE;
215 maps_item_list_destroy(*cloned);
221 EXPORT_API int maps_item_list_get_length(maps_item_list_h list, int *length)
223 if (!maps_condition_check_maps_feature())
224 return MAPS_ERROR_NOT_SUPPORTED;
225 if (!list || !length)
226 return MAPS_ERROR_INVALID_PARAMETER;
227 maps_item_list_s *l = (maps_item_list_s *)list;
231 *length = g_list_length(l->l);
232 return MAPS_ERROR_NONE;
235 /*----------------------------------------------------------------------------*/
237 typedef struct _maps_string_hashtable_s
240 } maps_string_hashtable_s;
242 EXPORT_API int maps_string_hashtable_create(maps_string_hashtable_h *table)
244 if (!maps_condition_check_maps_feature())
245 return MAPS_ERROR_NOT_SUPPORTED;
247 return MAPS_ERROR_INVALID_PARAMETER;
249 maps_string_hashtable_s *t = g_slice_new0(maps_string_hashtable_s);
252 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
253 return MAPS_ERROR_OUT_OF_MEMORY;
257 t->t = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
259 return MAPS_ERROR_NONE;
262 EXPORT_API int maps_string_hashtable_destroy(maps_string_hashtable_h table)
264 if (!maps_condition_check_maps_feature())
265 return MAPS_ERROR_NOT_SUPPORTED;
267 return MAPS_ERROR_INVALID_PARAMETER;
268 maps_string_hashtable_s *t = (maps_string_hashtable_s *) table;
270 g_hash_table_unref(t->t);
271 g_slice_free(maps_string_hashtable_s, t);
272 return MAPS_ERROR_NONE;
275 EXPORT_API int maps_string_hashtable_set(maps_string_hashtable_h table,
276 const char *key, const char *value)
278 if (!maps_condition_check_maps_feature())
279 return MAPS_ERROR_NOT_SUPPORTED;
280 if (!table || !key || !value)
281 return MAPS_ERROR_INVALID_PARAMETER;
282 maps_string_hashtable_s *t = (maps_string_hashtable_s *) table;
284 g_hash_table_insert(t->t, (gpointer) g_strdup(key),
285 (gpointer) g_strdup(value));
286 return MAPS_ERROR_NONE;
289 EXPORT_API int maps_string_hashtable_get(maps_string_hashtable_h table,
290 const char *key, char **value)
292 if (!maps_condition_check_maps_feature())
293 return MAPS_ERROR_NOT_SUPPORTED;
294 if (!table || !key || !value)
295 return MAPS_ERROR_INVALID_PARAMETER;
296 maps_string_hashtable_s *t = (maps_string_hashtable_s *) table;
298 return MAPS_ERROR_NOT_FOUND;
299 char *table_value = (char *) g_hash_table_lookup(t->t, key);
301 return MAPS_ERROR_NONE;
302 return maps_get_string(table_value, strlen(table_value), value);
305 EXPORT_API int maps_string_hashtable_remove(maps_string_hashtable_h table,
308 if (!maps_condition_check_maps_feature())
309 return MAPS_ERROR_NOT_SUPPORTED;
311 return MAPS_ERROR_INVALID_PARAMETER;
312 maps_string_hashtable_s *t = (maps_string_hashtable_s *) table;
314 g_hash_table_remove(t->t, (gpointer) key);
315 return MAPS_ERROR_NONE;
318 EXPORT_API int maps_string_hashtable_foreach(maps_string_hashtable_h table,
319 maps_string_hashtable_foreach_cb
323 if (!maps_condition_check_maps_feature())
324 return MAPS_ERROR_NOT_SUPPORTED;
325 if (!table || !callback)
326 return MAPS_ERROR_INVALID_PARAMETER;
327 maps_string_hashtable_s *t = (maps_string_hashtable_s *) table;
330 return MAPS_ERROR_NOT_FOUND;
334 const int total = g_hash_table_size(t->t);
336 g_hash_table_iter_init(&iter, t->t);
337 while (g_hash_table_iter_next(&iter, &key, &value)) {
338 char *key_clone = NULL;
339 if (maps_item_hashtable_clone_string(key,
340 (void **) &key_clone) != MAPS_ERROR_NONE)
341 continue; //LCOV_EXCL_LINE
342 char *value_clone = NULL;
343 if (maps_item_hashtable_clone_string(value,
344 (void **) &value_clone) != MAPS_ERROR_NONE)
345 continue; //LCOV_EXCL_LINE
347 if (!callback(index++, total, key_clone, value_clone,
351 return MAPS_ERROR_NONE;
354 EXPORT_API int maps_string_hashtable_clone(const maps_string_hashtable_h origin,
355 maps_string_hashtable_h *cloned)
357 if (!maps_condition_check_maps_feature())
358 return MAPS_ERROR_NOT_SUPPORTED;
359 if (!cloned || !origin)
360 return MAPS_ERROR_INVALID_PARAMETER;
362 int error = MAPS_ERROR_NONE;
364 error = maps_string_hashtable_create(cloned);
365 if (!(*cloned) || (error != MAPS_ERROR_NONE))
368 maps_string_hashtable_s *t = (maps_string_hashtable_s *) origin;
371 return MAPS_ERROR_NONE;
373 maps_string_hashtable_s *t_cloned =
374 (maps_string_hashtable_s *) (*cloned);
378 g_hash_table_iter_init(&iter, t->t);
379 while (g_hash_table_iter_next(&iter, &key, &value)) {
380 g_hash_table_insert(t_cloned->t,
382 (gpointer) g_strdup((const gchar *) key),
383 (gpointer) g_strdup((const gchar *) value));
387 return MAPS_ERROR_NONE;
391 maps_string_hashtable_destroy(*cloned);
397 EXPORT_API int maps_string_hashtable_contains(maps_string_hashtable_h table,
398 const char * key, bool * contains)
400 if (!maps_condition_check_maps_feature())
401 return MAPS_ERROR_NOT_SUPPORTED;
402 if (!table || !key || !contains)
403 return MAPS_ERROR_INVALID_PARAMETER;
404 maps_string_hashtable_s *t = (maps_string_hashtable_s *) table;
406 *contains = g_hash_table_contains(t->t, (gpointer) key);
407 return MAPS_ERROR_NONE;
410 /*----------------------------------------------------------------------------*/
411 typedef struct _maps_int_hashtable_s
414 } maps_int_hashtable_s;
416 EXPORT_API int maps_int_hashtable_create(maps_int_hashtable_h *table)
418 if (!maps_condition_check_maps_feature())
419 return MAPS_ERROR_NOT_SUPPORTED;
421 return MAPS_ERROR_INVALID_PARAMETER;
422 maps_int_hashtable_s *t = g_slice_new0(maps_int_hashtable_s);
426 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
427 return MAPS_ERROR_OUT_OF_MEMORY;
431 t->t = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free);
433 return MAPS_ERROR_NONE;
436 EXPORT_API int maps_int_hashtable_destroy(maps_int_hashtable_h table)
438 if (!maps_condition_check_maps_feature())
439 return MAPS_ERROR_NOT_SUPPORTED;
441 return MAPS_ERROR_INVALID_PARAMETER;
442 maps_int_hashtable_s *t = (maps_int_hashtable_s *) table;
444 g_hash_table_unref(t->t);
445 g_slice_free(maps_int_hashtable_s, t);
446 return MAPS_ERROR_NONE;
449 EXPORT_API int maps_int_hashtable_set(maps_int_hashtable_h table,
450 const int key, const int value)
452 if (!maps_condition_check_maps_feature())
453 return MAPS_ERROR_NOT_SUPPORTED;
455 return MAPS_ERROR_INVALID_PARAMETER;
456 maps_int_hashtable_s *t = (maps_int_hashtable_s *) table;
458 int *new_key = g_new0(int, 1);
460 int *new_value = g_new0(int, 1);
462 g_hash_table_insert(t->t,
464 (gpointer)new_value);
466 return MAPS_ERROR_NONE;
469 EXPORT_API int maps_int_hashtable_get(maps_int_hashtable_h table,
470 const int key, int *value)
472 if (!maps_condition_check_maps_feature())
473 return MAPS_ERROR_NOT_SUPPORTED;
474 if (!table || !value)
475 return MAPS_ERROR_INVALID_PARAMETER;
476 maps_int_hashtable_s *t = (maps_int_hashtable_s *) table;
478 return MAPS_ERROR_NOT_FOUND; //LCOV_EXCL_LINE
479 const int *table_value = (const int *) g_hash_table_lookup(t->t, &key);
481 return MAPS_ERROR_NONE;
482 *value = *table_value;
483 return MAPS_ERROR_NONE;
486 EXPORT_API int maps_int_hashtable_remove(maps_int_hashtable_h table,
489 if (!maps_condition_check_maps_feature())
490 return MAPS_ERROR_NOT_SUPPORTED;
492 return MAPS_ERROR_INVALID_PARAMETER;
493 maps_int_hashtable_s *t = (maps_int_hashtable_s *) table;
495 g_hash_table_remove(t->t, (gpointer) &key);
496 return MAPS_ERROR_NONE;
499 EXPORT_API int maps_int_hashtable_foreach(maps_int_hashtable_h table,
500 maps_int_hashtable_foreach_cb callback,
503 if (!maps_condition_check_maps_feature())
504 return MAPS_ERROR_NOT_SUPPORTED;
505 if (!table || !callback)
506 return MAPS_ERROR_INVALID_PARAMETER;
507 maps_int_hashtable_s *t = (maps_int_hashtable_s *) table;
510 return MAPS_ERROR_NOT_FOUND; //LCOV_EXCL_LINE
514 const int total = g_hash_table_size(t->t);
516 g_hash_table_iter_init(&iter, t->t);
517 while (g_hash_table_iter_next(&iter, &key, &value)) {
521 int *key_ptr = (int *)key;
522 int *value_ptr = (int *)value;
523 if (!callback(index++, total, *key_ptr, *value_ptr, user_data))
526 return MAPS_ERROR_NONE;
529 EXPORT_API int maps_int_hashtable_clone(const maps_int_hashtable_h origin,
530 maps_int_hashtable_h *cloned)
532 if (!maps_condition_check_maps_feature())
533 return MAPS_ERROR_NOT_SUPPORTED;
534 if (!cloned || !origin)
535 return MAPS_ERROR_INVALID_PARAMETER;
537 int error = MAPS_ERROR_NONE;
539 error = maps_int_hashtable_create(cloned);
540 if (!(*cloned) || (error != MAPS_ERROR_NONE))
543 maps_int_hashtable_s *t = (maps_int_hashtable_s *) origin;
546 return MAPS_ERROR_NONE;
548 maps_int_hashtable_s *t_cloned =
549 (maps_int_hashtable_s *) (*cloned);
553 g_hash_table_iter_init(&iter, t->t);
554 while (g_hash_table_iter_next(&iter, &key, &value)) {
555 int *new_key = g_new0(int, 1);
556 *new_key = *((int *)key);
557 int *new_value = g_new0(int, 1);
558 *new_value = *((int *)value);
559 g_hash_table_insert(t_cloned->t,
561 (gpointer) new_value);
564 return MAPS_ERROR_NONE;
568 maps_int_hashtable_destroy(*cloned);
574 EXPORT_API int maps_int_hashtable_contains(maps_int_hashtable_h table,
575 const int key, bool *contains)
577 if (!maps_condition_check_maps_feature())
578 return MAPS_ERROR_NOT_SUPPORTED;
579 if (!table || !contains)
580 return MAPS_ERROR_INVALID_PARAMETER;
581 maps_int_hashtable_s *t = (maps_int_hashtable_s *) table;
583 *contains = g_hash_table_contains(t->t, (gpointer)&key);
584 return MAPS_ERROR_NONE;
587 /*----------------------------------------------------------------------------*/
589 typedef struct _maps_hashtable_item_s
592 maps_item_hashtable_clone_cb clone_func;
593 maps_item_hashtable_free_cb free_func;
594 } maps_hashtable_item_s;
596 void _maps_hashtable_item_create(maps_hashtable_item_s **item)
598 *item = g_slice_new0(maps_hashtable_item_s);
601 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY); //LCOV_EXCL_LINE
604 void _maps_hashtable_item_destroy(gpointer data)
609 maps_hashtable_item_s *item = (maps_hashtable_item_s *) data;
610 if (item && item->value && item->free_func)
611 item->free_func(item->value);
613 g_slice_free(maps_hashtable_item_s, item);
616 /*----------------------------------------------------------------------------*/
618 typedef struct _maps_item_hashtable_s
621 } maps_item_hashtable_s;
623 EXPORT_API int maps_item_hashtable_create(maps_item_hashtable_h *table)
625 if (!maps_condition_check_maps_feature())
626 return MAPS_ERROR_NOT_SUPPORTED;
628 return MAPS_ERROR_INVALID_PARAMETER;
629 maps_item_hashtable_s *t = g_slice_new0(maps_item_hashtable_s);
633 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
634 return MAPS_ERROR_OUT_OF_MEMORY;
638 t->t = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
639 _maps_hashtable_item_destroy);
641 return MAPS_ERROR_NONE;
644 EXPORT_API int maps_item_hashtable_destroy(maps_item_hashtable_h table)
646 if (!maps_condition_check_maps_feature())
647 return MAPS_ERROR_NOT_SUPPORTED;
649 return MAPS_ERROR_INVALID_PARAMETER;
650 maps_item_hashtable_s *t = (maps_item_hashtable_s *) table;
652 g_hash_table_unref(t->t);
653 g_slice_free(maps_item_hashtable_s, t);
654 return MAPS_ERROR_NONE;
657 EXPORT_API int maps_item_hashtable_clone_string(void *origin, void **cloned)
659 if (!maps_condition_check_maps_feature())
660 return MAPS_ERROR_NOT_SUPPORTED;
661 if (!origin || !cloned)
662 return MAPS_ERROR_INVALID_PARAMETER;
663 return maps_get_string((char *) origin, strlen((char *) origin),
667 EXPORT_API int maps_item_hashtable_free_string(void *data)
669 if (!maps_condition_check_maps_feature())
670 return MAPS_ERROR_NOT_SUPPORTED;
672 return MAPS_ERROR_NONE;
675 EXPORT_API int maps_item_hashtable_clone_int(void *origin, void **cloned)
677 if (!maps_condition_check_maps_feature())
678 return MAPS_ERROR_NOT_SUPPORTED;
679 if (!origin || !cloned)
680 return MAPS_ERROR_INVALID_PARAMETER;
681 int *n_cloned = g_new0(int, 1);
683 if (n_cloned == NULL) {
685 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
686 return MAPS_ERROR_OUT_OF_MEMORY;
690 int *n_origin = (int *) origin;
691 *n_cloned = *n_origin;
693 return MAPS_ERROR_NONE;
696 EXPORT_API int maps_item_hashtable_free_int(void *data)
698 if (!maps_condition_check_maps_feature())
699 return MAPS_ERROR_NOT_SUPPORTED;
701 return MAPS_ERROR_NONE;
704 EXPORT_API int maps_item_hashtable_clone_float(void *origin, void **cloned)
706 if (!maps_condition_check_maps_feature())
707 return MAPS_ERROR_NOT_SUPPORTED;
708 if (!origin || !cloned)
709 return MAPS_ERROR_INVALID_PARAMETER;
710 double *n_cloned = g_new0(double, 1);
712 if (n_cloned == NULL) {
714 MAPS_LOGE("OUT_OF_MEMORY(0x%08x)", MAPS_ERROR_OUT_OF_MEMORY);
715 return MAPS_ERROR_OUT_OF_MEMORY;
719 double *n_origin = (double *) origin;
720 *n_cloned = *n_origin;
722 return MAPS_ERROR_NONE;
725 EXPORT_API int maps_item_hashtable_free_float(void *data)
727 if (!maps_condition_check_maps_feature())
728 return MAPS_ERROR_NOT_SUPPORTED;
730 return MAPS_ERROR_NONE;
733 EXPORT_API int maps_item_hashtable_set_string(maps_item_hashtable_h table,
737 if (!maps_condition_check_maps_feature())
738 return MAPS_ERROR_NOT_SUPPORTED;
739 return maps_item_hashtable_set(table, key, value,
740 maps_item_hashtable_clone_string,
741 maps_item_hashtable_free_string);
744 EXPORT_API int maps_item_hashtable_set_int(maps_item_hashtable_h table,
745 const char *key, const int value)
747 if (!maps_condition_check_maps_feature())
748 return MAPS_ERROR_NOT_SUPPORTED;
749 return maps_item_hashtable_set(table, key, &value,
750 maps_item_hashtable_clone_int, maps_item_hashtable_free_int);
753 EXPORT_API int maps_item_hashtable_set_float(maps_item_hashtable_h table,
757 if (!maps_condition_check_maps_feature())
758 return MAPS_ERROR_NOT_SUPPORTED;
759 return maps_item_hashtable_set(table, key, &value,
760 maps_item_hashtable_clone_float,
761 maps_item_hashtable_free_float);
764 EXPORT_API int maps_item_hashtable_set(maps_item_hashtable_h table,
765 const char *key, const void *value,
766 maps_item_hashtable_clone_cb clone_func,
767 maps_item_hashtable_free_cb free_func)
769 if (!maps_condition_check_maps_feature())
770 return MAPS_ERROR_NOT_SUPPORTED;
771 if (!table || !key || !value || !clone_func || !free_func)
772 return MAPS_ERROR_INVALID_PARAMETER;
773 maps_item_hashtable_s *t = (maps_item_hashtable_s *) table;
776 maps_hashtable_item_s *item = NULL;
777 _maps_hashtable_item_create(&item);
779 const int error = clone_func((void *) value, &item->value);
780 if (error != MAPS_ERROR_NONE) {
782 _maps_hashtable_item_destroy(item);
786 item->clone_func = clone_func;
787 item->free_func = free_func;
789 g_hash_table_insert(t->t, (gpointer) g_strdup(key),
793 return MAPS_ERROR_NONE;
796 EXPORT_API int maps_item_hashtable_get_string(maps_item_hashtable_h table,
797 const char *key, char **value)
799 if (!maps_condition_check_maps_feature())
800 return MAPS_ERROR_NOT_SUPPORTED;
801 return maps_item_hashtable_get(table, key, (void **) value);
804 EXPORT_API int maps_item_hashtable_get_int(maps_item_hashtable_h table,
805 const char *key, int *value)
807 if (!maps_condition_check_maps_feature())
808 return MAPS_ERROR_NOT_SUPPORTED;
809 if (!table || !key || !value)
810 return MAPS_ERROR_INVALID_PARAMETER;
812 const int error = maps_item_hashtable_get(table, key, (void **) &data);
813 if (error == MAPS_ERROR_NONE) {
815 maps_item_hashtable_free_int(data);
820 EXPORT_API int maps_item_hashtable_get_float(maps_item_hashtable_h table,
821 const char *key, double *value)
823 if (!maps_condition_check_maps_feature())
824 return MAPS_ERROR_NOT_SUPPORTED;
825 if (!table || !key || !value)
826 return MAPS_ERROR_INVALID_PARAMETER;
828 const int error = maps_item_hashtable_get(table, key, (void **) &data);
829 if (error == MAPS_ERROR_NONE) {
831 maps_item_hashtable_free_float(data);
836 EXPORT_API int maps_item_hashtable_get(maps_item_hashtable_h table,
837 const char *key, void **value)
839 if (!maps_condition_check_maps_feature())
840 return MAPS_ERROR_NOT_SUPPORTED;
841 if (!table || !key || !value)
842 return MAPS_ERROR_INVALID_PARAMETER;
843 maps_item_hashtable_s *t = (maps_item_hashtable_s *) table;
845 return MAPS_ERROR_NOT_FOUND;
846 maps_hashtable_item_s *item =
847 (maps_hashtable_item_s *) g_hash_table_lookup(t->t, key);
848 if (!item || !item->clone_func)
849 return MAPS_ERROR_NOT_FOUND;
850 return item->clone_func(item->value, value);
853 EXPORT_API int maps_item_hashtable_remove(maps_item_hashtable_h table,
856 if (!maps_condition_check_maps_feature())
857 return MAPS_ERROR_NOT_SUPPORTED;
859 return MAPS_ERROR_INVALID_PARAMETER;
860 maps_item_hashtable_s *t = (maps_item_hashtable_s *) table;
862 g_hash_table_remove(t->t, (gpointer) key);
863 return MAPS_ERROR_NONE;
866 EXPORT_API int maps_item_hashtable_foreach(maps_item_hashtable_h table,
867 maps_item_hashtable_foreach_cb
871 if (!maps_condition_check_maps_feature())
872 return MAPS_ERROR_NOT_SUPPORTED;
873 if (!table || !callback)
874 return MAPS_ERROR_INVALID_PARAMETER;
875 maps_item_hashtable_s *t = (maps_item_hashtable_s *) table;
877 return MAPS_ERROR_NOT_FOUND;
881 const int total = g_hash_table_size(t->t);
883 g_hash_table_iter_init(&iter, t->t);
884 while (g_hash_table_iter_next(&iter, &key, &value)) {
885 maps_hashtable_item_s *item = (maps_hashtable_item_s *) value;
886 if (!item || !item->clone_func)
887 continue; //LCOV_EXCL_LINE
889 char *key_clone = NULL;
890 if (maps_item_hashtable_clone_string(key,
891 (void **) &key_clone) != MAPS_ERROR_NONE)
893 void *value_clone = NULL;
894 if (item->clone_func(item->value,
895 &value_clone) != MAPS_ERROR_NONE)
898 if (!callback(index++, total, key_clone, value_clone,
903 return MAPS_ERROR_NONE;
906 EXPORT_API int maps_item_hashtable_clone(const maps_item_hashtable_h origin,
907 maps_item_hashtable_h* cloned)
909 if (!maps_condition_check_maps_feature())
910 return MAPS_ERROR_NOT_SUPPORTED;
911 if (!cloned || !origin)
912 return MAPS_ERROR_INVALID_PARAMETER;
914 int error = MAPS_ERROR_NONE;
916 error = maps_item_hashtable_create(cloned);
917 if (!(*cloned) || (error != MAPS_ERROR_NONE))
920 maps_item_hashtable_s *t = (maps_item_hashtable_s *) origin;
923 return MAPS_ERROR_NONE;
927 g_hash_table_iter_init(&iter, t->t);
928 while (g_hash_table_iter_next(&iter, &key, &value)) {
929 maps_hashtable_item_s *item =
930 (maps_hashtable_item_s *) value;
933 maps_item_hashtable_set(*cloned, (const char *) key,
934 (const void *) item->value, item->clone_func,
938 return MAPS_ERROR_NONE;
942 maps_item_hashtable_destroy(*cloned);
948 EXPORT_API int maps_item_hashtable_contains(maps_item_hashtable_h table,
949 const char *key, bool *contains)
951 if (!maps_condition_check_maps_feature())
952 return MAPS_ERROR_NOT_SUPPORTED;
953 if (!table || !key || !contains)
954 return MAPS_ERROR_INVALID_PARAMETER;
955 maps_item_hashtable_s *t = (maps_item_hashtable_s *) table;
957 *contains = g_hash_table_contains(t->t, (gpointer) key);
958 return MAPS_ERROR_NONE;