OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 12 matching lines...) Expand all Loading... | |
23 ~Version(); | 23 ~Version(); |
24 | 24 |
25 // Initializes from a decimal dotted version number, like "0.1.1". | 25 // Initializes from a decimal dotted version number, like "0.1.1". |
26 // Each component is limited to a uint16. Call IsValid() to learn | 26 // Each component is limited to a uint16. Call IsValid() to learn |
27 // the outcome. | 27 // the outcome. |
28 explicit Version(const std::string& version_str); | 28 explicit Version(const std::string& version_str); |
29 | 29 |
30 // Returns true if the object contains a valid version number. | 30 // Returns true if the object contains a valid version number. |
31 bool IsValid() const; | 31 bool IsValid() const; |
32 | 32 |
33 // Returns true if the version string is valid. In this version, the string | |
Alexei Svitkine (slow)
2012/06/19 18:30:27
You still have the "In this version" wording which
Mathieu
2012/06/19 20:01:35
Done. Sorry the updated version did not make it he
| |
34 // can end with ".*". Any other arrangement with "*" will be invalid (e.g. | |
35 // 1.*.3 or 1.2.3*). | |
36 static bool IsValidWildcard(const std::string& version_str); | |
37 | |
33 // Commonly used pattern. Given a valid version object, compare if a | 38 // Commonly used pattern. Given a valid version object, compare if a |
34 // |version_str| results in a newer version. Returns true if the | 39 // |version_str| results in a newer version. Returns true if the |
35 // string represents valid version and if the version is greater than | 40 // string represents valid version and if the version is greater than |
36 // than the version of this object. | 41 // than the version of this object. |
37 bool IsOlderThan(const std::string& version_str) const; | 42 bool IsOlderThan(const std::string& version_str) const; |
38 | 43 |
39 // Returns NULL if the string is not in the proper format. | 44 // Returns NULL if the string is not in the proper format. |
40 // Caller is responsible for freeing the Version object once done. | 45 // Caller is responsible for freeing the Version object once done. |
41 // DO NOT USE FOR NEWER CODE. | 46 // DO NOT USE FOR NEWER CODE. |
42 static Version* GetVersionFromString(const std::string& version_str); | 47 static Version* GetVersionFromString(const std::string& version_str); |
43 | 48 |
44 // Creates a copy of this version object. Caller takes ownership. | 49 // Creates a copy of this version object. Caller takes ownership. |
45 // DO NOT USE FOR NEWER CODE. | 50 // DO NOT USE FOR NEWER CODE. |
46 Version* Clone() const; | 51 Version* Clone() const; |
47 | 52 |
48 bool Equals(const Version& other) const; | 53 bool Equals(const Version& other) const; |
49 | 54 |
50 // Returns -1, 0, 1 for <, ==, >. | 55 // Returns -1, 0, 1 for <, ==, >. |
51 int CompareTo(const Version& other) const; | 56 int CompareTo(const Version& other) const; |
52 | 57 |
58 // Given a valid version object, compare if a |version_str| results in a | |
59 // newer version. This function will default to CompareTo if the string does | |
60 // not end in wildcard sequence ".*". | |
61 int CompareToWildcard(const std::string& version_str) const; | |
62 | |
53 // Return the string representation of this version. | 63 // Return the string representation of this version. |
54 const std::string GetString() const; | 64 const std::string GetString() const; |
55 | 65 |
56 const std::vector<uint16>& components() const { return components_; } | 66 const std::vector<uint16>& components() const { return components_; } |
57 | 67 |
58 private: | 68 private: |
59 std::vector<uint16> components_; | 69 std::vector<uint16> components_; |
60 }; | 70 }; |
61 | 71 |
62 #endif // BASE_VERSION_H_ | 72 #endif // BASE_VERSION_H_ |
OLD | NEW |