2 * CoreAttributesTreeIterator.h - TaskJuggler
4 * Copyright (c) 2001, 2002, 2003, 2004 by Chris Schlaeger <cs@kde.org>
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.
13 #ifndef _CoreAttributesTreeIterator_h_
14 #define _CoreAttributesTreeIterator_h_
16 enum IterationMode { leavesOnly = 0, parentAfterLeaves };
21 class CoreAttributesTreeIteratorT
25 CoreAttributesTreeIteratorT(T* root, IterationMode m = leavesOnly);
26 ~CoreAttributesTreeIteratorT() { }
28 T* operator*() { return current; }
39 CoreAttributesTreeIteratorT<T>::CoreAttributesTreeIteratorT(T* r,
45 while (current->hasSubs())
46 current = current->getSubList().getFirst();
51 CoreAttributesTreeIteratorT<T>::operator++()
56 while (current != root)
58 // Find the current CA in the parent's sub list.
59 CoreAttributesListIterator
60 cli(current->getParent()->getSubListIterator());
61 for ( ; *cli != current; ++cli)
63 // Check if there is another task in the sub list.
67 // Find the first leaf in this sub list.
69 while (current->hasSubs())
70 current = current->getSubList().getFirst();
71 // This is the new current task.
74 // End of sub list reached. Try parent node then.
75 current = current->getParent();
76 if (iMode == parentAfterLeaves)
82 typedef CoreAttributesTreeIteratorT<CoreAttributes> CoreAttributesTreeIterator;
83 typedef CoreAttributesTreeIteratorT<const CoreAttributes>
84 ConstCoreAttributesTreeIterator;