diff options
| author | 2009-10-10 18:20:01 +0200 | |
|---|---|---|
| committer | 2009-10-10 18:20:01 +0200 | |
| commit | 77b02c9404dbfef325b7a19228045a817cafe064 (patch) | |
| tree | 1d571bb5faf3ba49a7d1f0e7cdf8195b271d728d /include | |
| parent | c18c9d087860e812431799fae406144928dd46c8 (diff) | |
| download | libplist-77b02c9404dbfef325b7a19228045a817cafe064.tar.gz libplist-77b02c9404dbfef325b7a19228045a817cafe064.tar.bz2 | |
Rework public API to make it more consistent.
Diffstat (limited to 'include')
| -rw-r--r-- | include/plist/plist.h | 345 |
1 files changed, 258 insertions, 87 deletions
diff --git a/include/plist/plist.h b/include/plist/plist.h index 6388603..f8c5c53 100644 --- a/include/plist/plist.h +++ b/include/plist/plist.h | |||
| @@ -65,13 +65,11 @@ extern "C" { | |||
| 65 | * The enumeration of plist node types. | 65 | * The enumeration of plist node types. |
| 66 | */ | 66 | */ |
| 67 | typedef enum { | 67 | typedef enum { |
| 68 | PLIST_BOOLEAN, | 68 | PLIST_BOOLEAN, /**< Boolean, scalar type */ |
| 69 | /**< Boolean, scalar type */ | ||
| 70 | PLIST_UINT, /**< Unsigned integer, scalar type */ | 69 | PLIST_UINT, /**< Unsigned integer, scalar type */ |
| 71 | PLIST_REAL, /**< Real, scalar type */ | 70 | PLIST_REAL, /**< Real, scalar type */ |
| 72 | PLIST_STRING, | 71 | PLIST_STRING, /**< ASCII string, scalar type */ |
| 73 | /**< ASCII string, scalar type */ | 72 | PLIST_ARRAY, /**< Ordered array, structured type */ |
| 74 | PLIST_ARRAY,/**< Ordered array, structured type */ | ||
| 75 | PLIST_DICT, /**< Unordered dictionary (key/value pair), structured type */ | 73 | PLIST_DICT, /**< Unordered dictionary (key/value pair), structured type */ |
| 76 | PLIST_DATE, /**< Date, scalar type */ | 74 | PLIST_DATE, /**< Date, scalar type */ |
| 77 | PLIST_DATA, /**< Binary data, scalar type */ | 75 | PLIST_DATA, /**< Binary data, scalar type */ |
| @@ -103,6 +101,62 @@ extern "C" { | |||
| 103 | PLIST_API plist_t plist_new_array(void); | 101 | PLIST_API plist_t plist_new_array(void); |
| 104 | 102 | ||
| 105 | /** | 103 | /** |
| 104 | * Create a new plist_t type #PLIST_STRING | ||
| 105 | * | ||
| 106 | * @param val the sting value, encoded in UTF8. | ||
| 107 | * @return the created item | ||
| 108 | * @sa #plist_type | ||
| 109 | */ | ||
| 110 | PLIST_API plist_t plist_new_string(const char *val); | ||
| 111 | |||
| 112 | /** | ||
| 113 | * Create a new plist_t type #PLIST_BOOLEAN | ||
| 114 | * | ||
| 115 | * @param val the boolean value, 0 is false, other values are true. | ||
| 116 | * @return the created item | ||
| 117 | * @sa #plist_type | ||
| 118 | */ | ||
| 119 | PLIST_API plist_t plist_new_bool(uint8_t val); | ||
| 120 | |||
| 121 | /** | ||
| 122 | * Create a new plist_t type #PLIST_UINT | ||
| 123 | * | ||
| 124 | * @param val the unsigned integer value | ||
| 125 | * @return the created item | ||
| 126 | * @sa #plist_type | ||
| 127 | */ | ||
| 128 | PLIST_API plist_t plist_new_uint(uint64_t val); | ||
| 129 | |||
| 130 | /** | ||
| 131 | * Create a new plist_t type #PLIST_REAL | ||
| 132 | * | ||
| 133 | * @param val the real value | ||
| 134 | * @return the created item | ||
| 135 | * @sa #plist_type | ||
| 136 | */ | ||
| 137 | PLIST_API plist_t plist_new_real(double val); | ||
| 138 | |||
| 139 | /** | ||
| 140 | * Create a new plist_t type #PLIST_DATA | ||
| 141 | * | ||
| 142 | * @param val the binary buffer | ||
| 143 | * @param length the length of the buffer | ||
| 144 | * @return the created item | ||
| 145 | * @sa #plist_type | ||
| 146 | */ | ||
| 147 | PLIST_API plist_t plist_new_data(const char *val, uint64_t length); | ||
| 148 | |||
| 149 | /** | ||
| 150 | * Create a new plist_t type #PLIST_DATE | ||
| 151 | * | ||
| 152 | * @param sec the number of seconds since 01/01/2001 | ||
| 153 | * @param usec the number of microseconds | ||
| 154 | * @return the created item | ||
| 155 | * @sa #plist_type | ||
| 156 | */ | ||
| 157 | PLIST_API plist_t plist_new_date(int32_t sec, int32_t usec); | ||
| 158 | |||
| 159 | /** | ||
| 106 | * Destruct a plist_t node and all its children recursively | 160 | * Destruct a plist_t node and all its children recursively |
| 107 | * | 161 | * |
| 108 | * @param plist the plist to free | 162 | * @param plist the plist to free |
| @@ -120,139 +174,113 @@ extern "C" { | |||
| 120 | 174 | ||
| 121 | /******************************************** | 175 | /******************************************** |
| 122 | * * | 176 | * * |
| 123 | * Tree navigation * | 177 | * Array functions * |
| 124 | * * | 178 | * * |
| 125 | ********************************************/ | 179 | ********************************************/ |
| 126 | 180 | ||
| 127 | /** | 181 | /** |
| 128 | * Get the first child of a node | 182 | * Get size of a #PLIST_ARRAY node. |
| 129 | * | 183 | * |
| 130 | * @param node the first child | 184 | * @param node the node of type #PLIST_ARRAY |
| 185 | * @return size of the #PLIST_ARRAY node | ||
| 131 | */ | 186 | */ |
| 132 | PLIST_API plist_t plist_get_first_child(plist_t node); | 187 | PLIST_API uint32_t plist_array_get_size(plist_t node); |
| 133 | |||
| 134 | 188 | ||
| 135 | /** | 189 | /** |
| 136 | * Get the next sibling of a node | 190 | * Get the nth item in a #PLIST_ARRAY node. |
| 137 | * | 191 | * |
| 138 | * @param node the next sibling | 192 | * @param node the node of type #PLIST_ARRAY |
| 193 | * @param n the index of the item to get. Range is [0, array_size[ | ||
| 194 | * @return the nth item or NULL if node is not of type #PLIST_ARRAY | ||
| 139 | */ | 195 | */ |
| 140 | PLIST_API plist_t plist_get_next_sibling(plist_t node); | 196 | PLIST_API plist_t plist_array_get_item(plist_t node, uint32_t n); |
| 141 | |||
| 142 | 197 | ||
| 143 | /** | 198 | /** |
| 144 | * Get the previous sibling of a node | 199 | * Set the nth item in a #PLIST_ARRAY node. |
| 200 | * The previous item at index n will be freed using #plist_free | ||
| 145 | * | 201 | * |
| 146 | * @param node the previous sibling | 202 | * @param node the node of type #PLIST_ARRAY |
| 203 | * @param item the new item at index n | ||
| 204 | * @param n the index of the item to get. Range is [0, array_size[. Assert if n is not in range. | ||
| 147 | */ | 205 | */ |
| 148 | PLIST_API plist_t plist_get_prev_sibling(plist_t node); | 206 | PLIST_API void plist_array_set_item(plist_t node, plist_t item, uint32_t n); |
| 149 | 207 | ||
| 150 | /** | 208 | /** |
| 151 | * Get the parent of a node | 209 | * Append a new item at the end of a #PLIST_ARRAY node. |
| 152 | * | 210 | * |
| 153 | * @param node the parent (NULL if node is root) | 211 | * @param node the node of type #PLIST_ARRAY |
| 212 | * @param item the new item | ||
| 154 | */ | 213 | */ |
| 155 | PLIST_API plist_t plist_get_parent(plist_t node); | 214 | PLIST_API void plist_array_append_item(plist_t node, plist_t item); |
| 156 | 215 | ||
| 157 | /** | 216 | /** |
| 158 | * Get the nth child of a #PLIST_ARRAY node. | 217 | * Insert a new item at position n in a #PLIST_ARRAY node. |
| 159 | * | 218 | * |
| 160 | * @param node the node of type #PLIST_ARRAY | 219 | * @param node the node of type #PLIST_ARRAY |
| 161 | * @param n the index of the child to get. Range is [0, array_size[ | 220 | * @param item the new item to insert |
| 162 | * @return the nth children or NULL if node is not of type #PLIST_ARRAY | 221 | * @param n The position at which the node will be stored. Range is [0, array_size[. Assert if n is not in range. |
| 163 | */ | 222 | */ |
| 164 | PLIST_API plist_t plist_get_array_nth_el(plist_t node, uint32_t n); | 223 | PLIST_API void plist_array_insert_item(plist_t node, plist_t item, uint32_t n); |
| 165 | 224 | ||
| 166 | /** | 225 | /** |
| 167 | * Get the child of a #PLIST_DICT node from the associated key value. | 226 | * Remove an existing position in a #PLIST_ARRAY node. |
| 227 | * Removed position will be freed using #plist_free | ||
| 168 | * | 228 | * |
| 169 | * @param node the node of type #PLIST_DICT | 229 | * @param node the node of type #PLIST_ARRAY |
| 170 | * @param key the key associated to the requested value | 230 | * @param n The position to remove. Range is [0, array_size[. Assert if n is not in range. |
| 171 | * @return the key associated value or NULL if node is not of type #PLIST_DICT | ||
| 172 | */ | 231 | */ |
| 173 | PLIST_API plist_t plist_get_dict_el_from_key(plist_t node, const char *key); | 232 | PLIST_API void plist_array_remove_item(plist_t node, uint32_t n); |
| 174 | |||
| 175 | 233 | ||
| 176 | /******************************************** | 234 | /******************************************** |
| 177 | * * | 235 | * * |
| 178 | * Setters * | 236 | * Dictionary functions * |
| 179 | * * | 237 | * * |
| 180 | ********************************************/ | 238 | ********************************************/ |
| 181 | 239 | ||
| 182 | /** | 240 | /** |
| 183 | * Add a subnode to a node. The node must be of a structured type | 241 | * Get size of a #PLIST_DICT node. |
| 184 | * (ie #PLIST_DICT or #PLIST_ARRAY). This function fails silently | ||
| 185 | * if subnode already has a father. | ||
| 186 | * | ||
| 187 | * @param node the node to add a children to | ||
| 188 | * @param subnode the children node | ||
| 189 | */ | ||
| 190 | PLIST_API void plist_add_sub_node(plist_t node, plist_t subnode); | ||
| 191 | |||
| 192 | /** | ||
| 193 | * Add a subnode of type #PLIST_KEY to a node. The node must be of a structured type | ||
| 194 | * (ie #PLIST_DICT or #PLIST_ARRAY). | ||
| 195 | * | ||
| 196 | * @param node the node to add a children to | ||
| 197 | * @param val the key value encoded as an ASCII string (must be null terminated) | ||
| 198 | */ | ||
| 199 | PLIST_API void plist_add_sub_key_el(plist_t node, const char *val); | ||
| 200 | |||
| 201 | /** | ||
| 202 | * Add a subnode of type #PLIST_STRING to a node. The node must be of a structured type | ||
| 203 | * (ie #PLIST_DICT or #PLIST_ARRAY). | ||
| 204 | * | 242 | * |
| 205 | * @param node the node to add a children to | 243 | * @param node the node of type #PLIST_DICT |
| 206 | * @param val the string value encoded as an ASCII or UTF-8 string (must be null terminated) | 244 | * @return size of the #PLIST_DICT node |
| 207 | */ | 245 | */ |
| 208 | PLIST_API void plist_add_sub_string_el(plist_t node, const char *val); | 246 | PLIST_API uint32_t plist_dict_get_size(plist_t node); |
| 209 | 247 | ||
| 210 | /** | 248 | /** |
| 211 | * Add a subnode of type #PLIST_BOOLEAN to a node. The node must be of a structured type | 249 | * Get the nth item in a #PLIST_DICT node. |
| 212 | * (ie #PLIST_DICT or #PLIST_ARRAY). | ||
| 213 | * | 250 | * |
| 214 | * @param node the node to add a children to | 251 | * @param node the node of type #PLIST_DICT |
| 215 | * @param val the boolean value (TRUE or FALSE) | 252 | * @param key the identifier of the item to get. |
| 216 | */ | 253 | * @return the item or NULL if node is not of type #PLIST_DICT |
| 217 | PLIST_API void plist_add_sub_bool_el(plist_t node, uint8_t val); | ||
| 218 | |||
| 219 | /** | ||
| 220 | * Add a subnode of type #PLIST_UINT to a node. The node must be of a structured type | ||
| 221 | * (ie #PLIST_DICT or #PLIST_ARRAY). | ||
| 222 | * | ||
| 223 | * @param node the node to add a children to | ||
| 224 | * @param val the unsigned integer value | ||
| 225 | */ | 254 | */ |
| 226 | PLIST_API void plist_add_sub_uint_el(plist_t node, uint64_t val); | 255 | PLIST_API plist_t plist_dict_get_item(plist_t node, const char* key); |
| 227 | 256 | ||
| 228 | /** | 257 | /** |
| 229 | * Add a subnode of type #PLIST_REAL to a node. The node must be of a structured type | 258 | * Set item identified by key in a #PLIST_DICT node. |
| 230 | * (ie #PLIST_DICT or #PLIST_ARRAY). | 259 | * The previous item at index n will be freed using #plist_free |
| 231 | * | 260 | * |
| 232 | * @param node the node to add a children to | 261 | * @param node the node of type #PLIST_DICT |
| 233 | * @param val the real value | 262 | * @param item the new item associated to key |
| 263 | * @param key the identifier of the item to get. Assert if identifier is not present. | ||
| 234 | */ | 264 | */ |
| 235 | PLIST_API void plist_add_sub_real_el(plist_t node, double val); | 265 | PLIST_API void plist_dict_set_item(plist_t node, plist_t item, const char* key); |
| 236 | 266 | ||
| 237 | /** | 267 | /** |
| 238 | * Add a subnode of type #PLIST_DATA to a node. The node must be of a structured type | 268 | * Insert a new item at position n in a #PLIST_DICT node. |
| 239 | * (ie #PLIST_DICT or #PLIST_ARRAY). | ||
| 240 | * | 269 | * |
| 241 | * @param node the node to add a children to | 270 | * @param node the node of type #PLIST_DICT |
| 242 | * @param val the binary buffer | 271 | * @param item the new item to insert |
| 243 | * @param length the length of the buffer | 272 | * @param key The identifier of the item to insert. Assert if identifier already present. |
| 244 | */ | 273 | */ |
| 245 | PLIST_API void plist_add_sub_data_el(plist_t node, const char *val, uint64_t length); | 274 | PLIST_API void plist_dict_insert_item(plist_t node, plist_t item, const char* key); |
| 246 | 275 | ||
| 247 | /** | 276 | /** |
| 248 | * Add a subnode of type #PLIST_DATE to a node. The node must be of a structured type | 277 | * Remove an existing position in a #PLIST_DICT node. |
| 249 | * (ie #PLIST_DICT or #PLIST_ARRAY). | 278 | * Removed position will be freed using #plist_free |
| 250 | * | 279 | * |
| 251 | * @param node the node to add a children to | 280 | * @param node the node of type #PLIST_DICT |
| 252 | * @param sec the number of seconds since 01/01/2001 | 281 | * @param key The identifier of the item to remove. Assert if identifier is not present. |
| 253 | * @param usec the number of microseconds | ||
| 254 | */ | 282 | */ |
| 255 | PLIST_API void plist_add_sub_date_el(plist_t node, int32_t sec, int32_t usec); | 283 | PLIST_API void plist_dict_remove_item(plist_t node, const char* key); |
| 256 | 284 | ||
| 257 | 285 | ||
| 258 | /******************************************** | 286 | /******************************************** |
| @@ -262,6 +290,13 @@ extern "C" { | |||
| 262 | ********************************************/ | 290 | ********************************************/ |
| 263 | 291 | ||
| 264 | /** | 292 | /** |
| 293 | * Get the parent of a node | ||
| 294 | * | ||
| 295 | * @param node the parent (NULL if node is root) | ||
| 296 | */ | ||
| 297 | PLIST_API plist_t plist_get_parent(plist_t node); | ||
| 298 | |||
| 299 | /** | ||
| 265 | * Get the #plist_type of a node. | 300 | * Get the #plist_type of a node. |
| 266 | * | 301 | * |
| 267 | * @param node the node | 302 | * @param node the node |
| @@ -454,7 +489,6 @@ extern "C" { | |||
| 454 | PLIST_API void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist); | 489 | PLIST_API void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist); |
| 455 | 490 | ||
| 456 | 491 | ||
| 457 | |||
| 458 | /******************************************** | 492 | /******************************************** |
| 459 | * * | 493 | * * |
| 460 | * Utils * | 494 | * Utils * |
| @@ -488,6 +522,143 @@ extern "C" { | |||
| 488 | */ | 522 | */ |
| 489 | PLIST_API char plist_compare_node_value(plist_t node_l, plist_t node_r); | 523 | PLIST_API char plist_compare_node_value(plist_t node_l, plist_t node_r); |
| 490 | 524 | ||
| 525 | |||
| 526 | //DEPRECATED API BELOW | ||
| 527 | |||
| 528 | /*@}*/ | ||
| 529 | /** | ||
| 530 | * \defgroup DeprecatedAPI Deprecated libplist API | ||
| 531 | */ | ||
| 532 | /*@{*/ | ||
| 533 | |||
| 534 | /******************************************** | ||
| 535 | * * | ||
| 536 | * Tree navigation * | ||
| 537 | * * | ||
| 538 | ********************************************/ | ||
| 539 | |||
| 540 | /** | ||
| 541 | * Get the first child of a node | ||
| 542 | * | ||
| 543 | * @param node the first child | ||
| 544 | */ | ||
| 545 | PLIST_API plist_t plist_get_first_child(plist_t node); | ||
| 546 | |||
| 547 | /** | ||
| 548 | * Get the next sibling of a node | ||
| 549 | * | ||
| 550 | * @param node the next sibling | ||
| 551 | */ | ||
| 552 | PLIST_API plist_t plist_get_next_sibling(plist_t node); | ||
| 553 | |||
| 554 | /** | ||
| 555 | * Get the previous sibling of a node | ||
| 556 | * | ||
| 557 | * @param node the previous sibling | ||
| 558 | */ | ||
| 559 | PLIST_API plist_t plist_get_prev_sibling(plist_t node); | ||
| 560 | |||
| 561 | /** | ||
| 562 | * Get the nth child of a #PLIST_ARRAY node. | ||
| 563 | * | ||
| 564 | * @param node the node of type #PLIST_ARRAY | ||
| 565 | * @param n the index of the child to get. Range is [0, array_size[ | ||
| 566 | * @return the nth children or NULL if node is not of type #PLIST_ARRAY | ||
| 567 | */ | ||
| 568 | PLIST_API plist_t plist_get_array_nth_el(plist_t node, uint32_t n); | ||
| 569 | |||
| 570 | /** | ||
| 571 | * Get the child of a #PLIST_DICT node from the associated key value. | ||
| 572 | * | ||
| 573 | * @param node the node of type #PLIST_DICT | ||
| 574 | * @param key the key associated to the requested value | ||
| 575 | * @return the key associated value or NULL if node is not of type #PLIST_DICT | ||
| 576 | */ | ||
| 577 | PLIST_API plist_t plist_get_dict_el_from_key(plist_t node, const char *key); | ||
| 578 | |||
| 579 | |||
| 580 | /******************************************** | ||
| 581 | * * | ||
| 582 | * Setters * | ||
| 583 | * * | ||
| 584 | ********************************************/ | ||
| 585 | |||
| 586 | /** | ||
| 587 | * Add a subnode to a node. The node must be of a structured type | ||
| 588 | * (ie #PLIST_DICT or #PLIST_ARRAY). This function fails silently | ||
| 589 | * if subnode already has a father. | ||
| 590 | * | ||
| 591 | * @param node the node to add a children to | ||
| 592 | * @param subnode the children node | ||
| 593 | */ | ||
| 594 | PLIST_API void plist_add_sub_node(plist_t node, plist_t subnode); | ||
| 595 | |||
| 596 | /** | ||
| 597 | * Add a subnode of type #PLIST_KEY to a node. The node must be of a structured type | ||
| 598 | * (ie #PLIST_DICT or #PLIST_ARRAY). | ||
| 599 | * | ||
| 600 | * @param node the node to add a children to | ||
| 601 | * @param val the key value encoded as an ASCII string (must be null terminated) | ||
| 602 | */ | ||
| 603 | PLIST_API void plist_add_sub_key_el(plist_t node, const char *val); | ||
| 604 | |||
| 605 | /** | ||
| 606 | * Add a subnode of type #PLIST_STRING to a node. The node must be of a structured type | ||
| 607 | * (ie #PLIST_DICT or #PLIST_ARRAY). | ||
| 608 | * | ||
| 609 | * @param node the node to add a children to | ||
| 610 | * @param val the string value encoded as an ASCII or UTF-8 string (must be null terminated) | ||
| 611 | */ | ||
| 612 | PLIST_API void plist_add_sub_string_el(plist_t node, const char *val); | ||
| 613 | |||
| 614 | /** | ||
| 615 | * Add a subnode of type #PLIST_BOOLEAN to a node. The node must be of a structured type | ||
| 616 | * (ie #PLIST_DICT or #PLIST_ARRAY). | ||
| 617 | * | ||
| 618 | * @param node the node to add a children to | ||
| 619 | * @param val the boolean value (TRUE or FALSE) | ||
| 620 | */ | ||
| 621 | PLIST_API void plist_add_sub_bool_el(plist_t node, uint8_t val); | ||
| 622 | |||
| 623 | /** | ||
| 624 | * Add a subnode of type #PLIST_UINT to a node. The node must be of a structured type | ||
| 625 | * (ie #PLIST_DICT or #PLIST_ARRAY). | ||
| 626 | * | ||
| 627 | * @param node the node to add a children to | ||
| 628 | * @param val the unsigned integer value | ||
| 629 | */ | ||
| 630 | PLIST_API void plist_add_sub_uint_el(plist_t node, uint64_t val); | ||
| 631 | |||
| 632 | /** | ||
| 633 | * Add a subnode of type #PLIST_REAL to a node. The node must be of a structured type | ||
| 634 | * (ie #PLIST_DICT or #PLIST_ARRAY). | ||
| 635 | * | ||
| 636 | * @param node the node to add a children to | ||
| 637 | * @param val the real value | ||
| 638 | */ | ||
| 639 | PLIST_API void plist_add_sub_real_el(plist_t node, double val); | ||
| 640 | |||
| 641 | /** | ||
| 642 | * Add a subnode of type #PLIST_DATA to a node. The node must be of a structured type | ||
| 643 | * (ie #PLIST_DICT or #PLIST_ARRAY). | ||
| 644 | * | ||
| 645 | * @param node the node to add a children to | ||
| 646 | * @param val the binary buffer | ||
| 647 | * @param length the length of the buffer | ||
| 648 | */ | ||
| 649 | PLIST_API void plist_add_sub_data_el(plist_t node, const char *val, uint64_t length); | ||
| 650 | |||
| 651 | /** | ||
| 652 | * Add a subnode of type #PLIST_DATE to a node. The node must be of a structured type | ||
| 653 | * (ie #PLIST_DICT or #PLIST_ARRAY). | ||
| 654 | * | ||
| 655 | * @param node the node to add a children to | ||
| 656 | * @param sec the number of seconds since 01/01/2001 | ||
| 657 | * @param usec the number of microseconds | ||
| 658 | */ | ||
| 659 | PLIST_API void plist_add_sub_date_el(plist_t node, int32_t sec, int32_t usec); | ||
| 660 | |||
| 661 | |||
| 491 | /*@}*/ | 662 | /*@}*/ |
| 492 | 663 | ||
| 493 | 664 | ||
