libcollection  0.1.3
collection.h
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 
00510 typedef int (*col_copy_cb)(struct collection_item *item,
00511                            void *ext_data,
00512                            int *skip);
00513 
00540 int col_copy_collection_with_cb(struct collection_item **col_copy,
00541                                 struct collection_item *col_to_copy,
00542                                 const char *name_to_use,
00543                                 int copy_mode,
00544                                 col_copy_cb copy_cb,
00545                                 void *ext_data);
00546 
00564 int col_copy_collection(struct collection_item **col_copy,
00565                         struct collection_item *col_to_copy,
00566                         const char *name_to_use,
00567                         int copy_mode);
00568 
00600 int col_add_collection_to_collection(struct collection_item *ci,
00601                                      const char *subcollection,
00602                                      const char *as_property,
00603                                      struct collection_item *ci_to_add,
00604                                      int mode);
00631 typedef int (*col_item_fn)(const char *property,
00632                            int property_len,
00633                            int type,
00634                            void *data,
00635                            int length,
00636                            void *custom_dat,
00637                            int *stop);
00638 
00639 
00661 int col_traverse_collection(struct collection_item *ci,
00662                             int mode_flags,
00663                             col_item_fn item_handler,
00664                             void *custom_data);
00665 
00700 int col_get_item_and_do(struct collection_item *ci,
00701                         const char *property_to_find,
00702                         int type,
00703                         int mode_flags,
00704                         col_item_fn item_handler,
00705                         void *custom_data);
00706 
00745 int col_get_item(struct collection_item *ci,
00746                  const char *property_to_find,
00747                  int type,
00748                  int mode_flags,
00749                  struct collection_item **item);
00750 
00780 int col_sort_collection(struct collection_item *col,
00781                         unsigned cmp_flags,
00782                         unsigned sort_flags);
00783 
00815 int col_delete_property(struct collection_item *ci,
00816                         const char *property_to_find,
00817                         int type,
00818                         int mode_flags);
00819 
00844 int col_is_item_in_collection(struct collection_item *ci,
00845                               const char *property_to_find,
00846                               int type,
00847                               int mode_flags,
00848                               int *found);
00849 
00871 int col_get_collection_reference(struct collection_item *ci,
00872                                  struct collection_item **acceptor,
00873                                  const char *col_to_find);
00874 
00894 int col_get_reference_from_item(struct collection_item *item,
00895                                 struct collection_item **acceptor);
00896 
00897 
00898 
00927 int col_get_collection_class(struct collection_item *ci,
00928                              unsigned *cclass);
00929 
00943 int col_set_collection_class(struct collection_item *ci,
00944                              unsigned cclass);
00945 
00964 int col_get_collection_count(struct collection_item *ci,
00965                              unsigned *count);
00966 
00967 
00981 int col_is_of_class(struct collection_item *ci,
00982                     unsigned cclass);
00983 
00984 
01057 int col_add_str_property(struct collection_item *ci,
01058                          const char *subcollection,
01059                          const char *property,
01060                          const char *string,
01061                          int length);
01062 
01089 int col_add_binary_property(struct collection_item *ci,
01090                             const char *subcollection,
01091                             const char *property,
01092                             void *binary_data,
01093                             int length);
01094 
01120 int col_add_int_property(struct collection_item *ci,
01121                          const char *subcollection,
01122                          const char *property,
01123                          int32_t number);
01124 
01150 int col_add_unsigned_property(struct collection_item *ci,
01151                               const char *subcollection,
01152                               const char *property,
01153                               uint32_t number);
01154 
01180 int col_add_long_property(struct collection_item *ci,
01181                           const char *subcollection,
01182                           const char *property,
01183                           int64_t number);
01184 
01210 int col_add_ulong_property(struct collection_item *ci,
01211                            const char *subcollection,
01212                            const char *property,
01213                            uint64_t number);
01214 
01240 int col_add_double_property(struct collection_item *ci,
01241                             const char *subcollection,
01242                             const char *property,
01243                             double number);
01269 int col_add_bool_property(struct collection_item *ci,
01270                           const char *subcollection,
01271                           const char *property,
01272                           unsigned char logical);
01273 
01274 
01302 int col_add_any_property(struct collection_item *ci,
01303                          const char *subcollection,
01304                          const char *property,
01305                          int type,
01306                          void *data,
01307                          int length);
01308 
01368 int col_add_str_property_with_ref(struct collection_item *ci,
01369                                   const char *subcollection,
01370                                   const char *property,
01371                                   char *string, int length,
01372                                   struct collection_item **ret_ref);
01373 
01402 int col_add_binary_property_with_ref(struct collection_item *ci,
01403                                      const char *subcollection,
01404                                      const char *property,
01405                                      void *binary_data, int length,
01406                                      struct collection_item **ret_ref);
01407 
01435 int col_add_int_property_with_ref(struct collection_item *ci,
01436                                   const char *subcollection,
01437                                   const char *property, int32_t number,
01438                                   struct collection_item **ret_ref);
01439 
01467 int col_add_unsigned_property_with_ref(struct collection_item *ci,
01468                                        const char *subcollection,
01469                                        const char *property, uint32_t number,
01470                                        struct collection_item **ret_ref);
01471 
01499 int col_add_long_property_with_ref(struct collection_item *ci,
01500                                    const char *subcollection,
01501                                    const char *property, int64_t number,
01502                                    struct collection_item **ret_ref);
01503 
01531 int col_add_ulong_property_with_ref(struct collection_item *ci,
01532                                     const char *subcollection,
01533                                     const char *property, uint64_t number,
01534                                     struct collection_item **ret_ref);
01535 
01563 int col_add_double_property_with_ref(struct collection_item *ci,
01564                                      const char *subcollection,
01565                                      const char *property, double number,
01566                                      struct collection_item **ret_ref);
01567 
01595 int col_add_bool_property_with_ref(struct collection_item *ci,
01596                                    const char *subcollection,
01597                                    const char *property, unsigned char logical,
01598                                    struct collection_item **ret_ref);
01599 
01600 
01630 int col_add_any_property_with_ref(struct collection_item *ci,
01631                                   const char *subcollection,
01632                                   const char *property,
01633                                   int type, void *data, int length,
01634                                   struct collection_item **ret_ref);
01635 
01690 int col_insert_str_property(struct collection_item *ci,
01691                             const char *subcollection,
01692                             int disposition,
01693                             const char *refprop,
01694                             int idx,
01695                             unsigned flags,
01696                             const char *property,
01697                             const char *string,
01698                             int length);
01699 
01701 int col_insert_binary_property(struct collection_item *ci,
01702                                const char *subcollection,
01703                                int disposition,
01704                                const char *refprop,
01705                                int idx,
01706                                unsigned flags,
01707                                const char *property,
01708                                void *binary_data,
01709                                int length);
01710 
01712 int col_insert_int_property(struct collection_item *ci,
01713                             const char *subcollection,
01714                             int disposition,
01715                             const char *refprop,
01716                             int idx,
01717                             unsigned flags,
01718                             const char *property,
01719                             int32_t number);
01720 
01722 int col_insert_unsinged_property(struct collection_item *ci,
01723                                  const char *subcollection,
01724                                  int disposition,
01725                                  const char *refprop,
01726                                  int idx,
01727                                  unsigned flags,
01728                                  const char *property,
01729                                  uint32_t number);
01730 
01732 int col_insert_long_property(struct collection_item *ci,
01733                              const char *subcollection,
01734                              int disposition,
01735                              const char *refprop,
01736                              int idx,
01737                              unsigned flags,
01738                              const char *property,
01739                              int64_t number);
01740 
01742 int col_insert_ulong_property(struct collection_item *ci,
01743                               const char *subcollection,
01744                               int disposition,
01745                               const char *refprop,
01746                               int idx,
01747                               unsigned flags,
01748                               const char *property,
01749                               uint64_t number);
01750 
01752 int col_insert_double_property(struct collection_item *ci,
01753                                const char *subcollection,
01754                                int disposition,
01755                                const char *refprop,
01756                                int idx,
01757                                unsigned flags,
01758                                const char *property,
01759                                double number);
01760 
01762 int col_insert_bool_property(struct collection_item *ci,
01763                              const char *subcollection,
01764                              int disposition,
01765                              const char *refprop,
01766                              int idx,
01767                              unsigned flags,
01768                              const char *property,
01769                              unsigned char logical);
01770 
01772 int col_insert_str_property_with_ref(struct collection_item *ci,
01773                                      const char *subcollection,
01774                                      int disposition,
01775                                      const char *refprop,
01776                                      int idx,
01777                                      unsigned flags,
01778                                      const char *property,
01779                                      const char *string,
01780                                      int length,
01781                                      struct collection_item **ret_ref);
01782 
01784 int col_insert_binary_property_with_ref(struct collection_item *ci,
01785                                         const char *subcollection,
01786                                         int disposition,
01787                                         const char *refprop,
01788                                         int idx,
01789                                         unsigned flags,
01790                                         const char *property,
01791                                         void *binary_data,
01792                                         int length,
01793                                         struct collection_item **ret_ref);
01794 
01796 int col_insert_int_property_with_ref(struct collection_item *ci,
01797                                      const char *subcollection,
01798                                      int disposition,
01799                                      const char *refprop,
01800                                      int idx,
01801                                      unsigned flags,
01802                                      const char *property,
01803                                      int32_t number,
01804                                      struct collection_item **ret_ref);
01805 
01807 int col_insert_unsinged_property_with_ref(struct collection_item *ci,
01808                                           const char *subcollection,
01809                                           int disposition,
01810                                           const char *refprop,
01811                                           int idx,
01812                                           unsigned flags,
01813                                           const char *property,
01814                                           uint32_t number,
01815                                           struct collection_item **ret_ref);
01816 
01818 int col_insert_long_property_with_ref(struct collection_item *ci,
01819                                       const char *subcollection,
01820                                       int disposition,
01821                                       const char *refprop,
01822                                       int idx,
01823                                       unsigned flags,
01824                                       const char *property,
01825                                       int64_t number,
01826                                       struct collection_item **ret_ref);
01827 
01829 int col_insert_ulong_property_with_ref(struct collection_item *ci,
01830                                        const char *subcollection,
01831                                        int disposition,
01832                                        const char *refprop,
01833                                        int idx,
01834                                        unsigned flags,
01835                                        const char *property,
01836                                        uint64_t number,
01837                                        struct collection_item **ret_ref);
01838 
01843 int col_insert_double_property_with_ref(struct collection_item *ci,
01844                                         const char *subcollection,
01845                                         int disposition,
01846                                         const char *refprop,
01847                                         int idx,
01848                                         unsigned flags,
01849                                         const char *property,
01850                                         double number,
01851                                         struct collection_item **ret_ref);
01852 
01854 int col_insert_bool_property_with_ref(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                                       unsigned char logical,
01862                                       struct collection_item **ret_ref);
01863 
01865 int col_insert_property_with_ref(struct collection_item *ci,
01866                                  const char *subcollection,
01867                                  int disposition,
01868                                  const char *refprop,
01869                                  int idx,
01870                                  unsigned flags,
01871                                  const char *property,
01872                                  int type,
01873                                  const void *data,
01874                                  int length,
01875                                  struct collection_item **ret_ref);
01876 
01877 
01926 int col_update_str_property(struct collection_item *ci,
01927                             const char *property,
01928                             int mode_flags,
01929                             char *string,
01930                             int length);
01934 int col_update_binary_property(struct collection_item *ci,
01935                                const char *property,
01936                                int mode_flags,
01937                                void *binary_data,
01938                                int length);
01942 int col_update_int_property(struct collection_item *ci,
01943                             const char *property,
01944                             int mode_flags,
01945                             int32_t number);
01949 int col_update_unsigned_property(struct collection_item *ci,
01950                                  const char *property,
01951                                  int mode_flags,
01952                                  uint32_t number);
01956 int col_update_long_property(struct collection_item *ci,
01957                              const char *property,
01958                              int mode_flags,
01959                              int64_t number);
01963 int col_update_ulong_property(struct collection_item *ci,
01964                               const char *property,
01965                               int mode_flags,
01966                               uint64_t number);
01970 int col_update_double_property(struct collection_item *ci,
01971                                const char *property,
01972                                int mode_flags,
01973                                double number);
01977 int col_update_bool_property(struct collection_item *ci,
01978                              const char *property,
01979                              int mode_flags,
01980                              unsigned char logical);
01981 
01989 int col_update_property(struct collection_item *ci,
01990                         const char *property,
01991                         int type,
01992                         void *new_data,
01993                         int length,
01994                         int mode_flags);
01995 
01996 
02028 #define COL_CMPIN_PROP_EQU    0x000000004
02029 
02030 #define COL_CMPIN_PROP_BEG    0x000000005
02031 
02032 #define COL_CMPIN_PROP_MID    0x000000006
02033 
02034 #define COL_CMPIN_PROP_END    0x000000007
02035 
02047 #define COL_CMPIN_PROP_DOT     0x000000008
02048 
02050 #define COL_CMPIN_PROP_LEN     0x000000010
02051 
02053 #define COL_CMPIN_TYPE         0x000000020
02054 
02056 #define COL_CMPIN_DATA_LEN     0x000000040
02057 
02066 #define COL_CMPIN_DATA         0x000000080
02067 
02088 #define COL_CMPOUT_PROP_STR    0x00000001
02089 
02096 #define COL_CMPOUT_PROP_LEN    0x00000002
02097 
02103 #define COL_CMPOUT_DATA_LEN    0x00000004
02104 
02112 #define COL_CMPOUT_DATA    0x00000008
02113 
02139 #define COL_DSP_END             0
02140 
02150 #define COL_DSP_FRONT           1
02151 
02163 #define COL_DSP_BEFORE          2
02164 
02176 #define COL_DSP_AFTER           3
02177 
02195 #define COL_DSP_INDEX           4
02196 
02213 #define COL_DSP_FIRSTDUP        5
02214 
02233 #define COL_DSP_LASTDUP         6
02234 
02263 #define COL_DSP_NDUP            7
02264 
02283 #define COL_INSERT_NOCHECK      0
02284 
02288 #define COL_INSERT_DUPOVER      1
02289 
02293 #define COL_INSERT_DUPOVERT     2
02294 
02295 #define COL_INSERT_DUPERROR     3
02296 
02300 #define COL_INSERT_DUPERRORT    4
02301 
02304 #define COL_INSERT_DUPMOVE      5
02305 
02308 #define COL_INSERT_DUPMOVET     6
02309 
02336 const char *col_get_item_property(struct collection_item *ci,
02337                                   int *property_len);
02338 
02351 int col_get_item_type(struct collection_item *ci);
02352 
02366 int col_get_item_length(struct collection_item *ci);
02367 
02380 void *col_get_item_data(struct collection_item *ci);
02381 
02401 uint64_t col_get_item_hash(struct collection_item *ci);
02402 
02426 uint64_t col_make_hash(const char *string, int sub_len, int *length);
02427 
02428 
02455 int col_compare_items(struct collection_item *first,
02456                       struct collection_item *second,
02457                       unsigned in_flags,
02458                       unsigned *out_flags);
02459 
02460 
02461 
02496 int col_modify_item(struct collection_item *item,
02497                     const char *property,
02498                     int type,
02499                     const void *data,
02500                     int length);
02501 
02519 int col_modify_item_property(struct collection_item *item,
02520                              const char *property);
02521 
02535 int col_modify_str_item(struct collection_item *item,
02536                         const char *property,
02537                         const char *string,
02538                         int length);
02549 int col_modify_binary_item(struct collection_item *item,
02550                            const char *property,
02551                            void *binary_data,
02552                            int length);
02563 int col_modify_bool_item(struct collection_item *item,
02564                          const char *property,
02565                          unsigned char logical);
02576 int col_modify_int_item(struct collection_item *item,
02577                         const char *property,
02578                         int32_t number);
02589 int col_modify_long_item(struct collection_item *item,
02590                          const char *property,
02591                          int64_t number);
02602 int col_modify_ulong_item(struct collection_item *item,
02603                           const char *property,
02604                           uint64_t number);
02615 int col_modify_unsigned_item(struct collection_item *item,
02616                              const char *property,
02617                              uint32_t number);
02628 int col_modify_double_item(struct collection_item *item,
02629                            const char *property,
02630                            double number);
02631 
02695 int col_extract_item(struct collection_item *ci,
02696                      const char *subcollection,
02697                      int disposition,
02698                      const char *refprop,
02699                      int idx,
02700                      int type,
02701                      struct collection_item **ret_ref);
02702 
02743 int col_extract_item_from_current(struct collection_item *ci,
02744                                   int disposition,
02745                                   const char *refprop,
02746                                   int idx,
02747                                   int type,
02748                                   struct collection_item **ret_ref);
02749 
02797 int col_remove_item(struct collection_item *ci,
02798                     const char *subcollection,
02799                     int disposition,
02800                     const char *refprop,
02801                     int idx,
02802                     int type);
02803 
02804 
02843 int col_remove_item_from_current(struct collection_item *ci,
02844                                  int disposition,
02845                                  const char *refprop,
02846                                  int idx,
02847                                  int type);
02848 
02908 int col_insert_item(struct collection_item *ci,
02909                     const char *subcollection,
02910                     struct collection_item *item,
02911                     int disposition,
02912                     const char *refprop,
02913                     int idx,
02914                     unsigned flags);
02915 
02956 int col_insert_item_into_current(struct collection_item *ci,
02957                                  struct collection_item *item,
02958                                  int disposition,
02959                                  const char *refprop,
02960                                  int idx,
02961                                  unsigned flags);
02962 
02963 
02964 
02978 void col_delete_item(struct collection_item *item);
02979 
03014 int col_bind_iterator(struct collection_iterator **iterator,
03015                       struct collection_item *ci,
03016                       int mode_flags);
03017 
03023 void col_unbind_iterator(struct collection_iterator *iterator);
03024 
03045 int col_iterate_collection(struct collection_iterator *iterator,
03046                            struct collection_item **item);
03047 
03065 int col_iterate_up(struct collection_iterator *iterator, unsigned level);
03066 
03098 int col_get_iterator_depth(struct collection_iterator *iterator, int *depth);
03099 
03114 int col_get_item_depth(struct collection_iterator *iterator, int *depth);
03115 
03164 void col_pin_iterator(struct collection_iterator *iterator);
03165 
03178 void col_rewind_iterator(struct collection_iterator *iterator);
03179 
03180 
03189 #endif
 All Data Structures