[834] | 1 | /* |
---|
| 2 | Copyright (c) 2003-2006, Troy Aaron Johnson |
---|
| 3 | All rights reserved. |
---|
| 4 | |
---|
| 5 | Redistribution and use in source and binary forms, with or without |
---|
| 6 | modification, are permitted provided that the following conditions |
---|
| 7 | are met: |
---|
| 8 | |
---|
| 9 | * Redistributions of source code must retain the above copyright |
---|
| 10 | notice, this list of conditions and the following disclaimer. |
---|
| 11 | * Redistributions in binary form must reproduce the above copyright |
---|
| 12 | notice, this list of conditions and the following disclaimer in the |
---|
| 13 | documentation and/or other materials provided with the distribution. |
---|
| 14 | * Neither the name of Troy Aaron Johnson nor the names of any |
---|
| 15 | contributors may be used to endorse or promote products derived from |
---|
| 16 | this software without specific prior written permission. |
---|
| 17 | |
---|
| 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
| 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
| 28 | POSSIBILITY OF SUCH DAMAGE. |
---|
| 29 | */ |
---|
| 30 | |
---|
| 31 | template<class N> |
---|
| 32 | template<class T, class R, class P> |
---|
| 33 | void tree<N>::tree_iterator<T, R, P>::post_inc(tree_node<N>*& current, long& depth) |
---|
| 34 | { |
---|
| 35 | assert(current != NULL); |
---|
| 36 | |
---|
| 37 | if (current->next_sibling == NULL) |
---|
| 38 | { |
---|
| 39 | current = current->parent; |
---|
| 40 | depth--; |
---|
| 41 | } |
---|
| 42 | else |
---|
| 43 | { |
---|
| 44 | current = current->next_sibling; |
---|
| 45 | while (current->first_child != NULL) |
---|
| 46 | { |
---|
| 47 | current = current->first_child; |
---|
| 48 | depth++; |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | template<class N> |
---|
| 54 | template<class T, class R, class P> |
---|
| 55 | void tree<N>::tree_iterator<T, R, P>::post_dec(tree_node<N>*& current, long& depth) |
---|
| 56 | { |
---|
| 57 | assert(current != NULL); |
---|
| 58 | |
---|
| 59 | if(current->last_child == NULL) |
---|
| 60 | { |
---|
| 61 | while (current->prev_sibling == NULL) |
---|
| 62 | { |
---|
| 63 | current = current->parent; |
---|
| 64 | depth--; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | current = current->prev_sibling; |
---|
| 68 | } |
---|
| 69 | else |
---|
| 70 | { |
---|
| 71 | current = current->last_child; |
---|
| 72 | depth++; |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | template<class N> |
---|
| 77 | template<class T, class R, class P> |
---|
| 78 | void tree<N>::tree_iterator<T, R, P>::pre_inc(tree_node<N>*& current, long& depth) |
---|
| 79 | { |
---|
| 80 | assert(current != NULL); |
---|
| 81 | |
---|
| 82 | if (current->first_child != NULL) |
---|
| 83 | { |
---|
| 84 | current = current->first_child; |
---|
| 85 | depth++; |
---|
| 86 | } |
---|
| 87 | else |
---|
| 88 | { |
---|
| 89 | while (current->next_sibling == NULL) |
---|
| 90 | { |
---|
| 91 | current = current->parent; |
---|
| 92 | depth--; |
---|
| 93 | if (current == NULL) |
---|
| 94 | return; |
---|
| 95 | } |
---|
| 96 | current = current->next_sibling; |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | template<class N> |
---|
| 101 | template<class T, class R, class P> |
---|
| 102 | void tree<N>::tree_iterator<T, R, P>::pre_dec(tree_node<N>*& current, long& depth) |
---|
| 103 | { |
---|
| 104 | assert(current != NULL); |
---|
| 105 | |
---|
| 106 | if (current->prev_sibling) |
---|
| 107 | { |
---|
| 108 | current = current->prev_sibling; |
---|
| 109 | while (current->last_child != NULL) |
---|
| 110 | { |
---|
| 111 | current = current->last_child; |
---|
| 112 | depth++; |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | else |
---|
| 116 | { |
---|
| 117 | current = current->parent; |
---|
| 118 | depth--; |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | template<class N> |
---|
| 123 | template<class T, class R, class P> |
---|
| 124 | inline void tree<N>::tree_iterator<T, R, P>::sib_inc(tree_node<N>*& current) |
---|
| 125 | { |
---|
| 126 | if (current != NULL) |
---|
| 127 | current = current->next_sibling; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | template<class N> |
---|
| 131 | template<class T, class R, class P> |
---|
| 132 | inline void tree<N>::tree_iterator<T, R, P>::sib_dec(tree_node<N>*& current) |
---|
| 133 | { |
---|
| 134 | if (current != NULL) |
---|
| 135 | current = current->prev_sibling; |
---|
| 136 | } |
---|