Roll src/third_party/WebKit 6d85854:7e30d51 (svn 202247:202248)
[chromium-blink-merge.git] / base / version.h
blob814acaa2b4ed83f29b5aafe47b6c48b649ec7ed0
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.
5 #ifndef BASE_VERSION_H_
6 #define BASE_VERSION_H_
8 #include <stdint.h>
9 #include <string>
10 #include <vector>
12 #include "base/base_export.h"
13 #include "base/basictypes.h"
15 namespace base {
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();
25 ~Version();
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);
32 // Returns true if the object contains a valid version number.
33 bool IsValid() const;
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);
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;
47 bool Equals(const Version& other) const;
49 // Returns -1, 0, 1 for <, ==, >.
50 int CompareTo(const Version& other) const;
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;
58 // Return the string representation of this version.
59 const std::string GetString() const;
61 const std::vector<uint32_t>& components() const { return components_; }
63 private:
64 std::vector<uint32_t> components_;
67 } // namespace base
69 // TODO(xhwang) remove this when all users are updated to explicitly use the
70 // namespace
71 using base::Version;
73 #endif // BASE_VERSION_H_