blob: 99e6650654b8af84d28bead0ac6cafe1a2269ac4 [file] [log] [blame]
[email protected]19b8d82f2009-01-29 19:18:571// Copyright (c) 2009 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.
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
12#include "base/basictypes.h"
[email protected]a918f872010-06-01 14:30:5113#include "base/gtest_prod_util.h"
[email protected]19b8d82f2009-01-29 19:18:5714
15class Version {
[email protected]2fdc86a2010-01-26 23:08:0216 public:
[email protected]19b8d82f2009-01-29 19:18:5717 // The version string must be made up of 1 or more uint16's separated
18 // by '.'. Returns NULL if string is not in this format.
19 // Caller is responsible for freeing the Version object once done.
20 static Version* GetVersionFromString(const std::wstring& version_str);
21 static Version* GetVersionFromString(const std::string& version_str);
22
[email protected]26931bc2010-03-25 22:19:0423 // Exposed only so that a Version can be stored in STL containers;
24 // any call to the methods below on a default-constructed Version
25 // will DCHECK.
26 Version();
27
[email protected]19b8d82f2009-01-29 19:18:5728 ~Version() {}
29
30 bool Equals(const Version& other) const;
31
32 // Returns -1, 0, 1 for <, ==, >.
33 int CompareTo(const Version& other) const;
34
35 // Return the string representation of this version.
36 const std::string GetString() const;
37
38 const std::vector<uint16>& components() const { return components_; }
39
[email protected]2fdc86a2010-01-26 23:08:0240 private:
[email protected]19b8d82f2009-01-29 19:18:5741 bool InitFromString(const std::string& version_str);
42
[email protected]26931bc2010-03-25 22:19:0443 bool is_valid_;
[email protected]19b8d82f2009-01-29 19:18:5744 std::vector<uint16> components_;
[email protected]26931bc2010-03-25 22:19:0445
[email protected]a918f872010-06-01 14:30:5146 FRIEND_TEST_ALL_PREFIXES(VersionTest, DefaultConstructor);
47 FRIEND_TEST_ALL_PREFIXES(VersionTest, GetVersionFromString);
48 FRIEND_TEST_ALL_PREFIXES(VersionTest, Compare);
[email protected]19b8d82f2009-01-29 19:18:5749};
50
51#endif // BASE_VERSION_H_