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