1 /* libcomps - C alternative to yum.comps library 2 * Copyright (C) 2013 Jindrich Luza 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * any later version. 8 * 9 * This program is distributed in the hope that it will be useful, but 10 * WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 17 * USA 18 */ 19 20 /*! \file comps_objdict.h 21 * \brief Libcomps dictionary and multi-dictionary. COMPS_ObjDict and 22 * COMPS_ObjMDict are both derivates of COMPS_Object read more 23 * \link comps_obj here 24 * \endlink 25 * @see comps_dict 26 * @see comps_multi_dict 27 * 28 **/ 29 #ifndef COMPS_OBJDICT_H 30 #define COMPS_OBJDICT_H 31 32 #include "comps_objradix.h" 33 #include "comps_objmradix.h" 34 35 typedef COMPS_ObjRTree COMPS_ObjDict; 36 COMPS_Object_TAIL(COMPS_ObjDict); 37 38 typedef COMPS_ObjMRTree COMPS_ObjMDict; 39 COMPS_Object_TAIL(COMPS_ObjMDict); 40 41 COMPS_ObjDict* comps_objdict_create(); 42 COMPS_ObjMDict* comps_objmdict_create(); 43 44 45 void comps_objdict_destroy(COMPS_ObjDict *rt); 46 void comps_objdict_destroy_v(void *rt); 47 void comps_objmdict_destroy(COMPS_ObjMDict *rt); 48 void comps_objmdict_destroy_v(void *rt); 49 /** \defgroup comps_dict comps dictionary functions 50 *@{ @} */ 51 /** \defgroup comps_multi_dict comps multi-dictionary functions 52 *@{ @} */ 53 54 /** \addtogroup comps_dict 55 *@{*/ 56 /** set new item to dictionary 57 * 58 * if there's already item for specified key in dictionary, old item will 59 * be replaced with new item and its reference counter will be decremented. 60 * Reference counter of new item will be incremented 61 * 62 * @param rt COMPS_ObjDict object 63 * @param key key for new item 64 * @param data new item 65 */ 66 void comps_objdict_set(COMPS_ObjDict *rt, char *key, COMPS_Object *data); 67 68 /** set new item to dictionary 69 * 70 * if there's already item for specified key in dictionary, old item will 71 * be replaced with new item and its reference counter will be decremented. 72 * Reference counter of new items won't be incremented 73 * 74 * @param rt COMPS_ObjDict object 75 * @param key key for new item 76 * @param data new item 77 */ 78 void comps_objdict_set_x(COMPS_ObjDict *rt, char *key, COMPS_Object *data); 79 80 /** same as comps_objdict_set but with key length limited by argument 81 * 82 * @param rt COMPS_ObjDict object 83 * @param key key for new item 84 * @param len key length limiter 85 * @param data new item 86 */ 87 void comps_objdict_set_n(COMPS_ObjDict *rt, char *key, unsigned int len, 88 COMPS_Object *data); 89 /** @}*/ 90 91 /** \addtogroup comps_multi_dict 92 *@{*/ 93 /** set new item to multi-dictionary 94 * 95 * if there's already item for specified key, new item will be added into list 96 * for specified key. Reference counter of new item is incremented 97 * 98 * @param rt COMPS_ObjMDict object 99 * @param key key for new item 100 * @param data new item 101 */ 102 void comps_objmdict_set(COMPS_ObjMDict *rt, char *key, COMPS_Object *data); 103 104 /** set new item to multi-dictionary 105 * 106 * if there's already item for specified key, new item will be added into list 107 * for specified key. Reference counter of new item isn't incremented 108 * 109 * @param rt COMPS_ObjMDict object 110 * @param key key for new item 111 * @param data new item 112 */ 113 void comps_objmdict_set_x(COMPS_ObjMDict *rt, char *key, COMPS_Object *data); 114 115 /** same as comps_objmdict_set but with key length limited by argument 116 * 117 * @param rt COMPS_ObjMDict object 118 * @param key key for new item 119 * @param len key length limiter 120 * @param data new item 121 */ 122 void comps_objmdict_set_n(COMPS_ObjMDict *rt, char *key, unsigned int len, 123 COMPS_Object *data); 124 /** @}*/ 125 126 /** \addtogroup comps_dict 127 *@{*/ 128 129 /** get item from dictionary for specified key 130 * 131 * if there's no such item, return NULL. Item's reference counter will 132 * be incremented. 133 * 134 * @param rt COMPS_ObjDict object 135 * @param specified key 136 * @return item for key 137 */ 138 COMPS_Object* comps_objdict_get(COMPS_ObjDict *rt, const char *key); 139 140 /** get item from dictionary for specified key 141 * 142 * if there's no such item, return NULL. Item's reference counter WON'T 143 * be incremented. 144 * 145 * @param rt COMPS_ObjDict object 146 * @param specified key 147 * @return item for key 148 */ 149 COMPS_Object* comps_objdict_get_x(COMPS_ObjRTree * rt, const char * key); 150 /** @}*/ 151 152 /** \addtogroup comps_multi_dict 153 *@{*/ 154 /** get items from multi-dictionary for specified key 155 * 156 * if there's no such items, return NULL. Item's reference counter WON'T 157 * be incremented. 158 * 159 * @param rt COMPS_ObjDict object 160 * @param specified key 161 * @return COMPS_ObjList of specified items 162 */ 163 COMPS_ObjList * comps_objmdict_get(COMPS_ObjMDict *rt, const char *key); 164 /** @}*/ 165 166 /** \addtogroup comps_dict 167 *@{*/ 168 /** remove item from dictionary for specified key 169 * 170 * item's reference counter will be decremented 171 * 172 * @param rt COMPS_ObjDict object 173 * @param key item's key 174 */ 175 void comps_objdict_unset(COMPS_ObjDict * rt, const char * key); 176 /** @}*/ 177 178 /** \addtogroup comps_multi_dict 179 *@{*/ 180 /** remove item from multi-dictionary for specified key 181 * 182 * item's reference counter will be decremented 183 * 184 * @param rt COMPS_ObjDict object 185 * @param key item's key 186 */ 187 void comps_objmdict_unset(COMPS_ObjMDict * rt, const char * key); 188 /** @}*/ 189 190 /** \addtogroup comps_dict 191 *@{*/ 192 /** remove all items from dictionary 193 * @param rt COMPS_ObjDict object 194 */ 195 void comps_objdict_clear(COMPS_ObjDict * rt); 196 /** @}*/ 197 198 /** \addtogroup comps_multi_dict 199 *@{*/ 200 /** remove all items from multi-dictionary 201 * @param rt COMPS_ObjDict object 202 */ 203 void comps_objmdict_clear(COMPS_ObjMDict * rt); 204 /** @}*/ 205 206 /** \addtogroup comps_dict 207 *@{*/ 208 /** Return list of all values(items) in dictionary 209 * @param rt COMPS_ObjDict objecti 210 * @return COMPS_HSList of values 211 */ 212 COMPS_HSList * comps_objdict_values(COMPS_ObjDict * rt); 213 /** @}*/ 214 215 /** \addtogroup comps_multi_dict 216 *@{*/ 217 /** Return list of all values(items) in multi-dictionary 218 * @param rt COMPS_ObjDict object 219 * @return COMPS_HSList of values 220 */ 221 COMPS_HSList * comps_objmdict_values(COMPS_ObjMDict * rt); 222 /** @}*/ 223 224 /** \addtogroup comps_dict 225 *@{*/ 226 /** Apply function for each item in dictionary 227 * 228 * Applied function takes user data (udata param) and item as arguments 229 * 230 * @param rt COMPS_ObjDict object 231 * @param udata user data 232 * @param walk_f applied function 233 * 234 */ 235 void comps_objdict_values_walk(COMPS_ObjRTree * rt, void* udata, 236 void (*walk_f)(void*, COMPS_Object*)); 237 /** @}*/ 238 239 /** \addtogroup comps_multi_dict 240 *@{*/ 241 /** Apply function for each item in multi-dictionary 242 * 243 * Applied function takes user data (udata param) and item as arguments 244 * 245 * @param rt COMPS_ObjDict object 246 * @param udata user data 247 * @param walk_f applied function 248 * 249 */ 250 void comps_objmdict_values_walk(COMPS_ObjMDict *rt, void *udata, 251 void (*walk_f)(void*, void*)); 252 /** @}*/ 253 254 /** \addtogroup comps_dict 255 *@{*/ 256 /** Makes copy of dictionary 257 * 258 * Items in new dictionary is same items with incremented reference 259 * counter only 260 * 261 * @param rt COMPS_ObjDict object 262 * @return new COMPS_ObjDict object 263 */ 264 COMPS_ObjDict* comps_objdict_clone(COMPS_ObjDict *rt); 265 /** @}*/ 266 void * comps_objdict_clone_v(void * rt); 267 268 /** \addtogroup comps_multi_dict 269 *@{*/ 270 /** Makes copy of multi-dictionary 271 * 272 * Items in new dictionary is same items with incremented reference 273 * counter only 274 * 275 * @param rt COMPS_ObjDict object 276 * @return new COMPS_ObjDict object 277 */ 278 COMPS_ObjMDict* comps_objmdict_clone(COMPS_ObjMDict *rt); 279 /** @}*/ 280 void* comps_objmdict_clone_v(void *rt); 281 282 /** \addtogroup comps_multi_dict 283 *@{*/ 284 /** Return list of keys in multi-dictionary 285 * 286 * @param rt COMPS_ObjMDict object 287 * @return COMPS_HSList of key in multi-dictionary 288 */ 289 COMPS_HSList* comps_objmdict_keys(COMPS_ObjMDict *rt); 290 /** @}*/ 291 292 /** \addtogroup comps_dict 293 *@{*/ 294 /** Return list of keys in dictionary 295 * 296 * @param rt COMPS_ObjDict object 297 * @return COMPS_HSList of key in dictionary 298 */ 299 COMPS_HSList* comps_objdict_keys(COMPS_ObjDict *rt); 300 301 /** Return list of pairs(key-value) in dictionary 302 * 303 * @param rt COMPS_ObjDict object 304 * @return COMPS_HSList of pairs in dictionary 305 */ 306 COMPS_HSList* comps_objdict_pairs(COMPS_ObjDict *rt); 307 /** @}*/ 308 309 /** \addtogroup comps_multi_dict 310 *@{*/ 311 /** Return list of pairs(key-value) in multi-dictionary 312 * 313 * @param rt COMPS_ObjMDict object 314 * @return COMPS_HSList of pairs in dictionary 315 */ 316 COMPS_HSList* comps_objmdict_pairs(COMPS_ObjMDict *rt); 317 /** @}*/ 318 319 /** \addtogroup comps_dict 320 *@{*/ 321 //void comps_mdict_unite(COMPS_MDict *d1, COMPS_MDict *d2); 322 323 /** Join two dictionries into one 324 * 325 * New dictionary is filled with pairs of first dictionary and then 326 * with pairs of second dictionary with skipped items whose keys are already 327 * in dictionary 328 * 329 * @param d1 COMPS_ObjDict object 330 * @param d2 COMPS_ObjDict object 331 * @return new COMPS_ObjDict object 332 */ 333 COMPS_ObjDict* comps_objdict_union(COMPS_ObjDict *d1, COMPS_ObjDict *d2); 334 /** @}*/ 335 #endif 336