WebKit roll 98705:98715
[chromium-blink-merge.git] / base / version.h
blob2ea4101a9aecb2b7caeb768af2fd52071c9f21ea
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_export.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 class BASE_EXPORT Version {
19 public:
20 // The only thing you can legally do to a default constructed
21 // Version object is assign to it.
22 Version();
24 ~Version();
26 // Initializes from a decimal dotted version number, like "0.1.1".
27 // Each component is limited to a uint16. Call IsValid() to learn
28 // the outcome.
29 explicit Version(const std::string& version_str);
31 // Returns true if the object contains a valid version number.
32 bool IsValid() const;
34 // Commonly used pattern. Given a valid version object, compare if a
35 // |version_str| results in a newer version. Returns true if the
36 // string represents valid version and if the version is greater than
37 // than the version of this object.
38 bool IsOlderThan(const std::string& version_str) const;
40 // Returns NULL if the string is not in the proper format.
41 // Caller is responsible for freeing the Version object once done.
42 // DO NOT USE FOR NEWER CODE.
43 static Version* GetVersionFromString(const std::string& version_str);
45 // Creates a copy of this version object. Caller takes ownership.
46 // DO NOT USE FOR NEWER CODE.
47 Version* Clone() const;
49 bool Equals(const Version& other) const;
51 // Returns -1, 0, 1 for <, ==, >.
52 int CompareTo(const Version& other) const;
54 // Return the string representation of this version.
55 const std::string GetString() const;
57 const std::vector<uint16>& components() const { return components_; }
59 private:
60 std::vector<uint16> components_;
63 #endif // BASE_VERSION_H_