Docserver: Skip to version 3-45-2. There was a test instance already uploaded
[chromium-blink-merge.git] / base / version.h
blobb3012eb921b1e62a803b681f03954fbb17d14cea
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 <string>
9 #include <vector>
11 #include "base/base_export.h"
12 #include "base/basictypes.h"
14 namespace base {
16 // Version represents a dotted version number, like "1.2.3.4", supporting
17 // parsing and comparison.
18 class BASE_EXPORT Version {
19 public:
20 // The only thing you can legally do to a default constructed
21 // Version object is assign to it.
22 Version();
24 ~Version();
26 // Initializes from a decimal dotted version number, like "0.1.1".
27 // Each component is limited to a uint16. Call IsValid() to learn
28 // the outcome.
29 explicit Version(const std::string& version_str);
31 // Returns true if the object contains a valid version number.
32 bool IsValid() const;
34 // Returns true if the version wildcard string is valid. The version wildcard
35 // string may end with ".*" (e.g. 1.2.*, 1.*). Any other arrangement with "*"
36 // is invalid (e.g. 1.*.3 or 1.2.3*). This functions defaults to standard
37 // Version behavior (IsValid) if no wildcard is present.
38 static bool IsValidWildcardString(const std::string& wildcard_string);
40 // Commonly used pattern. Given a valid version object, compare if a
41 // |version_str| results in a newer version. Returns true if the
42 // string represents valid version and if the version is greater than
43 // than the version of this object.
44 bool IsOlderThan(const std::string& version_str) const;
46 bool Equals(const Version& other) const;
48 // Returns -1, 0, 1 for <, ==, >.
49 int CompareTo(const Version& other) const;
51 // Given a valid version object, compare if a |wildcard_string| results in a
52 // newer version. This function will default to CompareTo if the string does
53 // not end in wildcard sequence ".*". IsValidWildcard(wildcard_string) must be
54 // true before using this function.
55 int CompareToWildcardString(const std::string& wildcard_string) const;
57 // Return the string representation of this version.
58 const std::string GetString() const;
60 const std::vector<uint16>& components() const { return components_; }
62 private:
63 std::vector<uint16> components_;
66 } // namespace base
68 // TODO(xhwang) remove this when all users are updated to explicitly use the
69 // namespace
70 using base::Version;
72 #endif // BASE_VERSION_H_