OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_VERSION_H_ | 5 #ifndef BASE_VERSION_H_ |
6 #define BASE_VERSION_H_ | 6 #define BASE_VERSION_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/base_api.h" | 12 #include "base/base_api.h" |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 | 15 |
16 // Version represents a dotted version number, like "1.2.3.4", supporting | 16 // Version represents a dotted version number, like "1.2.3.4", supporting |
17 // parsing and comparison. | 17 // parsing and comparison. |
18 // Each component is limited to a uint16. | |
19 class BASE_API Version { | 18 class BASE_API Version { |
20 public: | 19 public: |
21 // Exposed only so that a Version can be stored in STL containers; | 20 // The only two things you can legally do to a default constructed |
22 // any call to the methods below on a default-constructed Version | 21 // Version object is assign to it and call InitFromString(). |
23 // will DCHECK. | |
24 Version(); | 22 Version(); |
25 | 23 |
26 ~Version(); | 24 // Initializes from a decimal dotted version number. See InitFromString() |
25 // for constraints on the inputs. | |
Evan Martin
2011/06/06 23:35:13
What happens to the return value of InitFromString
| |
26 explicit Version(const std::string& version_str); | |
27 | 27 |
28 // The version string must be made up of 1 or more uint16's separated | 28 // Initializes from a decimal dotted version number, like "0.1.1". |
29 // by '.'. Returns NULL if string is not in this format. | 29 // Each component is limited to a uint16. Returns false if any of the |
30 // Caller is responsible for freeing the Version object once done. | 30 // components is not convertible to uint16. |
31 bool InitFromString(const std::string& version_str); | |
32 | |
33 // Same as InitFromString Returns NULL if the string is not in the | |
34 // propper format. Caller is responsible for freeing the Version | |
Evan Martin
2011/06/06 23:35:13
Typo: maybe meant a period before capitalized "Ret
| |
35 // object once done. | |
36 // DO NOT USE FOR NEWER CODE. | |
31 static Version* GetVersionFromString(const std::string& version_str); | 37 static Version* GetVersionFromString(const std::string& version_str); |
32 | 38 |
33 // Creates a copy of this version. Caller takes ownership. | 39 // Creates a copy of this version. Caller takes ownership. |
40 // DO NOT USE FOR NEWER CODE. | |
34 Version* Clone() const; | 41 Version* Clone() const; |
35 | 42 |
36 bool Equals(const Version& other) const; | 43 bool Equals(const Version& other) const; |
37 | 44 |
38 // Returns -1, 0, 1 for <, ==, >. | 45 // Returns -1, 0, 1 for <, ==, >. |
39 int CompareTo(const Version& other) const; | 46 int CompareTo(const Version& other) const; |
40 | 47 |
48 // Returns true if at least the version has one valid | |
49 // component. For example 12 and 12.2 are both valid versions. | |
50 bool IsValid() const; | |
51 | |
41 // Return the string representation of this version. | 52 // Return the string representation of this version. |
42 const std::string GetString() const; | 53 const std::string GetString() const; |
43 | 54 |
44 const std::vector<uint16>& components() const { return components_; } | 55 const std::vector<uint16>& components() const { return components_; } |
45 | 56 |
46 private: | 57 private: |
47 bool InitFromString(const std::string& version_str); | |
48 | |
49 bool is_valid_; | |
50 std::vector<uint16> components_; | 58 std::vector<uint16> components_; |
51 | |
52 FRIEND_TEST_ALL_PREFIXES(VersionTest, DefaultConstructor); | |
53 FRIEND_TEST_ALL_PREFIXES(VersionTest, GetVersionFromString); | |
54 FRIEND_TEST_ALL_PREFIXES(VersionTest, Compare); | |
55 }; | 59 }; |
56 | 60 |
57 #endif // BASE_VERSION_H_ | 61 #endif // BASE_VERSION_H_ |
OLD | NEW |