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