source: Include/Classes/System/Version.ab@ 268

Last change on this file since 268 was 257, checked in by イグトランス (egtra), 18 years ago

VersionTest追加、Log1p追加

File size: 3.4 KB
RevLine 
[142]1' System/Version.ab
2
[175]3#ifndef __SYSTEM_VERSION_AB__
4#define __SYSTEM_VERSION_AB__
5
6#require <api_winsock2.sbp>
7
[257]8Namespace System
9
[142]10Class Version
11 ' Inherits ICloneable, IComparable, IComparable<Version>, IEquatable<Version>
12Public
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
[212]27 This.build = -1
28 This.revision = -1
[142]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
[212]35 This.revision = -1
[142]36 End Sub
37
[161]38 Sub Version(major As Long, minor As Long, build As Long, revision As Long)
[142]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
[233]61 Const Function MajorRevision() As Integer
[142]62 Return HIWORD(revision) As Integer
63 End Function
64
[233]65 Const Function MinorRevision() As Integer
[142]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
[233]76 CompareTo = revision - v.revision
[142]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
[233]84 Return _System_BSwap(major As DWord) Xor minor Xor build Xor _System_BSwap(revision As DWord)
[142]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)
[233]115 If revision >= 0 Then
116 ToString = ToString + "." + Str$(revision)
[142]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
[212]130 ToString = ToString + "." + Str$(minor)
[142]131 If fieldCount = 2 Then Exit Function
132
133 If build < 0 Then
134 ' Throw ArgumentException
135 Debug
136 End If
[212]137 ToString = ToString + "." + Str$(build)
[142]138 If fieldCount = 3 Then Exit Function
139
[233]140 If revision < 0 Then
[142]141 ' Throw ArgumentException
142 Debug
143 End If
[233]144 ToString = ToString + "." + Str$(revision)
[142]145 End Function
146Private
147 major As Long
148 minor As Long
149 build As Long
[233]150 revision As Long
[142]151End Class
[175]152
[257]153End Namespace 'System
154
[175]155#endif '__SYSTEM_VERSION_AB__
Note: See TracBrowser for help on using the repository browser.