summaryrefslogtreecommitdiffstats
path: root/base/version.h
diff options
context:
space:
mode:
authorcpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-07 17:21:30 +0000
committercpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-07 17:21:30 +0000
commit76002478cf1d6ddf9677401f73198fb7a564fdf7 (patch)
tree7782f6b6b2e7b06bb7f66da7081790b3fc019675 /base/version.h
parent0985614e49db6b4a94c551fda1107462b53a9aac (diff)
downloadchromium_src-76002478cf1d6ddf9677401f73198fb7a564fdf7.zip
chromium_src-76002478cf1d6ddf9677401f73198fb7a564fdf7.tar.gz
chromium_src-76002478cf1d6ddf9677401f73198fb7a564fdf7.tar.bz2
Clean up base/Version
It turns out base/Version is really a value object but probably because of some serious accident or by the machinations of a super villain, forgot his identity and now it thinks is a reference object, only creatable in the heap and that could only spawn offsprings via cloning. But fear not 'cause I've seen Version true nature; At its core is just a good 'ol vector<uint16>, which has very respectable value semantics. Also I have removed the is_valid_ parasite as much as I could. The old interface (GetVersionFromString and Clone) is kept so existing callers would not need to be modified. BUG=none TEST=included Review URL: http://codereview.chromium.org/7105008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88143 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/version.h')
-rw-r--r--base/version.h28
1 files changed, 13 insertions, 15 deletions
diff --git a/base/version.h b/base/version.h
index d256d06..7dcefb3 100644
--- a/base/version.h
+++ b/base/version.h
@@ -15,22 +15,27 @@
// Version represents a dotted version number, like "1.2.3.4", supporting
// parsing and comparison.
-// Each component is limited to a uint16.
class BASE_API Version {
public:
- // Exposed only so that a Version can be stored in STL containers;
- // any call to the methods below on a default-constructed Version
- // will DCHECK.
+ // The only thing you can legally do to a default constructed
+ // Version object is assign to it.
Version();
- ~Version();
+ // Initializes from a decimal dotted version number, like "0.1.1".
+ // Each component is limited to a uint16. Call IsValid() to learn
+ // the outcome.
+ explicit Version(const std::string& version_str);
- // The version string must be made up of 1 or more uint16's separated
- // by '.'. Returns NULL if string is not in this format.
+ // Returns true if the object contains a valid version number.
+ bool IsValid() const;
+
+ // Returns NULL if the string is not in the proper format.
// Caller is responsible for freeing the Version object once done.
+ // DO NOT USE FOR NEWER CODE.
static Version* GetVersionFromString(const std::string& version_str);
- // Creates a copy of this version. Caller takes ownership.
+ // Creates a copy of this version object. Caller takes ownership.
+ // DO NOT USE FOR NEWER CODE.
Version* Clone() const;
bool Equals(const Version& other) const;
@@ -44,14 +49,7 @@ class BASE_API Version {
const std::vector<uint16>& components() const { return components_; }
private:
- bool InitFromString(const std::string& version_str);
-
- bool is_valid_;
std::vector<uint16> components_;
-
- FRIEND_TEST_ALL_PREFIXES(VersionTest, DefaultConstructor);
- FRIEND_TEST_ALL_PREFIXES(VersionTest, GetVersionFromString);
- FRIEND_TEST_ALL_PREFIXES(VersionTest, Compare);
};
#endif // BASE_VERSION_H_