OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "testing/gtest/include/gtest/gtest_prod.h" |
12 | 13 |
13 class Version { | 14 class Version { |
14 public: | 15 public: |
15 // The version string must be made up of 1 or more uint16's separated | 16 // The version string must be made up of 1 or more uint16's separated |
16 // by '.'. Returns NULL if string is not in this format. | 17 // by '.'. Returns NULL if string is not in this format. |
17 // Caller is responsible for freeing the Version object once done. | 18 // Caller is responsible for freeing the Version object once done. |
18 static Version* GetVersionFromString(const std::wstring& version_str); | 19 static Version* GetVersionFromString(const std::wstring& version_str); |
19 static Version* GetVersionFromString(const std::string& version_str); | 20 static Version* GetVersionFromString(const std::string& version_str); |
20 | 21 |
| 22 // Exposed only so that a Version can be stored in STL containers; |
| 23 // any call to the methods below on a default-constructed Version |
| 24 // will DCHECK. |
| 25 Version(); |
| 26 |
21 ~Version() {} | 27 ~Version() {} |
22 | 28 |
23 bool Equals(const Version& other) const; | 29 bool Equals(const Version& other) const; |
24 | 30 |
25 // Returns -1, 0, 1 for <, ==, >. | 31 // Returns -1, 0, 1 for <, ==, >. |
26 int CompareTo(const Version& other) const; | 32 int CompareTo(const Version& other) const; |
27 | 33 |
28 // Return the string representation of this version. | 34 // Return the string representation of this version. |
29 const std::string GetString() const; | 35 const std::string GetString() const; |
30 | 36 |
31 const std::vector<uint16>& components() const { return components_; } | 37 const std::vector<uint16>& components() const { return components_; } |
32 | 38 |
33 private: | 39 private: |
34 Version() {} | |
35 bool InitFromString(const std::string& version_str); | 40 bool InitFromString(const std::string& version_str); |
36 | 41 |
| 42 bool is_valid_; |
37 std::vector<uint16> components_; | 43 std::vector<uint16> components_; |
| 44 |
| 45 FRIEND_TEST(VersionTest, DefaultConstructor); |
| 46 FRIEND_TEST(VersionTest, GetVersionFromString); |
| 47 FRIEND_TEST(VersionTest, Compare); |
38 }; | 48 }; |
39 | 49 |
40 #endif // BASE_VERSION_H_ | 50 #endif // BASE_VERSION_H_ |
OLD | NEW |