OLD | NEW |
---|---|
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_MODEL_H_ | 5 #ifndef UI_BASE_MODELS_TREE_NODE_MODEL_H_ |
6 #define UI_BASE_MODELS_TREE_NODE_MODEL_H_ | 6 #define UI_BASE_MODELS_TREE_NODE_MODEL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 // Returns the parent node, or NULL if this is the root node. | 105 // Returns the parent node, or NULL if this is the root node. |
106 const NodeType* parent() const { return parent_; } | 106 const NodeType* parent() const { return parent_; } |
107 NodeType* parent() { return parent_; } | 107 NodeType* parent() { return parent_; } |
108 | 108 |
109 // Returns true if this is the root node. | 109 // Returns true if this is the root node. |
110 bool is_root() const { return parent_ == NULL; } | 110 bool is_root() const { return parent_ == NULL; } |
111 | 111 |
112 // Returns the number of children. | 112 // Returns the number of children. |
113 int child_count() const { return static_cast<int>(children_->size()); } | 113 int child_count() const { return static_cast<int>(children_->size()); } |
114 | 114 |
115 // Returns whether the |children_| is empty. | |
sky
2011/06/08 15:52:26
Returns true if this nodes has no children.
tfarina
2011/06/08 17:33:43
Done.
| |
116 bool empty() const { return children_.empty(); } | |
117 | |
115 // Returns the number of all nodes in the subtree rooted at this node, | 118 // Returns the number of all nodes in the subtree rooted at this node, |
116 // including this node. | 119 // including this node. |
117 int GetTotalNodeCount() const { | 120 int GetTotalNodeCount() const { |
118 int count = 1; // Start with one to include the node itself. | 121 int count = 1; // Start with one to include the node itself. |
119 for (size_t i = 0; i < children_->size(); ++i) | 122 for (size_t i = 0; i < children_->size(); ++i) |
120 count += children_[i]->GetTotalNodeCount(); | 123 count += children_[i]->GetTotalNodeCount(); |
121 return count; | 124 return count; |
122 } | 125 } |
123 | 126 |
124 // Returns the node at |index|. | 127 // Returns the node at |index|. |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 | 289 |
287 // The root. | 290 // The root. |
288 scoped_ptr<NodeType> root_; | 291 scoped_ptr<NodeType> root_; |
289 | 292 |
290 DISALLOW_COPY_AND_ASSIGN(TreeNodeModel); | 293 DISALLOW_COPY_AND_ASSIGN(TreeNodeModel); |
291 }; | 294 }; |
292 | 295 |
293 } // namespace ui | 296 } // namespace ui |
294 | 297 |
295 #endif // UI_BASE_MODELS_TREE_NODE_MODEL_H_ | 298 #endif // UI_BASE_MODELS_TREE_NODE_MODEL_H_ |
OLD | NEW |