| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BASE_VERSION_H_ | |
| 6 #define BASE_VERSION_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/base_export.h" | |
| 13 #include "base/basictypes.h" | |
| 14 | |
| 15 namespace base { | |
| 16 | |
| 17 // Version represents a dotted version number, like "1.2.3.4", supporting | |
| 18 // parsing and comparison. | |
| 19 class BASE_EXPORT Version { | |
| 20 public: | |
| 21 // The only thing you can legally do to a default constructed | |
| 22 // Version object is assign to it. | |
| 23 Version(); | |
| 24 | |
| 25 ~Version(); | |
| 26 | |
| 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); | |
| 31 | |
| 32 // Returns true if the object contains a valid version number. | |
| 33 bool IsValid() const; | |
| 34 | |
| 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 | |
| 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 | |
| 47 bool Equals(const Version& other) const; | |
| 48 | |
| 49 // Returns -1, 0, 1 for <, ==, >. | |
| 50 int CompareTo(const Version& other) const; | |
| 51 | |
| 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 | |
| 58 // Return the string representation of this version. | |
| 59 const std::string GetString() const; | |
| 60 | |
| 61 const std::vector<uint32_t>& components() const { return components_; } | |
| 62 | |
| 63 private: | |
| 64 std::vector<uint32_t> components_; | |
| 65 }; | |
| 66 | |
| 67 } // namespace base | |
| 68 | |
| 69 // TODO(xhwang) remove this when all users are updated to explicitly use the | |
| 70 // namespace | |
| 71 using base::Version; | |
| 72 | |
| 73 #endif // BASE_VERSION_H_ | |
| OLD | NEW |