blob: d256d069b9cf7198e85cbcf7f23987e42c508abf [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.
18// Each component is limited to a uint16.
[email protected]f5661ca2011-03-24 19:00:2019class BASE_API Version {
[email protected]2fdc86a2010-01-26 23:08:0220 public:
[email protected]26931bc2010-03-25 22:19:0421 // 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();
25
[email protected]2858bbf2010-10-05 23:46:0226 ~Version();
[email protected]19b8d82f2009-01-29 19:18:5727
[email protected]a502bbe72011-01-07 18:06:4528 // 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);
32
[email protected]b566c112010-12-21 08:27:2533 // Creates a copy of this version. Caller takes ownership.
34 Version* Clone() const;
35
[email protected]19b8d82f2009-01-29 19:18:5736 bool Equals(const Version& other) const;
37
38 // Returns -1, 0, 1 for <, ==, >.
39 int CompareTo(const Version& other) const;
40
41 // Return the string representation of this version.
42 const std::string GetString() const;
43
44 const std::vector<uint16>& components() const { return components_; }
45
[email protected]2fdc86a2010-01-26 23:08:0246 private:
[email protected]19b8d82f2009-01-29 19:18:5747 bool InitFromString(const std::string& version_str);
48
[email protected]26931bc2010-03-25 22:19:0449 bool is_valid_;
[email protected]19b8d82f2009-01-29 19:18:5750 std::vector<uint16> components_;
[email protected]26931bc2010-03-25 22:19:0451
[email protected]a918f872010-06-01 14:30:5152 FRIEND_TEST_ALL_PREFIXES(VersionTest, DefaultConstructor);
53 FRIEND_TEST_ALL_PREFIXES(VersionTest, GetVersionFromString);
54 FRIEND_TEST_ALL_PREFIXES(VersionTest, Compare);
[email protected]19b8d82f2009-01-29 19:18:5755};
56
57#endif // BASE_VERSION_H_