| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 BASE_VERSION_H_ | 5 #ifndef BASE_VERSION_H_ |
| 6 #define BASE_VERSION_H_ | 6 #define BASE_VERSION_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 |
| 10 #include <iosfwd> |
| 9 #include <string> | 11 #include <string> |
| 10 #include <vector> | 12 #include <vector> |
| 11 | 13 |
| 12 #include "base/base_export.h" | 14 #include "base/base_export.h" |
| 13 | 15 |
| 14 namespace base { | 16 namespace base { |
| 15 | 17 |
| 16 // Version represents a dotted version number, like "1.2.3.4", supporting | 18 // Version represents a dotted version number, like "1.2.3.4", supporting |
| 17 // parsing and comparison. | 19 // parsing and comparison. |
| 18 class BASE_EXPORT Version { | 20 class BASE_EXPORT Version { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 30 | 32 |
| 31 // Returns true if the object contains a valid version number. | 33 // Returns true if the object contains a valid version number. |
| 32 bool IsValid() const; | 34 bool IsValid() const; |
| 33 | 35 |
| 34 // Returns true if the version wildcard string is valid. The version wildcard | 36 // Returns true if the version wildcard string is valid. The version wildcard |
| 35 // string may end with ".*" (e.g. 1.2.*, 1.*). Any other arrangement with "*" | 37 // string may end with ".*" (e.g. 1.2.*, 1.*). Any other arrangement with "*" |
| 36 // is invalid (e.g. 1.*.3 or 1.2.3*). This functions defaults to standard | 38 // is invalid (e.g. 1.*.3 or 1.2.3*). This functions defaults to standard |
| 37 // Version behavior (IsValid) if no wildcard is present. | 39 // Version behavior (IsValid) if no wildcard is present. |
| 38 static bool IsValidWildcardString(const std::string& wildcard_string); | 40 static bool IsValidWildcardString(const std::string& wildcard_string); |
| 39 | 41 |
| 40 // Commonly used pattern. Given a valid version object, compare if a | |
| 41 // |version_str| results in a newer version. Returns true if the | |
| 42 // string represents valid version and if the version is greater than | |
| 43 // than the version of this object. | |
| 44 bool IsOlderThan(const std::string& version_str) const; | |
| 45 | |
| 46 bool Equals(const Version& other) const; | |
| 47 | |
| 48 // Returns -1, 0, 1 for <, ==, >. | 42 // Returns -1, 0, 1 for <, ==, >. |
| 49 int CompareTo(const Version& other) const; | 43 int CompareTo(const Version& other) const; |
| 50 | 44 |
| 51 // Given a valid version object, compare if a |wildcard_string| results in a | 45 // Given a valid version object, compare if a |wildcard_string| results in a |
| 52 // newer version. This function will default to CompareTo if the string does | 46 // newer version. This function will default to CompareTo if the string does |
| 53 // not end in wildcard sequence ".*". IsValidWildcard(wildcard_string) must be | 47 // not end in wildcard sequence ".*". IsValidWildcard(wildcard_string) must be |
| 54 // true before using this function. | 48 // true before using this function. |
| 55 int CompareToWildcardString(const std::string& wildcard_string) const; | 49 int CompareToWildcardString(const std::string& wildcard_string) const; |
| 56 | 50 |
| 57 // Return the string representation of this version. | 51 // Return the string representation of this version. |
| 58 const std::string GetString() const; | 52 const std::string GetString() const; |
| 59 | 53 |
| 60 const std::vector<uint32_t>& components() const { return components_; } | 54 const std::vector<uint32_t>& components() const { return components_; } |
| 61 | 55 |
| 62 private: | 56 private: |
| 63 std::vector<uint32_t> components_; | 57 std::vector<uint32_t> components_; |
| 64 }; | 58 }; |
| 65 | 59 |
| 60 BASE_EXPORT bool operator==(const Version& v1, const Version& v2); |
| 61 BASE_EXPORT bool operator!=(const Version& v1, const Version& v2); |
| 62 BASE_EXPORT bool operator<(const Version& v1, const Version& v2); |
| 63 BASE_EXPORT bool operator<=(const Version& v1, const Version& v2); |
| 64 BASE_EXPORT bool operator>(const Version& v1, const Version& v2); |
| 65 BASE_EXPORT bool operator>=(const Version& v1, const Version& v2); |
| 66 BASE_EXPORT std::ostream& operator<<(std::ostream& stream, const Version& v); |
| 67 |
| 66 } // namespace base | 68 } // namespace base |
| 67 | 69 |
| 68 // TODO(xhwang) remove this when all users are updated to explicitly use the | 70 // TODO(xhwang) remove this when all users are updated to explicitly use the |
| 69 // namespace | 71 // namespace |
| 70 using base::Version; | 72 using base::Version; |
| 71 | 73 |
| 72 #endif // BASE_VERSION_H_ | 74 #endif // BASE_VERSION_H_ |
| OLD | NEW |