diff options
| -rw-r--r-- | include/plist/plist.h | 7 | ||||
| -rw-r--r-- | src/plist.c | 5 | ||||
| -rw-r--r-- | swig/plist.i | 8 |
3 files changed, 20 insertions, 0 deletions
diff --git a/include/plist/plist.h b/include/plist/plist.h index a075fc6..6388603 100644 --- a/include/plist/plist.h +++ b/include/plist/plist.h | |||
| @@ -148,6 +148,13 @@ extern "C" { | |||
| 148 | PLIST_API plist_t plist_get_prev_sibling(plist_t node); | 148 | PLIST_API plist_t plist_get_prev_sibling(plist_t node); |
| 149 | 149 | ||
| 150 | /** | 150 | /** |
| 151 | * Get the parent of a node | ||
| 152 | * | ||
| 153 | * @param node the parent (NULL if node is root) | ||
| 154 | */ | ||
| 155 | PLIST_API plist_t plist_get_parent(plist_t node); | ||
| 156 | |||
| 157 | /** | ||
| 151 | * Get the nth child of a #PLIST_ARRAY node. | 158 | * Get the nth child of a #PLIST_ARRAY node. |
| 152 | * | 159 | * |
| 153 | * @param node the node of type #PLIST_ARRAY | 160 | * @param node the node of type #PLIST_ARRAY |
diff --git a/src/plist.c b/src/plist.c index 8c326af..143418d 100644 --- a/src/plist.c +++ b/src/plist.c | |||
| @@ -195,6 +195,11 @@ plist_t plist_get_prev_sibling(plist_t node) | |||
| 195 | return (plist_t) g_node_prev_sibling((GNode *) node); | 195 | return (plist_t) g_node_prev_sibling((GNode *) node); |
| 196 | } | 196 | } |
| 197 | 197 | ||
| 198 | plist_t plist_get_parent(plist_t node) | ||
| 199 | { | ||
| 200 | return node ? (plist_t) ((GNode *) node)->parent : NULL; | ||
| 201 | } | ||
| 202 | |||
| 198 | plist_t plist_get_array_nth_el(plist_t node, uint32_t n) | 203 | plist_t plist_get_array_nth_el(plist_t node, uint32_t n) |
| 199 | { | 204 | { |
| 200 | plist_t ret = NULL; | 205 | plist_t ret = NULL; |
diff --git a/swig/plist.i b/swig/plist.i index b6f9f78..7240817 100644 --- a/swig/plist.i +++ b/swig/plist.i | |||
| @@ -141,6 +141,14 @@ typedef struct { | |||
| 141 | return NULL; | 141 | return NULL; |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | PListNode* get_parent() { | ||
| 145 | plist_t node = plist_get_parent( $self->node ); | ||
| 146 | if (node) { | ||
| 147 | return allocate_wrapper(node, 1); | ||
| 148 | } | ||
| 149 | return NULL; | ||
| 150 | } | ||
| 151 | |||
| 144 | %newobject as_key; | 152 | %newobject as_key; |
| 145 | char* as_key() { | 153 | char* as_key() { |
| 146 | char* k = NULL; | 154 | char* k = NULL; |
