blob: b3a0956bbe32f9a382c2dbb25c4042d2ebac4a9f [file] [log] [blame]
[email protected]810b25082012-07-04 16:22:481// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]19b8d82f2009-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
wfhbf68f4d5b2015-03-10 01:32:598#include <stdint.h>
robpercivaldcd8b102016-01-25 19:39:009
10#include <iosfwd>
[email protected]19b8d82f2009-01-29 19:18:5711#include <string>
12#include <vector>
13
[email protected]0bea7252011-08-05 15:34:0014#include "base/base_export.h"
[email protected]19b8d82f2009-01-29 19:18:5715
[email protected]1f04ef42013-04-22 07:35:5016namespace base {
17
[email protected]36ee0322010-12-23 21:27:1218// Version represents a dotted version number, like "1.2.3.4", supporting
19// parsing and comparison.
[email protected]0bea7252011-08-05 15:34:0020class BASE_EXPORT Version {
[email protected]2fdc86a2010-01-26 23:08:0221 public:
[email protected]760024782011-06-07 17:21:3022 // The only thing you can legally do to a default constructed
23 // Version object is assign to it.
[email protected]26931bc2010-03-25 22:19:0424 Version();
25
vmpstre65942b2016-02-25 00:50:3126 Version(const Version& other);
27
[email protected]760024782011-06-07 17:21:3028 // Initializes from a decimal dotted version number, like "0.1.1".
avi9b6f42932015-12-26 22:15:1429 // Each component is limited to a uint16_t. Call IsValid() to learn
[email protected]760024782011-06-07 17:21:3030 // the outcome.
31 explicit Version(const std::string& version_str);
[email protected]19b8d82f2009-01-29 19:18:5732
staraz8fb38082016-07-25 18:48:2133 // Initializes from a vector of components, like {1, 2, 3, 4}. Call IsValid()
34 // to learn the outcome.
35 explicit Version(std::vector<uint32_t> components);
36
37 ~Version();
38
[email protected]760024782011-06-07 17:21:3039 // Returns true if the object contains a valid version number.
40 bool IsValid() const;
41
[email protected]810b25082012-07-04 16:22:4842 // Returns true if the version wildcard string is valid. The version wildcard
43 // string may end with ".*" (e.g. 1.2.*, 1.*). Any other arrangement with "*"
44 // is invalid (e.g. 1.*.3 or 1.2.3*). This functions defaults to standard
45 // Version behavior (IsValid) if no wildcard is present.
46 static bool IsValidWildcardString(const std::string& wildcard_string);
47
[email protected]19b8d82f2009-01-29 19:18:5748 // Returns -1, 0, 1 for <, ==, >.
49 int CompareTo(const Version& other) const;
50
[email protected]810b25082012-07-04 16:22:4851 // 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;
56
[email protected]19b8d82f2009-01-29 19:18:5757 // Return the string representation of this version.
58 const std::string GetString() const;
59
wfhbf68f4d5b2015-03-10 01:32:5960 const std::vector<uint32_t>& components() const { return components_; }
[email protected]19b8d82f2009-01-29 19:18:5761
[email protected]2fdc86a2010-01-26 23:08:0262 private:
wfhbf68f4d5b2015-03-10 01:32:5963 std::vector<uint32_t> components_;
[email protected]19b8d82f2009-01-29 19:18:5764};
65
robpercivaldcd8b102016-01-25 19:39:0066BASE_EXPORT bool operator==(const Version& v1, const Version& v2);
67BASE_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 std::ostream& operator<<(std::ostream& stream, const Version& v);
73
[email protected]1f04ef42013-04-22 07:35:5074} // namespace base
75
[email protected]19b8d82f2009-01-29 19:18:5776#endif // BASE_VERSION_H_