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 <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 : title_(WideToUTF16(title)), parent_(NULL) {} | 75 : title_(WideToUTF16(title)), parent_(NULL) {} |
76 #endif | 76 #endif |
77 explicit TreeNode(const string16& title) | 77 explicit TreeNode(const string16& title) |
78 : title_(title), parent_(NULL) {} | 78 : title_(title), parent_(NULL) {} |
79 | 79 |
80 virtual ~TreeNode() { | 80 virtual ~TreeNode() { |
81 } | 81 } |
82 | 82 |
83 // Adds the specified child node. | 83 // Adds the specified child node. |
84 virtual void Add(int index, NodeType* child) { | 84 virtual void Add(int index, NodeType* child) { |
85 DCHECK(child && index >= 0 && index <= GetChildCount()); | 85 DCHECK(child); |
| 86 DCHECK_LE(0, index); |
| 87 DCHECK_GE(GetChildCount(), index); |
86 // If the node has a parent, remove it from its parent. | 88 // If the node has a parent, remove it from its parent. |
87 NodeType* node_parent = child->GetParent(); | 89 NodeType* node_parent = child->GetParent(); |
88 if (node_parent) | 90 if (node_parent) |
89 node_parent->Remove(node_parent->IndexOfChild(child)); | 91 node_parent->Remove(node_parent->IndexOfChild(child)); |
90 child->parent_ = static_cast<NodeType*>(this); | 92 child->parent_ = static_cast<NodeType*>(this); |
91 children_->insert(children_->begin() + index, child); | 93 children_->insert(children_->begin() + index, child); |
92 } | 94 } |
93 | 95 |
94 // Removes the node by index. This does NOT delete the specified node, it is | 96 // Removes the node by index. This does NOT delete the specified node, it is |
95 // up to the caller to delete it when done. | 97 // up to the caller to delete it when done. |
(...skipping 27 matching lines...) Expand all Loading... |
123 } | 125 } |
124 return count; | 126 return count; |
125 } | 127 } |
126 | 128 |
127 // Returns a child by index. | 129 // Returns a child by index. |
128 NodeType* GetChild(int index) { | 130 NodeType* GetChild(int index) { |
129 DCHECK(index >= 0 && index < GetChildCount()); | 131 DCHECK(index >= 0 && index < GetChildCount()); |
130 return children_[index]; | 132 return children_[index]; |
131 } | 133 } |
132 const NodeType* GetChild(int index) const { | 134 const NodeType* GetChild(int index) const { |
133 DCHECK(index >= 0 && index < GetChildCount()); | 135 DCHECK_LE(0, index); |
| 136 DCHECK_GT(GetChildCount(), index); |
134 return children_[index]; | 137 return children_[index]; |
135 } | 138 } |
136 | 139 |
137 // Returns the parent. | 140 // Returns the parent. |
138 NodeType* GetParent() { | 141 NodeType* GetParent() { |
139 return parent_; | 142 return parent_; |
140 } | 143 } |
141 const NodeType* GetParent() const { | 144 const NodeType* GetParent() const { |
142 return parent_; | 145 return parent_; |
143 } | 146 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 private: | 321 private: |
319 // The observers. | 322 // The observers. |
320 ObserverList<TreeModelObserver> observer_list_; | 323 ObserverList<TreeModelObserver> observer_list_; |
321 // The root. | 324 // The root. |
322 scoped_ptr<NodeType> root_; | 325 scoped_ptr<NodeType> root_; |
323 | 326 |
324 DISALLOW_COPY_AND_ASSIGN(TreeNodeModel); | 327 DISALLOW_COPY_AND_ASSIGN(TreeNodeModel); |
325 }; | 328 }; |
326 | 329 |
327 #endif // APP_TREE_NODE_MODEL_H_ | 330 #endif // APP_TREE_NODE_MODEL_H_ |
OLD | NEW |