1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * VBoxVersion class declaration
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2011 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #ifndef ___VBoxVersion_h___
|
---|
20 | #define ___VBoxVersion_h___
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Represents VirtualBox version wrapper
|
---|
24 | */
|
---|
25 | class VBoxVersion
|
---|
26 | {
|
---|
27 | public:
|
---|
28 |
|
---|
29 | VBoxVersion() : m_x(-1), m_y(-1), m_z(-1) {}
|
---|
30 |
|
---|
31 | VBoxVersion(const QString &strVersion)
|
---|
32 | : m_x(-1), m_y(-1), m_z(-1)
|
---|
33 | {
|
---|
34 | QStringList versionStack = strVersion.split('.');
|
---|
35 | if (versionStack.size() > 0)
|
---|
36 | m_x = versionStack[0].toInt();
|
---|
37 | if (versionStack.size() > 1)
|
---|
38 | m_y = versionStack[1].toInt();
|
---|
39 | if (versionStack.size() > 2)
|
---|
40 | m_z = versionStack[2].toInt();
|
---|
41 | }
|
---|
42 |
|
---|
43 | VBoxVersion& operator=(const VBoxVersion &other) { m_x = other.x(); m_y = other.y(); m_z = other.z(); return *this; }
|
---|
44 |
|
---|
45 | bool isValid() const { return m_x != -1 && m_y != -1 && m_z != -1; }
|
---|
46 |
|
---|
47 | bool equal(const VBoxVersion &other) const { return (m_x == other.m_x) && (m_y == other.m_y) && (m_z == other.m_z); }
|
---|
48 | bool operator==(const VBoxVersion &other) const { return equal(other); }
|
---|
49 | bool operator!=(const VBoxVersion &other) const { return !equal(other); }
|
---|
50 |
|
---|
51 | bool operator<(const VBoxVersion &other) const
|
---|
52 | {
|
---|
53 | return (m_x < other.m_x) ||
|
---|
54 | (m_x == other.m_x && m_y < other.m_y) ||
|
---|
55 | (m_x == other.m_x && m_y == other.m_y && m_z < other.m_z);
|
---|
56 | }
|
---|
57 | bool operator>(const VBoxVersion &other) const
|
---|
58 | {
|
---|
59 | return (m_x > other.m_x) ||
|
---|
60 | (m_x == other.m_x && m_y > other.m_y) ||
|
---|
61 | (m_x == other.m_x && m_y == other.m_y && m_z > other.m_z);
|
---|
62 | }
|
---|
63 |
|
---|
64 | QString toString() const
|
---|
65 | {
|
---|
66 | return QString("%1.%2.%3").arg(m_x).arg(m_y).arg(m_z);
|
---|
67 | }
|
---|
68 |
|
---|
69 | int x() const { return m_x; }
|
---|
70 | int y() const { return m_y; }
|
---|
71 | int z() const { return m_z; }
|
---|
72 |
|
---|
73 | private:
|
---|
74 |
|
---|
75 | int m_x;
|
---|
76 | int m_y;
|
---|
77 | int m_z;
|
---|
78 | };
|
---|
79 |
|
---|
80 | #endif // !___VBoxVersion_h___
|
---|
81 |
|
---|