roll skia 1111->1115
[chromium-blink-merge.git] / base / version.h
blobd256d069b9cf7198e85cbcf7f23987e42c508abf
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
3 // found in the LICENSE file.
5 #ifndef BASE_VERSION_H_
6 #define BASE_VERSION_H_
7 #pragma once
9 #include <string>
10 #include <vector>
12 #include "base/base_api.h"
13 #include "base/basictypes.h"
14 #include "base/gtest_prod_util.h"
16 // Version represents a dotted version number, like "1.2.3.4", supporting
17 // parsing and comparison.
18 // Each component is limited to a uint16.
19 class BASE_API Version {
20 public:
21 // Exposed only so that a Version can be stored in STL containers;
22 // any call to the methods below on a default-constructed Version
23 // will DCHECK.
24 Version();
26 ~Version();
28 // The version string must be made up of 1 or more uint16's separated
29 // by '.'. Returns NULL if string is not in this format.
30 // Caller is responsible for freeing the Version object once done.
31 static Version* GetVersionFromString(const std::string& version_str);
33 // Creates a copy of this version. Caller takes ownership.
34 Version* Clone() const;
36 bool Equals(const Version& other) const;
38 // Returns -1, 0, 1 for <, ==, >.
39 int CompareTo(const Version& other) const;
41 // Return the string representation of this version.
42 const std::string GetString() const;
44 const std::vector<uint16>& components() const { return components_; }
46 private:
47 bool InitFromString(const std::string& version_str);
49 bool is_valid_;
50 std::vector<uint16> components_;
52 FRIEND_TEST_ALL_PREFIXES(VersionTest, DefaultConstructor);
53 FRIEND_TEST_ALL_PREFIXES(VersionTest, GetVersionFromString);
54 FRIEND_TEST_ALL_PREFIXES(VersionTest, Compare);
57 #endif // BASE_VERSION_H_