|
libcollection 0.5.0
|
00001 /* 00002 COLLECTION LIBRARY 00003 00004 Header file for collection interface. 00005 00006 Copyright (C) Dmitri Pal <dpal@redhat.com> 2009 00007 00008 Collection Library is free software: you can redistribute it and/or modify 00009 it under the terms of the GNU Lesser General Public License as published by 00010 the Free Software Foundation, either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 Collection Library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public License 00019 along with Collection Library. If not, see <http://www.gnu.org/licenses/>. 00020 */ 00021 00022 #ifndef COLLECTION_H 00023 #define COLLECTION_H 00024 00025 #include <stdint.h> 00026 00108 #ifndef EOK 00109 #define EOK 0 00110 #endif 00111 00120 #define COL_CLASS_DEFAULT 0 00121 00127 #define COL_NOMATCH 0 00128 00133 #define COL_MATCH 1 00134 00135 00145 #define COL_TYPE_STRING 0x00000001 00146 00147 #define COL_TYPE_BINARY 0x00000002 00148 00149 #define COL_TYPE_INTEGER 0x00000004 00150 00151 #define COL_TYPE_UNSIGNED 0x00000008 00152 00153 #define COL_TYPE_LONG 0x00000010 00154 00155 #define COL_TYPE_ULONG 0x00000020 00156 00157 #define COL_TYPE_DOUBLE 0x00000040 00158 00159 #define COL_TYPE_BOOL 0x00000080 00160 00166 #define COL_TYPE_COLLECTION 0x00000100 00167 00173 #define COL_TYPE_COLLECTIONREF 0x00000200 00174 00179 #define COL_TYPE_END 0x10000000 00180 00186 #define COL_TYPE_ANY 0x0FFFFFFF 00187 00200 #define COL_ADD_MODE_REFERENCE 0 00201 00211 #define COL_ADD_MODE_EMBED 1 00212 00217 #define COL_ADD_MODE_CLONE 2 00218 00225 #define COL_ADD_MODE_FLAT 3 00226 00238 #define COL_ADD_MODE_FLATDOT 4 00239 00261 #define COL_TRAVERSE_DEFAULT 0x00000000 00262 00269 #define COL_TRAVERSE_ONELEVEL 0x00000001 00270 00280 #define COL_TRAVERSE_END 0x00000002 00281 00282 #define COL_TRAVERSE_IGNORE 0x00000004 00283 00296 #define COL_TRAVERSE_FLAT 0x00000008 00297 00322 #define COL_TRAVERSE_SHOWSUB 0x00010000 00323 00330 #define COL_TRAVERSE_ONLYSUB 0x00020000 00331 00353 #define COL_COPY_NORMAL 0 00354 00359 #define COL_COPY_FLAT 1 00360 00365 #define COL_COPY_FLATDOT 2 00366 00367 #define COL_COPY_KEEPREF 3 00368 00369 #define COL_COPY_TOP 4 00370 00385 #define COL_SORT_ASC 0x00000000 00386 00387 #define COL_SORT_DESC 0x00000001 00388 00389 #define COL_SORT_SUB 0x00000002 00390 00395 #define COL_SORT_MYSUB 0x00000004 00396 00401 /* Public declaration of the private data */ 00402 #ifndef COLLECTION_PRIV_H 00403 00418 struct collection_item; 00431 struct collection_iterator; 00432 00433 #endif /* COLLECTION_PRIV_H */ 00434 00435 00472 int col_create_collection(struct collection_item **ci, 00473 const char *name, 00474 unsigned cclass); 00475 00484 void col_destroy_collection(struct collection_item *ci); 00485 00507 typedef void (*col_item_cleanup_fn)(const char *property, 00508 int property_len, 00509 int type, 00510 void *data, 00511 int length, 00512 void *custom_data); 00513 00535 void col_destroy_collection_with_cb(struct collection_item *ci, 00536 col_item_cleanup_fn cb, 00537 void *custom_data); 00538 00563 typedef int (*col_copy_cb)(struct collection_item *item, 00564 void *ext_data, 00565 int *skip); 00566 00593 int col_copy_collection_with_cb(struct collection_item **col_copy, 00594 struct collection_item *col_to_copy, 00595 const char *name_to_use, 00596 int copy_mode, 00597 col_copy_cb copy_cb, 00598 void *ext_data); 00599 00617 int col_copy_collection(struct collection_item **col_copy, 00618 struct collection_item *col_to_copy, 00619 const char *name_to_use, 00620 int copy_mode); 00621 00653 int col_add_collection_to_collection(struct collection_item *ci, 00654 const char *subcollection, 00655 const char *as_property, 00656 struct collection_item *ci_to_add, 00657 int mode); 00684 typedef int (*col_item_fn)(const char *property, 00685 int property_len, 00686 int type, 00687 void *data, 00688 int length, 00689 void *custom_data, 00690 int *stop); 00691 00713 int col_traverse_collection(struct collection_item *ci, 00714 int mode_flags, 00715 col_item_fn item_handler, 00716 void *custom_data); 00717 00752 int col_get_item_and_do(struct collection_item *ci, 00753 const char *property_to_find, 00754 int type, 00755 int mode_flags, 00756 col_item_fn item_handler, 00757 void *custom_data); 00758 00797 int col_get_item(struct collection_item *ci, 00798 const char *property_to_find, 00799 int type, 00800 int mode_flags, 00801 struct collection_item **item); 00802 00845 int col_get_dup_item(struct collection_item *ci, 00846 const char *subcollection, 00847 const char *property_to_find, 00848 int type, 00849 int idx, 00850 int exact, 00851 struct collection_item **item); 00852 00882 int col_sort_collection(struct collection_item *col, 00883 unsigned cmp_flags, 00884 unsigned sort_flags); 00885 00917 int col_delete_property(struct collection_item *ci, 00918 const char *property_to_find, 00919 int type, 00920 int mode_flags); 00921 00946 int col_is_item_in_collection(struct collection_item *ci, 00947 const char *property_to_find, 00948 int type, 00949 int mode_flags, 00950 int *found); 00951 00973 int col_get_collection_reference(struct collection_item *ci, 00974 struct collection_item **acceptor, 00975 const char *col_to_find); 00976 00996 int col_get_reference_from_item(struct collection_item *item, 00997 struct collection_item **acceptor); 00998 00999 01000 01029 int col_get_collection_class(struct collection_item *ci, 01030 unsigned *cclass); 01031 01045 int col_set_collection_class(struct collection_item *ci, 01046 unsigned cclass); 01047 01066 int col_get_collection_count(struct collection_item *ci, 01067 unsigned *count); 01068 01069 01083 int col_is_of_class(struct collection_item *ci, 01084 unsigned cclass); 01085 01086 01159 int col_add_str_property(struct collection_item *ci, 01160 const char *subcollection, 01161 const char *property, 01162 const char *string, 01163 int length); 01164 01191 int col_add_binary_property(struct collection_item *ci, 01192 const char *subcollection, 01193 const char *property, 01194 void *binary_data, 01195 int length); 01196 01222 int col_add_int_property(struct collection_item *ci, 01223 const char *subcollection, 01224 const char *property, 01225 int32_t number); 01226 01252 int col_add_unsigned_property(struct collection_item *ci, 01253 const char *subcollection, 01254 const char *property, 01255 uint32_t number); 01256 01282 int col_add_long_property(struct collection_item *ci, 01283 const char *subcollection, 01284 const char *property, 01285 int64_t number); 01286 01312 int col_add_ulong_property(struct collection_item *ci, 01313 const char *subcollection, 01314 const char *property, 01315 uint64_t number); 01316 01342 int col_add_double_property(struct collection_item *ci, 01343 const char *subcollection, 01344 const char *property, 01345 double number); 01371 int col_add_bool_property(struct collection_item *ci, 01372 const char *subcollection, 01373 const char *property, 01374 unsigned char logical); 01375 01376 01404 int col_add_any_property(struct collection_item *ci, 01405 const char *subcollection, 01406 const char *property, 01407 int type, 01408 void *data, 01409 int length); 01410 01470 int col_add_str_property_with_ref(struct collection_item *ci, 01471 const char *subcollection, 01472 const char *property, 01473 char *string, int length, 01474 struct collection_item **ret_ref); 01475 01504 int col_add_binary_property_with_ref(struct collection_item *ci, 01505 const char *subcollection, 01506 const char *property, 01507 void *binary_data, int length, 01508 struct collection_item **ret_ref); 01509 01537 int col_add_int_property_with_ref(struct collection_item *ci, 01538 const char *subcollection, 01539 const char *property, int32_t number, 01540 struct collection_item **ret_ref); 01541 01569 int col_add_unsigned_property_with_ref(struct collection_item *ci, 01570 const char *subcollection, 01571 const char *property, uint32_t number, 01572 struct collection_item **ret_ref); 01573 01601 int col_add_long_property_with_ref(struct collection_item *ci, 01602 const char *subcollection, 01603 const char *property, int64_t number, 01604 struct collection_item **ret_ref); 01605 01633 int col_add_ulong_property_with_ref(struct collection_item *ci, 01634 const char *subcollection, 01635 const char *property, uint64_t number, 01636 struct collection_item **ret_ref); 01637 01665 int col_add_double_property_with_ref(struct collection_item *ci, 01666 const char *subcollection, 01667 const char *property, double number, 01668 struct collection_item **ret_ref); 01669 01697 int col_add_bool_property_with_ref(struct collection_item *ci, 01698 const char *subcollection, 01699 const char *property, unsigned char logical, 01700 struct collection_item **ret_ref); 01701 01702 01732 int col_add_any_property_with_ref(struct collection_item *ci, 01733 const char *subcollection, 01734 const char *property, 01735 int type, void *data, int length, 01736 struct collection_item **ret_ref); 01737 01792 int col_insert_str_property(struct collection_item *ci, 01793 const char *subcollection, 01794 int disposition, 01795 const char *refprop, 01796 int idx, 01797 unsigned flags, 01798 const char *property, 01799 const char *string, 01800 int length); 01801 01803 int col_insert_binary_property(struct collection_item *ci, 01804 const char *subcollection, 01805 int disposition, 01806 const char *refprop, 01807 int idx, 01808 unsigned flags, 01809 const char *property, 01810 void *binary_data, 01811 int length); 01812 01814 int col_insert_int_property(struct collection_item *ci, 01815 const char *subcollection, 01816 int disposition, 01817 const char *refprop, 01818 int idx, 01819 unsigned flags, 01820 const char *property, 01821 int32_t number); 01822 01824 int col_insert_unsigned_property(struct collection_item *ci, 01825 const char *subcollection, 01826 int disposition, 01827 const char *refprop, 01828 int idx, 01829 unsigned flags, 01830 const char *property, 01831 uint32_t number); 01832 01834 int col_insert_long_property(struct collection_item *ci, 01835 const char *subcollection, 01836 int disposition, 01837 const char *refprop, 01838 int idx, 01839 unsigned flags, 01840 const char *property, 01841 int64_t number); 01842 01844 int col_insert_ulong_property(struct collection_item *ci, 01845 const char *subcollection, 01846 int disposition, 01847 const char *refprop, 01848 int idx, 01849 unsigned flags, 01850 const char *property, 01851 uint64_t number); 01852 01854 int col_insert_double_property(struct collection_item *ci, 01855 const char *subcollection, 01856 int disposition, 01857 const char *refprop, 01858 int idx, 01859 unsigned flags, 01860 const char *property, 01861 double number); 01862 01864 int col_insert_bool_property(struct collection_item *ci, 01865 const char *subcollection, 01866 int disposition, 01867 const char *refprop, 01868 int idx, 01869 unsigned flags, 01870 const char *property, 01871 unsigned char logical); 01872 01874 int col_insert_str_property_with_ref(struct collection_item *ci, 01875 const char *subcollection, 01876 int disposition, 01877 const char *refprop, 01878 int idx, 01879 unsigned flags, 01880 const char *property, 01881 const char *string, 01882 int length, 01883 struct collection_item **ret_ref); 01884 01886 int col_insert_binary_property_with_ref(struct collection_item *ci, 01887 const char *subcollection, 01888 int disposition, 01889 const char *refprop, 01890 int idx, 01891 unsigned flags, 01892 const char *property, 01893 void *binary_data, 01894 int length, 01895 struct collection_item **ret_ref); 01896 01898 int col_insert_int_property_with_ref(struct collection_item *ci, 01899 const char *subcollection, 01900 int disposition, 01901 const char *refprop, 01902 int idx, 01903 unsigned flags, 01904 const char *property, 01905 int32_t number, 01906 struct collection_item **ret_ref); 01907 01909 int col_insert_unsigned_property_with_ref(struct collection_item *ci, 01910 const char *subcollection, 01911 int disposition, 01912 const char *refprop, 01913 int idx, 01914 unsigned flags, 01915 const char *property, 01916 uint32_t number, 01917 struct collection_item **ret_ref); 01918 01920 int col_insert_long_property_with_ref(struct collection_item *ci, 01921 const char *subcollection, 01922 int disposition, 01923 const char *refprop, 01924 int idx, 01925 unsigned flags, 01926 const char *property, 01927 int64_t number, 01928 struct collection_item **ret_ref); 01929 01931 int col_insert_ulong_property_with_ref(struct collection_item *ci, 01932 const char *subcollection, 01933 int disposition, 01934 const char *refprop, 01935 int idx, 01936 unsigned flags, 01937 const char *property, 01938 uint64_t number, 01939 struct collection_item **ret_ref); 01940 01945 int col_insert_double_property_with_ref(struct collection_item *ci, 01946 const char *subcollection, 01947 int disposition, 01948 const char *refprop, 01949 int idx, 01950 unsigned flags, 01951 const char *property, 01952 double number, 01953 struct collection_item **ret_ref); 01954 01956 int col_insert_bool_property_with_ref(struct collection_item *ci, 01957 const char *subcollection, 01958 int disposition, 01959 const char *refprop, 01960 int idx, 01961 unsigned flags, 01962 const char *property, 01963 unsigned char logical, 01964 struct collection_item **ret_ref); 01965 01967 int col_insert_property_with_ref(struct collection_item *ci, 01968 const char *subcollection, 01969 int disposition, 01970 const char *refprop, 01971 int idx, 01972 unsigned flags, 01973 const char *property, 01974 int type, 01975 const void *data, 01976 int length, 01977 struct collection_item **ret_ref); 01978 01979 02028 int col_update_str_property(struct collection_item *ci, 02029 const char *property, 02030 int mode_flags, 02031 char *string, 02032 int length); 02036 int col_update_binary_property(struct collection_item *ci, 02037 const char *property, 02038 int mode_flags, 02039 void *binary_data, 02040 int length); 02044 int col_update_int_property(struct collection_item *ci, 02045 const char *property, 02046 int mode_flags, 02047 int32_t number); 02051 int col_update_unsigned_property(struct collection_item *ci, 02052 const char *property, 02053 int mode_flags, 02054 uint32_t number); 02058 int col_update_long_property(struct collection_item *ci, 02059 const char *property, 02060 int mode_flags, 02061 int64_t number); 02065 int col_update_ulong_property(struct collection_item *ci, 02066 const char *property, 02067 int mode_flags, 02068 uint64_t number); 02072 int col_update_double_property(struct collection_item *ci, 02073 const char *property, 02074 int mode_flags, 02075 double number); 02079 int col_update_bool_property(struct collection_item *ci, 02080 const char *property, 02081 int mode_flags, 02082 unsigned char logical); 02083 02091 int col_update_property(struct collection_item *ci, 02092 const char *property, 02093 int type, 02094 void *new_data, 02095 int length, 02096 int mode_flags); 02097 02098 02130 #define COL_CMPIN_PROP_EQU 0x000000004 02131 02132 #define COL_CMPIN_PROP_BEG 0x000000005 02133 02134 #define COL_CMPIN_PROP_MID 0x000000006 02135 02136 #define COL_CMPIN_PROP_END 0x000000007 02137 02149 #define COL_CMPIN_PROP_DOT 0x000000008 02150 02152 #define COL_CMPIN_PROP_LEN 0x000000010 02153 02155 #define COL_CMPIN_TYPE 0x000000020 02156 02158 #define COL_CMPIN_DATA_LEN 0x000000040 02159 02168 #define COL_CMPIN_DATA 0x000000080 02169 02190 #define COL_CMPOUT_PROP_STR 0x00000001 02191 02198 #define COL_CMPOUT_PROP_LEN 0x00000002 02199 02205 #define COL_CMPOUT_DATA_LEN 0x00000004 02206 02214 #define COL_CMPOUT_DATA 0x00000008 02215 02241 #define COL_DSP_END 0 02242 02252 #define COL_DSP_FRONT 1 02253 02265 #define COL_DSP_BEFORE 2 02266 02278 #define COL_DSP_AFTER 3 02279 02297 #define COL_DSP_INDEX 4 02298 02315 #define COL_DSP_FIRSTDUP 5 02316 02335 #define COL_DSP_LASTDUP 6 02336 02365 #define COL_DSP_NDUP 7 02366 02385 #define COL_DSP_LASTDUPNS 8 02386 02415 #define COL_DSP_NDUPNS 9 02416 02435 #define COL_INSERT_NOCHECK 0 02436 02440 #define COL_INSERT_DUPOVER 1 02441 02445 #define COL_INSERT_DUPOVERT 2 02446 02447 #define COL_INSERT_DUPERROR 3 02448 02452 #define COL_INSERT_DUPERRORT 4 02453 02456 #define COL_INSERT_DUPMOVE 5 02457 02460 #define COL_INSERT_DUPMOVET 6 02461 02488 const char *col_get_item_property(struct collection_item *ci, 02489 int *property_len); 02490 02503 int col_get_item_type(struct collection_item *ci); 02504 02518 int col_get_item_length(struct collection_item *ci); 02519 02532 void *col_get_item_data(struct collection_item *ci); 02533 02553 uint64_t col_get_item_hash(struct collection_item *ci); 02554 02578 uint64_t col_make_hash(const char *string, int sub_len, int *length); 02579 02580 02607 int col_compare_items(struct collection_item *first, 02608 struct collection_item *second, 02609 unsigned in_flags, 02610 unsigned *out_flags); 02611 02612 02613 02650 int col_modify_item(struct collection_item *item, 02651 const char *property, 02652 int type, 02653 const void *data, 02654 int length); 02655 02673 int col_modify_item_property(struct collection_item *item, 02674 const char *property); 02675 02689 int col_modify_str_item(struct collection_item *item, 02690 const char *property, 02691 const char *string, 02692 int length); 02703 int col_modify_binary_item(struct collection_item *item, 02704 const char *property, 02705 void *binary_data, 02706 int length); 02717 int col_modify_bool_item(struct collection_item *item, 02718 const char *property, 02719 unsigned char logical); 02730 int col_modify_int_item(struct collection_item *item, 02731 const char *property, 02732 int32_t number); 02743 int col_modify_long_item(struct collection_item *item, 02744 const char *property, 02745 int64_t number); 02756 int col_modify_ulong_item(struct collection_item *item, 02757 const char *property, 02758 uint64_t number); 02769 int col_modify_unsigned_item(struct collection_item *item, 02770 const char *property, 02771 uint32_t number); 02782 int col_modify_double_item(struct collection_item *item, 02783 const char *property, 02784 double number); 02785 02849 int col_extract_item(struct collection_item *ci, 02850 const char *subcollection, 02851 int disposition, 02852 const char *refprop, 02853 int idx, 02854 int type, 02855 struct collection_item **ret_ref); 02856 02897 int col_extract_item_from_current(struct collection_item *ci, 02898 int disposition, 02899 const char *refprop, 02900 int idx, 02901 int type, 02902 struct collection_item **ret_ref); 02903 02951 int col_remove_item(struct collection_item *ci, 02952 const char *subcollection, 02953 int disposition, 02954 const char *refprop, 02955 int idx, 02956 int type); 02957 03008 int col_remove_item_with_cb(struct collection_item *ci, 03009 const char *subcollection, 03010 int disposition, 03011 const char *refprop, 03012 int idx, 03013 int type, 03014 col_item_cleanup_fn cb, 03015 void *custom_data); 03016 03055 int col_remove_item_from_current(struct collection_item *ci, 03056 int disposition, 03057 const char *refprop, 03058 int idx, 03059 int type); 03060 03120 int col_insert_item(struct collection_item *ci, 03121 const char *subcollection, 03122 struct collection_item *item, 03123 int disposition, 03124 const char *refprop, 03125 int idx, 03126 unsigned flags); 03127 03168 int col_insert_item_into_current(struct collection_item *ci, 03169 struct collection_item *item, 03170 int disposition, 03171 const char *refprop, 03172 int idx, 03173 unsigned flags); 03174 03175 03176 03190 void col_delete_item(struct collection_item *item); 03191 03205 void col_delete_item_with_cb(struct collection_item *item, 03206 col_item_cleanup_fn cb, 03207 void *custom_data); 03208 03209 03244 int col_bind_iterator(struct collection_iterator **iterator, 03245 struct collection_item *ci, 03246 int mode_flags); 03247 03253 void col_unbind_iterator(struct collection_iterator *iterator); 03254 03275 int col_iterate_collection(struct collection_iterator *iterator, 03276 struct collection_item **item); 03277 03295 int col_iterate_up(struct collection_iterator *iterator, unsigned level); 03296 03328 int col_get_iterator_depth(struct collection_iterator *iterator, int *depth); 03329 03344 int col_get_item_depth(struct collection_iterator *iterator, int *depth); 03345 03391 void col_pin_iterator(struct collection_iterator *iterator); 03392 03402 void col_rewind_iterator(struct collection_iterator *iterator); 03403 03404 03413 #endif
1.7.3