OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 APP_TREE_NODE_MODEL_H_ | 5 #ifndef APP_TREE_NODE_MODEL_H_ |
6 #define APP_TREE_NODE_MODEL_H_ | 6 #define APP_TREE_NODE_MODEL_H_ |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 for (size_t i = 0; i < children_->size(); ++i) | 97 for (size_t i = 0; i < children_->size(); ++i) |
98 children_[i]->parent_ = NULL; | 98 children_[i]->parent_ = NULL; |
99 children_->clear(); | 99 children_->clear(); |
100 } | 100 } |
101 | 101 |
102 // Returns the number of children. | 102 // Returns the number of children. |
103 int GetChildCount() const { | 103 int GetChildCount() const { |
104 return static_cast<int>(children_->size()); | 104 return static_cast<int>(children_->size()); |
105 } | 105 } |
106 | 106 |
107 // Returns the number of all nodes in teh subtree rooted at this node, | |
108 // including this node. | |
109 int GetTotalNodeCount() const { | |
110 int count = 1; // Start with one to include the node itself. | |
111 for (size_t i = 0; i < children_->size()(); ++i) { | |
sky
2009/10/23 21:50:21
()()->()
| |
112 TreeNode<NodeType> *child = children_[i]; | |
113 count += child->GetTotalNodeCount(); | |
114 } | |
115 return count; | |
116 } | |
117 | |
107 // Returns a child by index. | 118 // Returns a child by index. |
108 NodeType* GetChild(int index) { | 119 NodeType* GetChild(int index) { |
109 DCHECK(index >= 0 && index < GetChildCount()); | 120 DCHECK(index >= 0 && index < GetChildCount()); |
110 return children_[index]; | 121 return children_[index]; |
111 } | 122 } |
112 const NodeType* GetChild(int index) const { | 123 const NodeType* GetChild(int index) const { |
113 DCHECK(index >= 0 && index < GetChildCount()); | 124 DCHECK(index >= 0 && index < GetChildCount()); |
114 return children_[index]; | 125 return children_[index]; |
115 } | 126 } |
116 | 127 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 // The root. | 288 // The root. |
278 scoped_ptr<NodeType> root_; | 289 scoped_ptr<NodeType> root_; |
279 | 290 |
280 // The observer. | 291 // The observer. |
281 TreeModelObserver* observer_; | 292 TreeModelObserver* observer_; |
282 | 293 |
283 DISALLOW_COPY_AND_ASSIGN(TreeNodeModel); | 294 DISALLOW_COPY_AND_ASSIGN(TreeNodeModel); |
284 }; | 295 }; |
285 | 296 |
286 #endif // APP_TREE_NODE_MODEL_H_ | 297 #endif // APP_TREE_NODE_MODEL_H_ |
OLD | NEW |