blob: 8d45899c4fc2797bdca676263b793137cde4b742 [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_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]19b8d82f2009-01-29 19:18:578
9#include <string>
10#include <vector>
11
[email protected]0bea7252011-08-05 15:34:0012#include "base/base_export.h"
[email protected]19b8d82f2009-01-29 19:18:5713#include "base/basictypes.h"
14
[email protected]36ee0322010-12-23 21:27:1215// Version represents a dotted version number, like "1.2.3.4", supporting
16// parsing and comparison.
[email protected]0bea7252011-08-05 15:34:0017class BASE_EXPORT Version {
[email protected]2fdc86a2010-01-26 23:08:0218 public:
[email protected]760024782011-06-07 17:21:3019 // The only thing you can legally do to a default constructed
20 // Version object is assign to it.
[email protected]26931bc2010-03-25 22:19:0421 Version();
22
[email protected]1513bf82011-06-07 17:43:2023 ~Version();
24
[email protected]760024782011-06-07 17:21:3025 // Initializes from a decimal dotted version number, like "0.1.1".
26 // Each component is limited to a uint16. Call IsValid() to learn
27 // the outcome.
28 explicit Version(const std::string& version_str);
[email protected]19b8d82f2009-01-29 19:18:5729
[email protected]760024782011-06-07 17:21:3030 // Returns true if the object contains a valid version number.
31 bool IsValid() const;
32
[email protected]810b25082012-07-04 16:22:4833 // Returns true if the version wildcard string is valid. The version wildcard
34 // string may end with ".*" (e.g. 1.2.*, 1.*). Any other arrangement with "*"
35 // is invalid (e.g. 1.*.3 or 1.2.3*). This functions defaults to standard
36 // Version behavior (IsValid) if no wildcard is present.
37 static bool IsValidWildcardString(const std::string& wildcard_string);
38
[email protected]30c157c2011-08-01 17:45:0839 // Commonly used pattern. Given a valid version object, compare if a
40 // |version_str| results in a newer version. Returns true if the
41 // string represents valid version and if the version is greater than
42 // than the version of this object.
43 bool IsOlderThan(const std::string& version_str) const;
44
[email protected]760024782011-06-07 17:21:3045 // Returns NULL if the string is not in the proper format.
[email protected]a502bbe72011-01-07 18:06:4546 // Caller is responsible for freeing the Version object once done.
[email protected]760024782011-06-07 17:21:3047 // DO NOT USE FOR NEWER CODE.
[email protected]a502bbe72011-01-07 18:06:4548 static Version* GetVersionFromString(const std::string& version_str);
49
[email protected]760024782011-06-07 17:21:3050 // Creates a copy of this version object. Caller takes ownership.
51 // DO NOT USE FOR NEWER CODE.
[email protected]b566c112010-12-21 08:27:2552 Version* Clone() const;
53
[email protected]19b8d82f2009-01-29 19:18:5754 bool Equals(const Version& other) const;
55
56 // Returns -1, 0, 1 for <, ==, >.
57 int CompareTo(const Version& other) const;
58
[email protected]810b25082012-07-04 16:22:4859 // Given a valid version object, compare if a |wildcard_string| results in a
60 // newer version. This function will default to CompareTo if the string does
61 // not end in wildcard sequence ".*". IsValidWildcard(wildcard_string) must be
62 // true before using this function.
63 int CompareToWildcardString(const std::string& wildcard_string) const;
64
[email protected]19b8d82f2009-01-29 19:18:5765 // Return the string representation of this version.
66 const std::string GetString() const;
67
68 const std::vector<uint16>& components() const { return components_; }
69
[email protected]2fdc86a2010-01-26 23:08:0270 private:
[email protected]19b8d82f2009-01-29 19:18:5771 std::vector<uint16> components_;
[email protected]19b8d82f2009-01-29 19:18:5772};
73
74#endif // BASE_VERSION_H_