mathp@google.com | 810b250 | 2012-07-04 16:22:48 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
erikkay@google.com | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BASE_VERSION_H_ |
| 6 | #define BASE_VERSION_H_ |
| 7 | |
wfh | bf68f4d5 | 2015-03-10 01:32:59 | [diff] [blame^] | 8 | #include <stdint.h> |
erikkay@google.com | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
darin@chromium.org | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 12 | #include "base/base_export.h" |
erikkay@google.com | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 13 | #include "base/basictypes.h" |
| 14 | |
xhwang@chromium.org | 1f04ef4 | 2013-04-22 07:35:50 | [diff] [blame] | 15 | namespace base { |
| 16 | |
evan@chromium.org | 36ee032 | 2010-12-23 21:27:12 | [diff] [blame] | 17 | // Version represents a dotted version number, like "1.2.3.4", supporting |
| 18 | // parsing and comparison. |
darin@chromium.org | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 19 | class BASE_EXPORT Version { |
erg@google.com | 2fdc86a | 2010-01-26 23:08:02 | [diff] [blame] | 20 | public: |
cpu@chromium.org | 76002478 | 2011-06-07 17:21:30 | [diff] [blame] | 21 | // The only thing you can legally do to a default constructed |
| 22 | // Version object is assign to it. |
akalin@chromium.org | 26931bc | 2010-03-25 22:19:04 | [diff] [blame] | 23 | Version(); |
erikkay@google.com | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 24 | |
cpu@chromium.org | 1513bf8 | 2011-06-07 17:43:20 | [diff] [blame] | 25 | ~Version(); |
| 26 | |
cpu@chromium.org | 76002478 | 2011-06-07 17:21:30 | [diff] [blame] | 27 | // Initializes from a decimal dotted version number, like "0.1.1". |
| 28 | // Each component is limited to a uint16. Call IsValid() to learn |
| 29 | // the outcome. |
| 30 | explicit Version(const std::string& version_str); |
erikkay@google.com | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 31 | |
cpu@chromium.org | 76002478 | 2011-06-07 17:21:30 | [diff] [blame] | 32 | // Returns true if the object contains a valid version number. |
| 33 | bool IsValid() const; |
| 34 | |
mathp@google.com | 810b250 | 2012-07-04 16:22:48 | [diff] [blame] | 35 | // Returns true if the version wildcard string is valid. The version wildcard |
| 36 | // string may end with ".*" (e.g. 1.2.*, 1.*). Any other arrangement with "*" |
| 37 | // is invalid (e.g. 1.*.3 or 1.2.3*). This functions defaults to standard |
| 38 | // Version behavior (IsValid) if no wildcard is present. |
| 39 | static bool IsValidWildcardString(const std::string& wildcard_string); |
| 40 | |
cpu@chromium.org | 30c157c | 2011-08-01 17:45:08 | [diff] [blame] | 41 | // Commonly used pattern. Given a valid version object, compare if a |
| 42 | // |version_str| results in a newer version. Returns true if the |
| 43 | // string represents valid version and if the version is greater than |
| 44 | // than the version of this object. |
| 45 | bool IsOlderThan(const std::string& version_str) const; |
| 46 | |
erikkay@google.com | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 47 | bool Equals(const Version& other) const; |
| 48 | |
| 49 | // Returns -1, 0, 1 for <, ==, >. |
| 50 | int CompareTo(const Version& other) const; |
| 51 | |
mathp@google.com | 810b250 | 2012-07-04 16:22:48 | [diff] [blame] | 52 | // Given a valid version object, compare if a |wildcard_string| results in a |
| 53 | // newer version. This function will default to CompareTo if the string does |
| 54 | // not end in wildcard sequence ".*". IsValidWildcard(wildcard_string) must be |
| 55 | // true before using this function. |
| 56 | int CompareToWildcardString(const std::string& wildcard_string) const; |
| 57 | |
erikkay@google.com | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 58 | // Return the string representation of this version. |
| 59 | const std::string GetString() const; |
| 60 | |
wfh | bf68f4d5 | 2015-03-10 01:32:59 | [diff] [blame^] | 61 | const std::vector<uint32_t>& components() const { return components_; } |
erikkay@google.com | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 62 | |
erg@google.com | 2fdc86a | 2010-01-26 23:08:02 | [diff] [blame] | 63 | private: |
wfh | bf68f4d5 | 2015-03-10 01:32:59 | [diff] [blame^] | 64 | std::vector<uint32_t> components_; |
erikkay@google.com | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 65 | }; |
| 66 | |
xhwang@chromium.org | 1f04ef4 | 2013-04-22 07:35:50 | [diff] [blame] | 67 | } // namespace base |
| 68 | |
avi@chromium.org | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 69 | // TODO(xhwang) remove this when all users are updated to explicitly use the |
| 70 | // namespace |
| 71 | using base::Version; |
| 72 | |
erikkay@google.com | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 73 | #endif // BASE_VERSION_H_ |