1 | ' System/Version.ab
|
---|
2 |
|
---|
3 | #ifndef __SYSTEM_VERSION_AB__
|
---|
4 | #define __SYSTEM_VERSION_AB__
|
---|
5 |
|
---|
6 | #require <api_winsock2.sbp>
|
---|
7 |
|
---|
8 | Namespace System
|
---|
9 |
|
---|
10 | Class Version
|
---|
11 | ' Inherits ICloneable, IComparable, IComparable<Version>, IEquatable<Version>
|
---|
12 | Public
|
---|
13 | ' Constractor
|
---|
14 | Sub Version()
|
---|
15 | major = 0
|
---|
16 | minor = 0
|
---|
17 | build = -1
|
---|
18 | revision = -1
|
---|
19 | End Sub
|
---|
20 |
|
---|
21 | 'Sub Version(s As String)
|
---|
22 | 'End Sub
|
---|
23 |
|
---|
24 | Sub Version(major As Long, minor As Long)
|
---|
25 | This.major = major
|
---|
26 | This.minor = minor
|
---|
27 | This.build = -1
|
---|
28 | This.revision = -1
|
---|
29 | End Sub
|
---|
30 |
|
---|
31 | Sub Version(major As Long, minor As Long, build As Long)
|
---|
32 | This.major = major
|
---|
33 | This.minor = minor
|
---|
34 | This.build = build
|
---|
35 | This.revision = -1
|
---|
36 | End Sub
|
---|
37 |
|
---|
38 | Sub Version(major As Long, minor As Long, build As Long, revision As Long)
|
---|
39 | This.major = major
|
---|
40 | This.minor = minor
|
---|
41 | This.build = build
|
---|
42 | This.revision = revision
|
---|
43 | End Sub
|
---|
44 |
|
---|
45 | Const Function Major() As Long
|
---|
46 | Return major
|
---|
47 | End Function
|
---|
48 |
|
---|
49 | Const Function Minor() As Long
|
---|
50 | Return minor
|
---|
51 | End Function
|
---|
52 |
|
---|
53 | Const Function Build() As Long
|
---|
54 | Return build
|
---|
55 | End Function
|
---|
56 |
|
---|
57 | Const Function Revision() As Long
|
---|
58 | Return revision
|
---|
59 | End Function
|
---|
60 |
|
---|
61 | Const Function MajorRevision() As Integer
|
---|
62 | Return HIWORD(revision) As Integer
|
---|
63 | End Function
|
---|
64 |
|
---|
65 | Const Function MinorRevision() As Integer
|
---|
66 | Return LOWORD(revision) As Integer
|
---|
67 | End Function
|
---|
68 |
|
---|
69 | Const Function CompareTo(v As Version) As Long
|
---|
70 | CompareTo = major - v.major
|
---|
71 | If CompareTo <> 0 Then Exit Function
|
---|
72 | CompareTo = minor - v.minor
|
---|
73 | If CompareTo <> 0 Then Exit Function
|
---|
74 | CompareTo = build - v.build
|
---|
75 | If CompareTo <> 0 Then Exit Function
|
---|
76 | CompareTo = revision - v.revision
|
---|
77 | End Function
|
---|
78 |
|
---|
79 | Const Function Equals(v As Version) As Boolean
|
---|
80 | Return CompareTo(v) = 0
|
---|
81 | End Function
|
---|
82 |
|
---|
83 | Override Function GetHashCode() As Long
|
---|
84 | Return _System_BSwap(major As DWord) Xor minor Xor build Xor _System_BSwap(revision As DWord)
|
---|
85 | End Function
|
---|
86 |
|
---|
87 | Function Operator ==(v As Version) As Boolean
|
---|
88 | Return CompareTo(v) = 0
|
---|
89 | End Function
|
---|
90 |
|
---|
91 | Function Operator <>(v As Version) As Boolean
|
---|
92 | Return CompareTo(v) <> 0
|
---|
93 | End Function
|
---|
94 |
|
---|
95 | Function Operator <(v As Version) As Boolean
|
---|
96 | Return CompareTo(v) < 0
|
---|
97 | End Function
|
---|
98 |
|
---|
99 | Function Operator >(v As Version) As Boolean
|
---|
100 | Return CompareTo(v) > 0
|
---|
101 | End Function
|
---|
102 |
|
---|
103 | Function Operator <=(v As Version) As Boolean
|
---|
104 | Return CompareTo(v) <= 0
|
---|
105 | End Function
|
---|
106 |
|
---|
107 | Function Operator >=(v As Version) As Boolean
|
---|
108 | Return CompareTo(v) >= 0
|
---|
109 | End Function
|
---|
110 |
|
---|
111 | Override Function ToString() As String
|
---|
112 | ToString = Str$(major) + "." + Str$(minor)
|
---|
113 | If build >= 0 Then
|
---|
114 | ToString = ToString + "." + Str$(build)
|
---|
115 | If revision >= 0 Then
|
---|
116 | ToString = ToString + "." + Str$(revision)
|
---|
117 | End If
|
---|
118 | End If
|
---|
119 | End Function
|
---|
120 |
|
---|
121 | Function ToString(fieldCount As Long) As String
|
---|
122 | If fieldCount < 0 Or fieldCount > 4 Then
|
---|
123 | ' Throw ArgumentException
|
---|
124 | Debug
|
---|
125 | End If
|
---|
126 | ToString = ""
|
---|
127 | If fieldCount = 0 Then Exit Function
|
---|
128 | ToString = Str$(major)
|
---|
129 | If fieldCount = 1 Then Exit Function
|
---|
130 | ToString = ToString + "." + Str$(minor)
|
---|
131 | If fieldCount = 2 Then Exit Function
|
---|
132 |
|
---|
133 | If build < 0 Then
|
---|
134 | ' Throw ArgumentException
|
---|
135 | Debug
|
---|
136 | End If
|
---|
137 | ToString = ToString + "." + Str$(build)
|
---|
138 | If fieldCount = 3 Then Exit Function
|
---|
139 |
|
---|
140 | If revision < 0 Then
|
---|
141 | ' Throw ArgumentException
|
---|
142 | Debug
|
---|
143 | End If
|
---|
144 | ToString = ToString + "." + Str$(revision)
|
---|
145 | End Function
|
---|
146 | Private
|
---|
147 | major As Long
|
---|
148 | minor As Long
|
---|
149 | build As Long
|
---|
150 | revision As Long
|
---|
151 | End Class
|
---|
152 |
|
---|
153 | End Namespace 'System
|
---|
154 |
|
---|
155 | #endif '__SYSTEM_VERSION_AB__
|
---|