[email protected] | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef BASE_VERSION_H_ | ||||
6 | #define BASE_VERSION_H_ | ||||
7 | |||||
8 | #include <string> | ||||
9 | #include <vector> | ||||
10 | |||||
11 | #include "base/basictypes.h" | ||||
[email protected] | 26931bc | 2010-03-25 22:19:04 | [diff] [blame^] | 12 | #include "testing/gtest/include/gtest/gtest_prod.h" |
[email protected] | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 13 | |
14 | class Version { | ||||
[email protected] | 2fdc86a | 2010-01-26 23:08:02 | [diff] [blame] | 15 | public: |
[email protected] | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 16 | // The version string must be made up of 1 or more uint16's separated |
17 | // by '.'. Returns NULL if string is not in this format. | ||||
18 | // Caller is responsible for freeing the Version object once done. | ||||
19 | static Version* GetVersionFromString(const std::wstring& version_str); | ||||
20 | static Version* GetVersionFromString(const std::string& version_str); | ||||
21 | |||||
[email protected] | 26931bc | 2010-03-25 22:19:04 | [diff] [blame^] | 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 | |||||
[email protected] | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 27 | ~Version() {} |
28 | |||||
29 | bool Equals(const Version& other) const; | ||||
30 | |||||
31 | // Returns -1, 0, 1 for <, ==, >. | ||||
32 | int CompareTo(const Version& other) const; | ||||
33 | |||||
34 | // Return the string representation of this version. | ||||
35 | const std::string GetString() const; | ||||
36 | |||||
37 | const std::vector<uint16>& components() const { return components_; } | ||||
38 | |||||
[email protected] | 2fdc86a | 2010-01-26 23:08:02 | [diff] [blame] | 39 | private: |
[email protected] | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 40 | bool InitFromString(const std::string& version_str); |
41 | |||||
[email protected] | 26931bc | 2010-03-25 22:19:04 | [diff] [blame^] | 42 | bool is_valid_; |
[email protected] | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 43 | std::vector<uint16> components_; |
[email protected] | 26931bc | 2010-03-25 22:19:04 | [diff] [blame^] | 44 | |
45 | FRIEND_TEST(VersionTest, DefaultConstructor); | ||||
46 | FRIEND_TEST(VersionTest, GetVersionFromString); | ||||
47 | FRIEND_TEST(VersionTest, Compare); | ||||
[email protected] | 19b8d82f | 2009-01-29 19:18:57 | [diff] [blame] | 48 | }; |
49 | |||||
50 | #endif // BASE_VERSION_H_ |