[go: nahoru, domu]

blob: 814acaa2b4ed83f29b5aafe47b6c48b649ec7ed0 [file] [log] [blame]
mathp@google.com810b2502012-07-04 16:22:481// Copyright (c) 2012 The Chromium Authors. All rights reserved.
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>
erikkay@google.com19b8d82f2009-01-29 19:18:579#include <string>
10#include <vector>
11
darin@chromium.org0bea7252011-08-05 15:34:0012#include "base/base_export.h"
erikkay@google.com19b8d82f2009-01-29 19:18:5713#include "base/basictypes.h"
14
xhwang@chromium.org1f04ef42013-04-22 07:35:5015namespace base {
16
evan@chromium.org36ee0322010-12-23 21:27:1217// Version represents a dotted version number, like "1.2.3.4", supporting
18// parsing and comparison.
darin@chromium.org0bea7252011-08-05 15:34:0019class BASE_EXPORT Version {
erg@google.com2fdc86a2010-01-26 23:08:0220 public:
cpu@chromium.org760024782011-06-07 17:21:3021 // The only thing you can legally do to a default constructed
22 // Version object is assign to it.
akalin@chromium.org26931bc2010-03-25 22:19:0423 Version();
erikkay@google.com19b8d82f2009-01-29 19:18:5724
cpu@chromium.org1513bf82011-06-07 17:43:2025 ~Version();
26
cpu@chromium.org760024782011-06-07 17:21:3027 // 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);
erikkay@google.com19b8d82f2009-01-29 19:18:5731
cpu@chromium.org760024782011-06-07 17:21:3032 // Returns true if the object contains a valid version number.
33 bool IsValid() const;
34
mathp@google.com810b2502012-07-04 16:22:4835 // 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);
40
cpu@chromium.org30c157c2011-08-01 17:45:0841 // 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;
46
erikkay@google.com19b8d82f2009-01-29 19:18:5747 bool Equals(const Version& other) const;
48
49 // Returns -1, 0, 1 for <, ==, >.
50 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.
56 int CompareToWildcardString(const std::string& wildcard_string) const;
57
erikkay@google.com19b8d82f2009-01-29 19:18:5758 // Return the string representation of this version.
59 const std::string GetString() const;
60
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
xhwang@chromium.org1f04ef42013-04-22 07:35:5067} // namespace base
68
avi@chromium.orgc5e4a2222014-01-03 16:06:1369// TODO(xhwang) remove this when all users are updated to explicitly use the
70// namespace
71using base::Version;
72
erikkay@google.com19b8d82f2009-01-29 19:18:5773#endif // BASE_VERSION_H_