source: trunk/source/visualization/XXX/include/tree/const_iterator.h @ 834

Last change on this file since 834 was 834, checked in by garnier, 16 years ago

import all except CVS

File size: 2.7 KB
Line 
1/*
2Copyright (c) 2003-2006, Troy Aaron Johnson
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions
7are 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
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28POSSIBILITY OF SUCH DAMAGE.
29*/
30
31/** An iterator that can be used to inspect the tree but not modify it.
32 */
33class const_iterator : public tree_iterator<N, const N&, const N*>
34{
35  friend class tree;
36
37  /* allows iterator to call the protected constructor below */
38  friend tree<N>::iterator::operator const_iterator() const;
39
40  private:
41
42    /* this typedef is very convenient and allows Java-like code */
43    typedef tree_iterator<N, const N&, const N*> super;
44
45  protected:
46
47    const_iterator(tree_node<N>* current) : super(current) { }
48
49  public:
50
51    const_iterator(void) { }
52    const_iterator(const const_iterator& iter) : super(iter) { }
53
54    typename super::reference
55    operator * (void) const { return this->current->data; }
56
57    typename super::pointer
58    operator -> (void) const { return &(this->current->data); }
59
60    const_sibling_iterator beginChildren(void) const
61    { return const_sibling_iterator(const_iterator(this->current->first_child)); }
62
63    const_sibling_iterator endChildren(void) const
64    { return const_sibling_iterator(const_iterator(NULL)); }
65
66    const_iterator parent(void) const
67    { return this->current->parent; }
68
69    /** Determines the size of the subtree below and including this position.
70     *
71     * @return The size of this subtree.
72     */
73    size_t size(void) const;
74};
Note: See TracBrowser for help on using the repository browser.