blob: 30cb735b16cf572e971c0b185ee486c649eea866 [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
[email protected]1513bf82011-06-07 17:43:2026 ~Version();
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
[email protected]760024782011-06-07 17:21:3033 // Returns true if the object contains a valid version number.
34 bool IsValid() const;
35
[email protected]810b25082012-07-04 16:22:4836 // Returns true if the version wildcard string is valid. The version wildcard
37 // string may end with ".*" (e.g. 1.2.*, 1.*). Any other arrangement with "*"
38 // is invalid (e.g. 1.*.3 or 1.2.3*). This functions defaults to standard
39 // Version behavior (IsValid) if no wildcard is present.
40 static bool IsValidWildcardString(const std::string& wildcard_string);
41
[email protected]19b8d82f2009-01-29 19:18:5742 // Returns -1, 0, 1 for <, ==, >.
43 int CompareTo(const Version& other) const;
44
[email protected]810b25082012-07-04 16:22:4845 // Given a valid version object, compare if a |wildcard_string| results in a
46 // newer version. This function will default to CompareTo if the string does
47 // not end in wildcard sequence ".*". IsValidWildcard(wildcard_string) must be
48 // true before using this function.
49 int CompareToWildcardString(const std::string& wildcard_string) const;
50
[email protected]19b8d82f2009-01-29 19:18:5751 // Return the string representation of this version.
52 const std::string GetString() const;
53
wfhbf68f4d5b2015-03-10 01:32:5954 const std::vector<uint32_t>& components() const { return components_; }
[email protected]19b8d82f2009-01-29 19:18:5755
[email protected]2fdc86a2010-01-26 23:08:0256 private:
wfhbf68f4d5b2015-03-10 01:32:5957 std::vector<uint32_t> components_;
[email protected]19b8d82f2009-01-29 19:18:5758};
59
robpercivaldcd8b102016-01-25 19:39:0060BASE_EXPORT bool operator==(const Version& v1, const Version& v2);
61BASE_EXPORT bool operator!=(const Version& v1, const Version& v2);
62BASE_EXPORT bool operator<(const Version& v1, const Version& v2);
63BASE_EXPORT bool operator<=(const Version& v1, const Version& v2);
64BASE_EXPORT bool operator>(const Version& v1, const Version& v2);
65BASE_EXPORT bool operator>=(const Version& v1, const Version& v2);
66BASE_EXPORT std::ostream& operator<<(std::ostream& stream, const Version& v);
67
[email protected]1f04ef42013-04-22 07:35:5068} // namespace base
69
thakis37be69c2015-08-19 03:26:5770// TODO(xhwang) remove this when all users are updated to explicitly use the
71// namespace
72using base::Version;
73
[email protected]19b8d82f2009-01-29 19:18:5774#endif // BASE_VERSION_H_