OSDN Git Service

Removing redundant error checking related to booking declaration.
[tjqt4port/tj2qt4.git] / taskjuggler / CoreAttributesTreeIterator.h
1 /*
2  * CoreAttributesTreeIterator.h - TaskJuggler
3  *
4  * Copyright (c) 2001, 2002, 2003, 2004 by Chris Schlaeger <cs@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of version 2 of the GNU General Public License as
8  * published by the Free Software Foundation.
9  *
10  * $Id$
11  */
12
13 #ifndef _CoreAttributesTreeIterator_h_
14 #define _CoreAttributesTreeIterator_h_
15
16 enum IterationMode { leavesOnly = 0, parentAfterLeaves };
17
18 class CoreAttributes;
19
20 template <class T>
21 class CoreAttributesTreeIteratorT
22 {
23 public:
24
25     CoreAttributesTreeIteratorT(T* root, IterationMode m = leavesOnly);
26     ~CoreAttributesTreeIteratorT() { }
27
28     T* operator*() { return current; }
29     T* operator++();
30
31 protected:
32     T* current;
33 private:
34     IterationMode iMode;
35     T* root;
36 } ;
37
38 template <class T>
39 CoreAttributesTreeIteratorT<T>::CoreAttributesTreeIteratorT(T* r,
40                                                             IterationMode m) :
41     current(r),
42     iMode(m),
43     root(r)
44 {
45     while (current->hasSubs())
46         current = current->getSubList().getFirst();
47 }
48
49 template <class T>
50 T*
51 CoreAttributesTreeIteratorT<T>::operator++()
52 {
53     if (current == 0)
54         return 0;
55
56     while (current != root)
57     {
58         // Find the current CA in the parent's sub list.
59         CoreAttributesListIterator
60             cli(current->getParent()->getSubListIterator());
61         for ( ; *cli != current; ++cli)
62             ;
63         // Check if there is another task in the sub list.
64         ++cli;
65         if (*cli != 0)
66         {
67             // Find the first leaf in this sub list.
68             current = *cli;
69             while (current->hasSubs())
70                 current = current->getSubList().getFirst();
71             // This is the new current task.
72             return current;
73         }
74         // End of sub list reached. Try parent node then.
75         current = current->getParent();
76         if (iMode == parentAfterLeaves)
77             return current;
78     }
79     return (current = 0);
80 }
81
82 typedef CoreAttributesTreeIteratorT<CoreAttributes> CoreAttributesTreeIterator;
83 typedef CoreAttributesTreeIteratorT<const CoreAttributes>
84     ConstCoreAttributesTreeIterator;
85
86 #endif
87