blob: 7dcefb3d063d859b335fcff505c5531e6bc8d3eb [file] [log] [blame]
[email protected]a502bbe72011-01-07 18:06:451// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]19b8d82f2009-01-29 19:18:572// 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_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]19b8d82f2009-01-29 19:18:578
9#include <string>
10#include <vector>
11
[email protected]f5661ca2011-03-24 19:00:2012#include "base/base_api.h"
[email protected]19b8d82f2009-01-29 19:18:5713#include "base/basictypes.h"
[email protected]a918f872010-06-01 14:30:5114#include "base/gtest_prod_util.h"
[email protected]19b8d82f2009-01-29 19:18:5715
[email protected]36ee0322010-12-23 21:27:1216// Version represents a dotted version number, like "1.2.3.4", supporting
17// parsing and comparison.
[email protected]f5661ca2011-03-24 19:00:2018class BASE_API Version {
[email protected]2fdc86a2010-01-26 23:08:0219 public:
[email protected]760024782011-06-07 17:21:3020 // The only thing you can legally do to a default constructed
21 // Version object is assign to it.
[email protected]26931bc2010-03-25 22:19:0422 Version();
23
[email protected]760024782011-06-07 17:21:3024 // Initializes from a decimal dotted version number, like "0.1.1".
25 // Each component is limited to a uint16. Call IsValid() to learn
26 // the outcome.
27 explicit Version(const std::string& version_str);
[email protected]19b8d82f2009-01-29 19:18:5728
[email protected]760024782011-06-07 17:21:3029 // Returns true if the object contains a valid version number.
30 bool IsValid() const;
31
32 // Returns NULL if the string is not in the proper format.
[email protected]a502bbe72011-01-07 18:06:4533 // Caller is responsible for freeing the Version object once done.
[email protected]760024782011-06-07 17:21:3034 // DO NOT USE FOR NEWER CODE.
[email protected]a502bbe72011-01-07 18:06:4535 static Version* GetVersionFromString(const std::string& version_str);
36
[email protected]760024782011-06-07 17:21:3037 // Creates a copy of this version object. Caller takes ownership.
38 // DO NOT USE FOR NEWER CODE.
[email protected]b566c112010-12-21 08:27:2539 Version* Clone() const;
40
[email protected]19b8d82f2009-01-29 19:18:5741 bool Equals(const Version& other) const;
42
43 // Returns -1, 0, 1 for <, ==, >.
44 int CompareTo(const Version& other) const;
45
46 // Return the string representation of this version.
47 const std::string GetString() const;
48
49 const std::vector<uint16>& components() const { return components_; }
50
[email protected]2fdc86a2010-01-26 23:08:0251 private:
[email protected]19b8d82f2009-01-29 19:18:5752 std::vector<uint16> components_;
[email protected]19b8d82f2009-01-29 19:18:5753};
54
55#endif // BASE_VERSION_H_