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 wildcard string is valid. The version wildcard |
| 34 // string may end with ".*" (e.g. 1.2.*, 1.*). Any other arrangement with "*" |
| 35 // is invalid (e.g. 1.*.3 or 1.2.3*). This functions defaults to standard |
| 36 // Version behavior (IsValid) if no wildcard is present. |
| 37 static bool IsValidWildcardString(const std::string& wildcard_string); |
| 38 |
33 // Commonly used pattern. Given a valid version object, compare if a | 39 // Commonly used pattern. Given a valid version object, compare if a |
34 // |version_str| results in a newer version. Returns true if the | 40 // |version_str| results in a newer version. Returns true if the |
35 // string represents valid version and if the version is greater than | 41 // string represents valid version and if the version is greater than |
36 // than the version of this object. | 42 // than the version of this object. |
37 bool IsOlderThan(const std::string& version_str) const; | 43 bool IsOlderThan(const std::string& version_str) const; |
38 | 44 |
39 // Returns NULL if the string is not in the proper format. | 45 // Returns NULL if the string is not in the proper format. |
40 // Caller is responsible for freeing the Version object once done. | 46 // Caller is responsible for freeing the Version object once done. |
41 // DO NOT USE FOR NEWER CODE. | 47 // DO NOT USE FOR NEWER CODE. |
42 static Version* GetVersionFromString(const std::string& version_str); | 48 static Version* GetVersionFromString(const std::string& version_str); |
43 | 49 |
44 // Creates a copy of this version object. Caller takes ownership. | 50 // Creates a copy of this version object. Caller takes ownership. |
45 // DO NOT USE FOR NEWER CODE. | 51 // DO NOT USE FOR NEWER CODE. |
46 Version* Clone() const; | 52 Version* Clone() const; |
47 | 53 |
48 bool Equals(const Version& other) const; | 54 bool Equals(const Version& other) const; |
49 | 55 |
50 // Returns -1, 0, 1 for <, ==, >. | 56 // Returns -1, 0, 1 for <, ==, >. |
51 int CompareTo(const Version& other) const; | 57 int CompareTo(const Version& other) const; |
52 | 58 |
| 59 // Given a valid version object, compare if a |wildcard_string| results in a |
| 60 // newer version. This function will default to CompareTo if the string does |
| 61 // not end in wildcard sequence ".*". IsValidWildcard(wildcard_string) must be |
| 62 // true before using this function. |
| 63 int CompareToWildcardString(const std::string& wildcard_string) const; |
| 64 |
53 // Return the string representation of this version. | 65 // Return the string representation of this version. |
54 const std::string GetString() const; | 66 const std::string GetString() const; |
55 | 67 |
56 const std::vector<uint16>& components() const { return components_; } | 68 const std::vector<uint16>& components() const { return components_; } |
57 | 69 |
58 private: | 70 private: |
59 std::vector<uint16> components_; | 71 std::vector<uint16> components_; |
60 }; | 72 }; |
61 | 73 |
62 #endif // BASE_VERSION_H_ | 74 #endif // BASE_VERSION_H_ |
OLD | NEW |