diff options
Diffstat (limited to 'libcnary/node_iterator.c')
| -rw-r--r-- | libcnary/node_iterator.c | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/libcnary/node_iterator.c b/libcnary/node_iterator.c deleted file mode 100644 index e629b73..0000000 --- a/libcnary/node_iterator.c +++ /dev/null | |||
| @@ -1,80 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * node_iterator.c | ||
| 3 | * | ||
| 4 | * Created on: Mar 8, 2011 | ||
| 5 | * Author: posixninja | ||
| 6 | * | ||
| 7 | * Copyright (c) 2011 Joshua Hill. All Rights Reserved. | ||
| 8 | * | ||
| 9 | * This library is free software; you can redistribute it and/or | ||
| 10 | * modify it under the terms of the GNU Lesser General Public | ||
| 11 | * License as published by the Free Software Foundation; either | ||
| 12 | * version 2.1 of the License, or (at your option) any later version. | ||
| 13 | * | ||
| 14 | * This library is distributed in the hope that it will be useful, | ||
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 17 | * Lesser General Public License for more details. | ||
| 18 | * | ||
| 19 | * You should have received a copy of the GNU Lesser General Public | ||
| 20 | * License along with this library; if not, write to the Free Software | ||
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 22 | */ | ||
| 23 | |||
| 24 | #include <stdio.h> | ||
| 25 | #include <stdlib.h> | ||
| 26 | #include <string.h> | ||
| 27 | |||
| 28 | #include "node.h" | ||
| 29 | #include "node_list.h" | ||
| 30 | #include "node_iterator.h" | ||
| 31 | |||
| 32 | void node_iterator_destroy(node_iterator_t* iterator) { | ||
| 33 | if(iterator) { | ||
| 34 | free(iterator); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | node_iterator_t* node_iterator_create(node_list_t* list) { | ||
| 39 | node_iterator_t* iterator = (node_iterator_t*) malloc(sizeof(node_iterator_t)); | ||
| 40 | if(iterator == NULL) { | ||
| 41 | return NULL; | ||
| 42 | } | ||
| 43 | memset(iterator, '\0', sizeof(node_iterator_t)); | ||
| 44 | |||
| 45 | iterator->count = 0; | ||
| 46 | iterator->position = 0; | ||
| 47 | |||
| 48 | iterator->end = NULL; | ||
| 49 | iterator->begin = NULL; | ||
| 50 | iterator->value = NULL; | ||
| 51 | |||
| 52 | iterator->list = NULL; | ||
| 53 | iterator->next = node_iterator_next; | ||
| 54 | iterator->bind = node_iterator_bind; | ||
| 55 | |||
| 56 | |||
| 57 | if(list != NULL) { | ||
| 58 | iterator->bind(iterator, list); | ||
| 59 | } | ||
| 60 | |||
| 61 | return iterator; | ||
| 62 | } | ||
| 63 | |||
| 64 | node_t* node_iterator_next(node_iterator_t* iterator) { | ||
| 65 | node_t* node = iterator->value; | ||
| 66 | if (node) { | ||
| 67 | iterator->value = node->next; | ||
| 68 | } | ||
| 69 | iterator->position++; | ||
| 70 | return node; | ||
| 71 | } | ||
| 72 | |||
| 73 | int node_iterator_bind(node_iterator_t* iterator, node_list_t* list) { | ||
| 74 | iterator->position = 0; | ||
| 75 | iterator->end = list->end; | ||
| 76 | iterator->count = list->count; | ||
| 77 | iterator->begin = list->begin; | ||
| 78 | iterator->value = list->begin; | ||
| 79 | return 0; | ||
| 80 | } | ||
