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