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_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 class BASE_API Version
{
20 // The only thing you can legally do to a default constructed
21 // Version object is assign to it.
26 // Initializes from a decimal dotted version number, like "0.1.1".
27 // Each component is limited to a uint16. Call IsValid() to learn
29 explicit Version(const std::string
& version_str
);
31 // Returns true if the object contains a valid version number.
34 // Returns NULL if the string is not in the proper format.
35 // Caller is responsible for freeing the Version object once done.
36 // DO NOT USE FOR NEWER CODE.
37 static Version
* GetVersionFromString(const std::string
& version_str
);
39 // Creates a copy of this version object. Caller takes ownership.
40 // DO NOT USE FOR NEWER CODE.
41 Version
* Clone() const;
43 bool Equals(const Version
& other
) const;
45 // Returns -1, 0, 1 for <, ==, >.
46 int CompareTo(const Version
& other
) const;
48 // Return the string representation of this version.
49 const std::string
GetString() const;
51 const std::vector
<uint16
>& components() const { return components_
; }
54 std::vector
<uint16
> components_
;
57 #endif // BASE_VERSION_H_