[go: nahoru, domu]

blob: f0cb75d7af4846d38670d9db49f2e77f7f66c11a [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2012 The Chromium Authors
erikkay@google.com19b8d82f2009-01-29 19:18:572// 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
wfhbf68f4d52015-03-10 01:32:598#include <stdint.h>
robpercivaldcd8b102016-01-25 19:39:009
10#include <iosfwd>
erikkay@google.com19b8d82f2009-01-29 19:18:5711#include <string>
12#include <vector>
13
darin@chromium.org0bea7252011-08-05 15:34:0014#include "base/base_export.h"
Greg Thompson15a9d172019-08-06 21:13:5515#include "base/strings/string_piece.h"
erikkay@google.com19b8d82f2009-01-29 19:18:5716
xhwang@chromium.org1f04ef42013-04-22 07:35:5017namespace base {
18
evan@chromium.org36ee0322010-12-23 21:27:1219// Version represents a dotted version number, like "1.2.3.4", supporting
20// parsing and comparison.
darin@chromium.org0bea7252011-08-05 15:34:0021class BASE_EXPORT Version {
erg@google.com2fdc86a2010-01-26 23:08:0222 public:
cpu@chromium.org760024782011-06-07 17:21:3023 // The only thing you can legally do to a default constructed
24 // Version object is assign to it.
akalin@chromium.org26931bc2010-03-25 22:19:0425 Version();
26
vmpstre65942b2016-02-25 00:50:3127 Version(const Version& other);
28
cpu@chromium.org760024782011-06-07 17:21:3029 // Initializes from a decimal dotted version number, like "0.1.1".
Christian Flachbf5fdc42023-10-24 02:30:1830 // Each component is limited to a uint32_t. Call IsValid() to learn
cpu@chromium.org760024782011-06-07 17:21:3031 // the outcome.
Greg Thompson15a9d172019-08-06 21:13:5532 explicit Version(StringPiece version_str);
erikkay@google.com19b8d82f2009-01-29 19:18:5733
staraz8fb38082016-07-25 18:48:2134 // Initializes from a vector of components, like {1, 2, 3, 4}. Call IsValid()
35 // to learn the outcome.
36 explicit Version(std::vector<uint32_t> components);
37
38 ~Version();
39
cpu@chromium.org760024782011-06-07 17:21:3040 // Returns true if the object contains a valid version number.
41 bool IsValid() const;
42
mathp@google.com810b2502012-07-04 16:22:4843 // Returns true if the version wildcard string is valid. The version wildcard
44 // string may end with ".*" (e.g. 1.2.*, 1.*). Any other arrangement with "*"
45 // is invalid (e.g. 1.*.3 or 1.2.3*). This functions defaults to standard
46 // Version behavior (IsValid) if no wildcard is present.
Greg Thompson15a9d172019-08-06 21:13:5547 static bool IsValidWildcardString(StringPiece wildcard_string);
mathp@google.com810b2502012-07-04 16:22:4848
Chris Fredrickson075b4952022-11-21 15:57:3049 // Returns -1, 0, 1 for <, ==, >. `this` and `other` must both be valid.
erikkay@google.com19b8d82f2009-01-29 19:18:5750 int CompareTo(const Version& other) const;
51
mathp@google.com810b2502012-07-04 16:22:4852 // 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.
Greg Thompson15a9d172019-08-06 21:13:5556 int CompareToWildcardString(StringPiece wildcard_string) const;
mathp@google.com810b2502012-07-04 16:22:4857
erikkay@google.com19b8d82f2009-01-29 19:18:5758 // Return the string representation of this version.
Devlin Croninfde745d2019-09-25 22:21:5759 std::string GetString() const;
erikkay@google.com19b8d82f2009-01-29 19:18:5760
wfhbf68f4d52015-03-10 01:32:5961 const std::vector<uint32_t>& components() const { return components_; }
erikkay@google.com19b8d82f2009-01-29 19:18:5762
erg@google.com2fdc86a2010-01-26 23:08:0263 private:
wfhbf68f4d52015-03-10 01:32:5964 std::vector<uint32_t> components_;
erikkay@google.com19b8d82f2009-01-29 19:18:5765};
66
robpercivaldcd8b102016-01-25 19:39:0067BASE_EXPORT bool operator==(const Version& v1, const Version& v2);
68BASE_EXPORT bool operator!=(const Version& v1, const Version& v2);
69BASE_EXPORT bool operator<(const Version& v1, const Version& v2);
70BASE_EXPORT bool operator<=(const Version& v1, const Version& v2);
71BASE_EXPORT bool operator>(const Version& v1, const Version& v2);
72BASE_EXPORT bool operator>=(const Version& v1, const Version& v2);
73BASE_EXPORT std::ostream& operator<<(std::ostream& stream, const Version& v);
74
xhwang@chromium.org1f04ef42013-04-22 07:35:5075} // namespace base
76
erikkay@google.com19b8d82f2009-01-29 19:18:5777#endif // BASE_VERSION_H_