| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // TreeNode ------------------------------------------------------------------- | 62 // TreeNode ------------------------------------------------------------------- |
| 63 | 63 |
| 64 template <class NodeType> | 64 template <class NodeType> |
| 65 class TreeNode : public TreeModelNode { | 65 class TreeNode : public TreeModelNode { |
| 66 public: | 66 public: |
| 67 TreeNode() : parent_(NULL) {} | 67 TreeNode() : parent_(NULL) {} |
| 68 | 68 |
| 69 explicit TreeNode(const base::string16& title) | 69 explicit TreeNode(const base::string16& title) |
| 70 : title_(title), parent_(NULL) {} | 70 : title_(title), parent_(NULL) {} |
| 71 | 71 |
| 72 ~TreeNode() override { | 72 ~TreeNode() override { base::STLDeleteElements(&children_); } |
| 73 STLDeleteElements(&children_); | |
| 74 } | |
| 75 | 73 |
| 76 // Adds |node| as a child of this node, at |index|. | 74 // Adds |node| as a child of this node, at |index|. |
| 77 virtual void Add(NodeType* node, int index) { | 75 virtual void Add(NodeType* node, int index) { |
| 78 DCHECK(node); | 76 DCHECK(node); |
| 79 DCHECK_GE(index, 0); | 77 DCHECK_GE(index, 0); |
| 80 DCHECK_LE(index, child_count()); | 78 DCHECK_LE(index, child_count()); |
| 81 // If |node| has a parent, remove it from its parent. | 79 // If |node| has a parent, remove it from its parent. |
| 82 NodeType* parent = node->parent_; | 80 NodeType* parent = node->parent_; |
| 83 if (parent) | 81 if (parent) |
| 84 parent->Remove(node); | 82 parent->Remove(node); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 | 297 |
| 300 // The root. | 298 // The root. |
| 301 std::unique_ptr<NodeType> root_; | 299 std::unique_ptr<NodeType> root_; |
| 302 | 300 |
| 303 DISALLOW_COPY_AND_ASSIGN(TreeNodeModel); | 301 DISALLOW_COPY_AND_ASSIGN(TreeNodeModel); |
| 304 }; | 302 }; |
| 305 | 303 |
| 306 } // namespace ui | 304 } // namespace ui |
| 307 | 305 |
| 308 #endif // UI_BASE_MODELS_TREE_NODE_MODEL_H_ | 306 #endif // UI_BASE_MODELS_TREE_NODE_MODEL_H_ |
| OLD | NEW |