Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: ui/base/models/tree_node_iterator.h

Issue 7003039: ui/base/models: Add empty() accessor to TreeNode class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sky review Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_BASE_MODELS_TREE_NODE_ITERATOR_H_ 5 #ifndef UI_BASE_MODELS_TREE_NODE_ITERATOR_H_
6 #define UI_BASE_MODELS_TREE_NODE_ITERATOR_H_ 6 #define UI_BASE_MODELS_TREE_NODE_ITERATOR_H_
7 #pragma once 7 #pragma once
8 8
9 #include <stack> 9 #include <stack>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 13
14 namespace ui { 14 namespace ui {
15 15
16 // Iterator that iterates over the descendants of a node. The iteration does 16 // Iterator that iterates over the descendants of a node. The iteration does
17 // not include the node itself, only the descendants. The following illustrates 17 // not include the node itself, only the descendants. The following illustrates
18 // typical usage: 18 // typical usage:
19 // while (iterator.has_next()) { 19 // while (iterator.has_next()) {
20 // Node* node = iterator.Next(); 20 // Node* node = iterator.Next();
21 // // do something with node. 21 // // do something with node.
22 // } 22 // }
23 template <class NodeType> 23 template <class NodeType>
24 class TreeNodeIterator { 24 class TreeNodeIterator {
25 public: 25 public:
26 explicit TreeNodeIterator(NodeType* node) { 26 explicit TreeNodeIterator(NodeType* node) {
27 if (node->child_count() > 0) 27 if (!node->empty())
28 positions_.push(Position<NodeType>(node, 0)); 28 positions_.push(Position<NodeType>(node, 0));
29 } 29 }
30 30
31 // Returns true if there are more descendants. 31 // Returns true if there are more descendants.
32 bool has_next() const { return !positions_.empty(); } 32 bool has_next() const { return !positions_.empty(); }
33 33
34 // Returns the next descendant. 34 // Returns the next descendant.
35 NodeType* Next() { 35 NodeType* Next() {
36 if (!has_next()) { 36 if (!has_next()) {
37 NOTREACHED(); 37 NOTREACHED();
(...skipping 28 matching lines...) Expand all
66 }; 66 };
67 67
68 std::stack<Position<NodeType> > positions_; 68 std::stack<Position<NodeType> > positions_;
69 69
70 DISALLOW_COPY_AND_ASSIGN(TreeNodeIterator); 70 DISALLOW_COPY_AND_ASSIGN(TreeNodeIterator);
71 }; 71 };
72 72
73 } // namespace ui 73 } // namespace ui
74 74
75 #endif // UI_BASE_MODELS_TREE_NODE_ITERATOR_H_ 75 #endif // UI_BASE_MODELS_TREE_NODE_ITERATOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc ('k') | ui/base/models/tree_node_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698