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