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

Unified Diff: base/version.cc

Issue 7105008: Clean up base/Version (Closed) Base URL: svn://chrome-svn/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 side-by-side diff with in-line comments
Download patch
Index: base/version.cc
===================================================================
--- base/version.cc (revision 86383)
+++ base/version.cc (working copy)
@@ -10,40 +10,44 @@
#include "base/string_number_conversions.h"
#include "base/string_split.h"
#include "base/string_util.h"
-#include "base/utf_string_conversions.h"
-Version::Version() : is_valid_(false) {}
+Version::Version() {
+}
-Version::~Version() {}
+Version::Version(const std::string& version_str) {
+ InitFromString(version_str);
+}
-// static
+// TODO: remove this method.
Evan Martin 2011/06/06 23:35:13 TODO(cpu) or file a bug :)
Version* Version::GetVersionFromString(const std::string& version_str) {
Version* vers = new Version();
if (vers->InitFromString(version_str)) {
- DCHECK(vers->is_valid_);
+ DCHECK(vers->IsValid());
return vers;
}
delete vers;
return NULL;
}
+// TODO: remove this method.
Version* Version::Clone() const {
- DCHECK(is_valid_);
- Version* copy = new Version();
- copy->components_ = components_;
- copy->is_valid_ = true;
- return copy;
+ DCHECK(IsValid());
+ return new Version(*this);
}
+bool Version::IsValid() const {
+ return (!components_.empty());
+}
+
bool Version::Equals(const Version& that) const {
- DCHECK(is_valid_);
- DCHECK(that.is_valid_);
- return CompareTo(that) == 0;
+ DCHECK(IsValid());
+ DCHECK(that.IsValid());
+ return (CompareTo(that) == 0);
}
int Version::CompareTo(const Version& other) const {
- DCHECK(is_valid_);
- DCHECK(other.is_valid_);
+ DCHECK(IsValid());
+ DCHECK(other.IsValid());
size_t count = std::min(components_.size(), other.components_.size());
for (size_t i = 0; i < count; ++i) {
if (components_[i] > other.components_[i])
@@ -64,7 +68,7 @@
}
const std::string Version::GetString() const {
- DCHECK(is_valid_);
+ DCHECK(IsValid());
std::string version_str;
size_t count = components_.size();
for (size_t i = 0; i < count - 1; ++i) {
@@ -76,7 +80,6 @@
}
bool Version::InitFromString(const std::string& version_str) {
- DCHECK(!is_valid_);
std::vector<std::string> numbers;
base::SplitString(version_str, '.', &numbers);
if (numbers.empty())
@@ -97,6 +100,5 @@
uint16 component = static_cast<uint16>(num);
components_.push_back(component);
}
- is_valid_ = true;
return true;
}
« base/version.h ('K') | « base/version.h ('k') | base/version_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698