Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: ui/base/models/tree_node_model.h

Issue 7058030: ui/base/models: Reverse the DCHECKs of index. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 TreeNode() : parent_(NULL) {} 67 TreeNode() : parent_(NULL) {}
68 68
69 explicit TreeNode(const string16& title) 69 explicit TreeNode(const string16& title)
70 : title_(title), parent_(NULL) {} 70 : title_(title), parent_(NULL) {}
71 71
72 virtual ~TreeNode() {} 72 virtual ~TreeNode() {}
73 73
74 // Adds |node| as a child of this one, at |index|. 74 // Adds |node| as a child of this one, at |index|.
75 virtual void Add(NodeType* node, int index) { 75 virtual void Add(NodeType* node, int index) {
76 DCHECK(node); 76 DCHECK(node);
77 DCHECK_LE(0, index); 77 DCHECK_GE(index, 0);
78 DCHECK_GE(child_count(), index); 78 DCHECK_LE(index, child_count());
79 // If the node has a parent, remove it from its parent. 79 // If the node has a parent, remove it from its parent.
80 NodeType* parent = node->parent_; 80 NodeType* parent = node->parent_;
81 if (parent) 81 if (parent)
82 parent->Remove(node); 82 parent->Remove(node);
83 node->parent_ = static_cast<NodeType*>(this); 83 node->parent_ = static_cast<NodeType*>(this);
84 children_->insert(children_->begin() + index, node); 84 children_->insert(children_->begin() + index, node);
85 } 85 }
86 86
87 // Removes |node| from this node and returns it. It's up to the caller to 87 // Removes |node| from this node and returns it. It's up to the caller to
88 // delete it. 88 // delete it.
(...skipping 20 matching lines...) Expand all
109 // including this node. 109 // including this node.
110 int GetTotalNodeCount() const { 110 int GetTotalNodeCount() const {
111 int count = 1; // Start with one to include the node itself. 111 int count = 1; // Start with one to include the node itself.
112 for (size_t i = 0; i < children_->size(); ++i) 112 for (size_t i = 0; i < children_->size(); ++i)
113 count += children_[i]->GetTotalNodeCount(); 113 count += children_[i]->GetTotalNodeCount();
114 return count; 114 return count;
115 } 115 }
116 116
117 // Returns the node at |index|. 117 // Returns the node at |index|.
118 const NodeType* GetChild(int index) const { 118 const NodeType* GetChild(int index) const {
119 DCHECK_LE(0, index); 119 DCHECK_GE(index, 0);
120 DCHECK_GT(child_count(), index); 120 DCHECK_LT(index, child_count());
121 return children_[index]; 121 return children_[index];
122 } 122 }
123 NodeType* GetChild(int index) { 123 NodeType* GetChild(int index) {
124 return const_cast<NodeType*>( 124 return const_cast<NodeType*>(
125 static_cast<const NodeType&>(*this).GetChild(index)); 125 static_cast<const NodeType&>(*this).GetChild(index));
126 } 126 }
127 127
128 // Returns the parent node, or NULL if this is the root node. 128 // Returns the parent node, or NULL if this is the root node.
129 const NodeType* parent() const { return parent_; } 129 const NodeType* parent() const { return parent_; }
130 NodeType* parent() { return parent_; } 130 NodeType* parent() { return parent_; }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 287
288 // The root. 288 // The root.
289 scoped_ptr<NodeType> root_; 289 scoped_ptr<NodeType> root_;
290 290
291 DISALLOW_COPY_AND_ASSIGN(TreeNodeModel); 291 DISALLOW_COPY_AND_ASSIGN(TreeNodeModel);
292 }; 292 };
293 293
294 } // namespace ui 294 } // namespace ui
295 295
296 #endif // UI_BASE_MODELS_TREE_NODE_MODEL_H_ 296 #endif // UI_BASE_MODELS_TREE_NODE_MODEL_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698