summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-29 00:29:51 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-29 00:29:51 +0000
commitd1e335bfa8581678b24de3737ce59da98f915a7c (patch)
tree153480f573cef78ec71057893760eef5bcac6e29
parent367f8ea350e8aac8368002b78456e3c61f6a2cd1 (diff)
downloadchromium_src-d1e335bfa8581678b24de3737ce59da98f915a7c.zip
chromium_src-d1e335bfa8581678b24de3737ce59da98f915a7c.tar.gz
chromium_src-d1e335bfa8581678b24de3737ce59da98f915a7c.tar.bz2
history: Make QueryNodeList more readable.
- Group all the overridden methods. - Add OVERRIDE to them. - Move the implementation out of the class declaration. - Fix the order to match with our style. - Use STLDeleteElements. - Add DISALLOW_COPY_AND_ASSIGN. BUG=68682 TEST=None R=sky@chromium.org Review URL: http://codereview.chromium.org/6904087 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83453 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/history/query_parser.cc70
1 files changed, 46 insertions, 24 deletions
diff --git a/chrome/browser/history/query_parser.cc b/chrome/browser/history/query_parser.cc
index cd2a695..b7c2599 100644
--- a/chrome/browser/history/query_parser.cc
+++ b/chrome/browser/history/query_parser.cc
@@ -6,9 +6,12 @@
#include <algorithm>
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
#include "base/i18n/break_iterator.h"
#include "base/logging.h"
#include "base/memory/scoped_vector.h"
+#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "ui/base/l10n/l10n_util.h"
@@ -121,47 +124,47 @@ int QueryNodeWord::AppendToSQLiteQuery(string16* query) const {
return 1;
}
-// A QueryNodeList has a collection of child QueryNodes
-// which it cleans up after.
+// A QueryNodeList has a collection of QueryNodes which are deleted in the end.
class QueryNodeList : public QueryNode {
public:
- virtual ~QueryNodeList();
-
- virtual int AppendToSQLiteQuery(string16* query) const {
- return AppendChildrenToString(query);
- }
- virtual bool IsWord() const { return false; }
+ typedef std::vector<QueryNode*> QueryNodeVector;
- void AddChild(QueryNode* node) { children_.push_back(node); }
+ QueryNodeList();
+ virtual ~QueryNodeList();
- typedef std::vector<QueryNode*> QueryNodeVector;
QueryNodeVector* children() { return &children_; }
+ void AddChild(QueryNode* node);
+
// Remove empty subnodes left over from other parsing.
void RemoveEmptySubnodes();
- // QueryNodeList is never used with Matches or HasMatchIn.
- virtual bool Matches(const string16& word, bool exact) const {
- NOTREACHED();
- return false;
- }
- virtual bool HasMatchIn(const std::vector<QueryWord>& words,
- Snippet::MatchPositions* match_positions) const {
- NOTREACHED();
- return false;
- }
- virtual void AppendWords(std::vector<string16>* words) const;
+ // QueryNode:
+ virtual int AppendToSQLiteQuery(string16* query) const OVERRIDE;
+ virtual bool IsWord() const OVERRIDE;
+ virtual bool Matches(const string16& word, bool exact) const OVERRIDE;
+ virtual bool HasMatchIn(
+ const std::vector<QueryWord>& words,
+ Snippet::MatchPositions* match_positions) const OVERRIDE;
+ virtual void AppendWords(std::vector<string16>* words) const OVERRIDE;
protected:
int AppendChildrenToString(string16* query) const;
QueryNodeVector children_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(QueryNodeList);
};
+QueryNodeList::QueryNodeList() {}
+
QueryNodeList::~QueryNodeList() {
- for (QueryNodeVector::iterator node = children_.begin();
- node != children_.end(); ++node)
- delete *node;
+ STLDeleteElements(&children_);
+}
+
+void QueryNodeList::AddChild(QueryNode* node) {
+ children_.push_back(node);
}
void QueryNodeList::RemoveEmptySubnodes() {
@@ -179,6 +182,25 @@ void QueryNodeList::RemoveEmptySubnodes() {
}
}
+int QueryNodeList::AppendToSQLiteQuery(string16* query) const {
+ return AppendChildrenToString(query);
+}
+
+bool QueryNodeList::IsWord() const {
+ return false;
+}
+
+bool QueryNodeList::Matches(const string16& word, bool exact) const {
+ NOTREACHED();
+ return false;
+}
+
+bool QueryNodeList::HasMatchIn(const std::vector<QueryWord>& words,
+ Snippet::MatchPositions* match_positions) const {
+ NOTREACHED();
+ return false;
+}
+
void QueryNodeList::AppendWords(std::vector<string16>* words) const {
for (size_t i = 0; i < children_.size(); ++i)
children_[i]->AppendWords(words);