michael@0: // Copyright (c) 2012 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef BASE_VERSION_H_ michael@0: #define BASE_VERSION_H_ michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "base/base_export.h" michael@0: #include "base/basictypes.h" michael@0: michael@0: namespace base { michael@0: michael@0: // Version represents a dotted version number, like "1.2.3.4", supporting michael@0: // parsing and comparison. michael@0: class BASE_EXPORT Version { michael@0: public: michael@0: // The only thing you can legally do to a default constructed michael@0: // Version object is assign to it. michael@0: Version(); michael@0: michael@0: ~Version(); michael@0: michael@0: // Initializes from a decimal dotted version number, like "0.1.1". michael@0: // Each component is limited to a uint16. Call IsValid() to learn michael@0: // the outcome. michael@0: explicit Version(const std::string& version_str); michael@0: michael@0: // Returns true if the object contains a valid version number. michael@0: bool IsValid() const; michael@0: michael@0: // Returns true if the version wildcard string is valid. The version wildcard michael@0: // string may end with ".*" (e.g. 1.2.*, 1.*). Any other arrangement with "*" michael@0: // is invalid (e.g. 1.*.3 or 1.2.3*). This functions defaults to standard michael@0: // Version behavior (IsValid) if no wildcard is present. michael@0: static bool IsValidWildcardString(const std::string& wildcard_string); michael@0: michael@0: // Commonly used pattern. Given a valid version object, compare if a michael@0: // |version_str| results in a newer version. Returns true if the michael@0: // string represents valid version and if the version is greater than michael@0: // than the version of this object. michael@0: bool IsOlderThan(const std::string& version_str) const; michael@0: michael@0: bool Equals(const Version& other) const; michael@0: michael@0: // Returns -1, 0, 1 for <, ==, >. michael@0: int CompareTo(const Version& other) const; michael@0: michael@0: // Given a valid version object, compare if a |wildcard_string| results in a michael@0: // newer version. This function will default to CompareTo if the string does michael@0: // not end in wildcard sequence ".*". IsValidWildcard(wildcard_string) must be michael@0: // true before using this function. michael@0: int CompareToWildcardString(const std::string& wildcard_string) const; michael@0: michael@0: // Return the string representation of this version. michael@0: const std::string GetString() const; michael@0: michael@0: const std::vector& components() const { return components_; } michael@0: michael@0: private: michael@0: std::vector components_; michael@0: }; michael@0: michael@0: } // namespace base michael@0: michael@0: // TODO(xhwang) remove this when all users are updated to explicitly use the michael@0: // namespace michael@0: using base::Version; michael@0: michael@0: #endif // BASE_VERSION_H_