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_
12 #include "base/base_export.h"
13 #include "base/basictypes.h"
15 // Version represents a dotted version number, like "1.2.3.4", supporting
16 // parsing and comparison.
17 class BASE_EXPORT Version
{
19 // The only thing you can legally do to a default constructed
20 // Version object is assign to it.
25 // Initializes from a decimal dotted version number, like "0.1.1".
26 // Each component is limited to a uint16. Call IsValid() to learn
28 explicit Version(const std::string
& version_str
);
30 // Returns true if the object contains a valid version number.
33 // Commonly used pattern. Given a valid version object, compare if a
34 // |version_str| results in a newer version. Returns true if the
35 // string represents valid version and if the version is greater than
36 // than the version of this object.
37 bool IsOlderThan(const std::string
& version_str
) const;
39 // Returns NULL if the string is not in the proper format.
40 // Caller is responsible for freeing the Version object once done.
41 // DO NOT USE FOR NEWER CODE.
42 static Version
* GetVersionFromString(const std::string
& version_str
);
44 // Creates a copy of this version object. Caller takes ownership.
45 // DO NOT USE FOR NEWER CODE.
46 Version
* Clone() const;
48 bool Equals(const Version
& other
) const;
50 // Returns -1, 0, 1 for <, ==, >.
51 int CompareTo(const Version
& other
) const;
53 // Return the string representation of this version.
54 const std::string
GetString() const;
56 const std::vector
<uint16
>& components() const { return components_
; }
59 std::vector
<uint16
> components_
;
62 #endif // BASE_VERSION_H_