| 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 CHROME_VIEWS_TREE_NODE_MODEL_H__ | 5 #ifndef CHROME_VIEWS_TREE_NODE_MODEL_H__ |
| 6 #define CHROME_VIEWS_TREE_NODE_MODEL_H__ | 6 #define CHROME_VIEWS_TREE_NODE_MODEL_H__ |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // Removes the node by index. This does NOT delete the specified node, it is | 85 // Removes the node by index. This does NOT delete the specified node, it is |
| 86 // up to the caller to delete it when done. | 86 // up to the caller to delete it when done. |
| 87 virtual NodeType* Remove(int index) { | 87 virtual NodeType* Remove(int index) { |
| 88 DCHECK(index >= 0 && index < GetChildCount()); | 88 DCHECK(index >= 0 && index < GetChildCount()); |
| 89 NodeType* node = GetChild(index); | 89 NodeType* node = GetChild(index); |
| 90 node->parent_ = NULL; | 90 node->parent_ = NULL; |
| 91 children_->erase(index + children_->begin()); | 91 children_->erase(index + children_->begin()); |
| 92 return node; | 92 return node; |
| 93 } | 93 } |
| 94 | 94 |
| 95 // Removes all the children from this node. This does NOT delete the nodes. |
| 96 void RemoveAll() { |
| 97 for (size_t i = 0; i < children_->size(); ++i) |
| 98 children_[i]->parent_ = NULL; |
| 99 children_->clear(); |
| 100 } |
| 101 |
| 95 // Returns the number of children. | 102 // Returns the number of children. |
| 96 int GetChildCount() { | 103 int GetChildCount() { |
| 97 return static_cast<int>(children_->size()); | 104 return static_cast<int>(children_->size()); |
| 98 } | 105 } |
| 99 | 106 |
| 100 // Returns a child by index. | 107 // Returns a child by index. |
| 101 NodeType* GetChild(int index) { | 108 NodeType* GetChild(int index) { |
| 102 DCHECK(index >= 0 && index < GetChildCount()); | 109 DCHECK(index >= 0 && index < GetChildCount()); |
| 103 return children_[index]; | 110 return children_[index]; |
| 104 } | 111 } |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 | 272 |
| 266 // The observer. | 273 // The observer. |
| 267 TreeModelObserver* observer_; | 274 TreeModelObserver* observer_; |
| 268 | 275 |
| 269 DISALLOW_COPY_AND_ASSIGN(TreeNodeModel); | 276 DISALLOW_COPY_AND_ASSIGN(TreeNodeModel); |
| 270 }; | 277 }; |
| 271 | 278 |
| 272 } // namespace views | 279 } // namespace views |
| 273 | 280 |
| 274 #endif // CHROME_VIEWS_TREE_NODE_MODEL_H__ | 281 #endif // CHROME_VIEWS_TREE_NODE_MODEL_H__ |
| OLD | NEW |