[email protected] | a502bbe7 | 2011-01-07 18:06:45 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 2 | // 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] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 8 | |
9 | #include <string> | ||||
10 | #include <vector> | ||||
11 | |||||
[email protected] | f5661ca | 2011-03-24 19:00:20 | [diff] [blame] | 12 | #include "base/base_api.h" |
[email protected] | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 13 | #include "base/basictypes.h" |
[email protected] | a918f87 | 2010-06-01 14:30:51 | [diff] [blame] | 14 | #include "base/gtest_prod_util.h" |
[email protected] | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 15 | |
[email protected] | 36ee032 | 2010-12-23 21:27:12 | [diff] [blame] | 16 | // Version represents a dotted version number, like "1.2.3.4", supporting |
17 | // parsing and comparison. | ||||
[email protected] | f5661ca | 2011-03-24 19:00:20 | [diff] [blame] | 18 | class BASE_API Version { |
[email protected] | 2fdc86a | 2010-01-26 23:08:02 | [diff] [blame] | 19 | public: |
[email protected] | 76002478 | 2011-06-07 17:21:30 | [diff] [blame] | 20 | // The only thing you can legally do to a default constructed |
21 | // Version object is assign to it. | ||||
[email protected] | 26931bc | 2010-03-25 22:19:04 | [diff] [blame] | 22 | Version(); |
23 | |||||
[email protected] | 1513bf8 | 2011-06-07 17:43:20 | [diff] [blame^] | 24 | ~Version(); |
25 | |||||
[email protected] | 76002478 | 2011-06-07 17:21:30 | [diff] [blame] | 26 | // Initializes from a decimal dotted version number, like "0.1.1". |
27 | // Each component is limited to a uint16. Call IsValid() to learn | ||||
28 | // the outcome. | ||||
29 | explicit Version(const std::string& version_str); | ||||
[email protected] | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 30 | |
[email protected] | 76002478 | 2011-06-07 17:21:30 | [diff] [blame] | 31 | // Returns true if the object contains a valid version number. |
32 | bool IsValid() const; | ||||
33 | |||||
34 | // Returns NULL if the string is not in the proper format. | ||||
[email protected] | a502bbe7 | 2011-01-07 18:06:45 | [diff] [blame] | 35 | // Caller is responsible for freeing the Version object once done. |
[email protected] | 76002478 | 2011-06-07 17:21:30 | [diff] [blame] | 36 | // DO NOT USE FOR NEWER CODE. |
[email protected] | a502bbe7 | 2011-01-07 18:06:45 | [diff] [blame] | 37 | static Version* GetVersionFromString(const std::string& version_str); |
38 | |||||
[email protected] | 76002478 | 2011-06-07 17:21:30 | [diff] [blame] | 39 | // Creates a copy of this version object. Caller takes ownership. |
40 | // DO NOT USE FOR NEWER CODE. | ||||
[email protected] | b566c11 | 2010-12-21 08:27:25 | [diff] [blame] | 41 | Version* Clone() const; |
42 | |||||
[email protected] | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 43 | bool Equals(const Version& other) const; |
44 | |||||
45 | // Returns -1, 0, 1 for <, ==, >. | ||||
46 | int CompareTo(const Version& other) const; | ||||
47 | |||||
48 | // Return the string representation of this version. | ||||
49 | const std::string GetString() const; | ||||
50 | |||||
51 | const std::vector<uint16>& components() const { return components_; } | ||||
52 | |||||
[email protected] | 2fdc86a | 2010-01-26 23:08:02 | [diff] [blame] | 53 | private: |
[email protected] | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 54 | std::vector<uint16> components_; |
[email protected] | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 55 | }; |
56 | |||||
57 | #endif // BASE_VERSION_H_ |