Changeset 709 for trunk/ab5.0/ablib/src/com/currency.ab
- Timestamp:
- Jun 29, 2009, 4:03:45 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/ablib/src/com/currency.ab
r478 r709 7 7 8 8 Class Currency 9 Implements System.ICloneable, System.IEquatable<Currency>', System.IComparable<Currency> 9 10 Public 10 11 Sub Currency() 11 12 cy = 0 12 13 End Sub 13 14 14 /* 15 15 Sub Currency(x As CY) … … 25 25 End Sub 26 26 */ 27 /* 28 Const Function Operator +() As Currency 29 Return New Currency(This) 30 End Function 31 */ 32 Const Function Operator -() As Currency 33 Dim ret = New Currency 34 VarCyNeg(This.cy, ret.cy) 35 Return ret 36 End Function 37 38 Const Function Operator *(y As Currency) As Currency 39 Dim ret = New Currency 40 VarCyMul(This.cy, y.cy, ret.cy) 41 Return ret 42 End Function 43 44 Const Function Operator *(y As Long) As Currency 45 Dim ret = New Currency 46 VarCyMulI4(This.cy, y, ret.cy) 47 Return ret 48 End Function 49 50 Const Function Operator *(y As Int64) As Currency 51 Dim ret = New Currency 52 VarCyMulI8(This.cy, y, ret.cy) 53 Return ret 54 End Function 55 56 Const Function Operator /(y As Variant) As Double 27 Static Function FromCy(cy As CY) As Currency 28 FromCy = New Currency 29 FromCy.cy = cy 30 End Function 31 32 Function Operator +() As Currency 33 Return FromCy(cy) 34 End Function 35 36 Function Operator -() As Currency 37 Dim ret = New Currency 38 Windows.ThrowIfFailed(VarCyNeg(This.cy, ret.cy)) 39 Return ret 40 End Function 41 42 Function Operator *(y As Currency) As Currency 43 Dim ret = New Currency 44 Windows.ThrowIfFailed(VarCyMul(This.cy, y.cy, ret.cy)) 45 Return ret 46 End Function 47 48 Function Operator *(y As Long) As Currency 49 Dim ret = New Currency 50 Windows.ThrowIfFailed(VarCyMulI4(This.cy, y, ret.cy)) 51 Return ret 52 End Function 53 54 Function Operator *(y As Int64) As Currency 55 Dim ret = New Currency 56 Windows.ThrowIfFailed(VarCyMulI8(This.cy, y, ret.cy)) 57 Return ret 58 End Function 59 60 Function Operator /(y As Variant) As Double 57 61 Dim vx = New Variant(This) 58 62 Dim ret = vx / y … … 60 64 End Function 61 65 62 ConstFunction Operator /(y As Currency) As Double66 Function Operator /(y As Currency) As Double 63 67 Dim vx = New Variant(This) 64 68 Dim vy = New Variant(y) … … 67 71 End Function 68 72 69 ConstFunction Operator +(y As Currency) As Currency70 Dim ret = New Currency 71 VarCyAdd(This.cy, y.cy, ret.cy)72 Return ret 73 End Function 74 75 ConstFunction Operator -(y As Currency) As Currency76 Dim ret = New Currency 77 VarCySub(This.cy, y.cy, ret.cy)73 Function Operator +(y As Currency) As Currency 74 Dim ret = New Currency 75 Windows.ThrowIfFailed(VarCyAdd(This.cy, y.cy, ret.cy)) 76 Return ret 77 End Function 78 79 Function Operator -(y As Currency) As Currency 80 Dim ret = New Currency 81 Windows.ThrowIfFailed(VarCySub(This.cy, y.cy, ret.cy)) 78 82 Return ret 79 83 End Function … … 99 103 End Function 100 104 101 ConstFunction Operator ==(y As Currency) As Boolean105 Function Operator ==(y As Currency) As Boolean 102 106 Dim c = Compare(This, y) 103 107 Return c = VARCMP_EQ 104 108 End Function 105 109 106 ConstFunction Operator ==(y As Double) As Boolean110 Function Operator ==(y As Double) As Boolean 107 111 Dim c = Compare(This, y) 108 112 Return c = VARCMP_EQ 109 113 End Function 110 114 111 ConstFunction Operator <>(y As Currency) As Boolean115 Function Operator <>(y As Currency) As Boolean 112 116 Dim c = Compare(This, y) 113 117 Return c <> VARCMP_EQ 114 118 End Function 115 119 116 ConstFunction Operator <>(y As Double) As Boolean120 Function Operator <>(y As Double) As Boolean 117 121 Dim c = Compare(This, y) 118 122 Return c <> VARCMP_EQ 119 123 End Function 120 124 121 ConstFunction Operator <(y As Currency) As Boolean125 Function Operator <(y As Currency) As Boolean 122 126 Dim c = Compare(This, y) 123 127 Return c = VARCMP_LT 124 128 End Function 125 129 126 ConstFunction Operator <(y As Double) As Boolean130 Function Operator <(y As Double) As Boolean 127 131 Dim c = Compare(This, y) 128 132 Return c = VARCMP_LT 129 133 End Function 130 134 131 ConstFunction Operator >(y As Currency) As Boolean135 Function Operator >(y As Currency) As Boolean 132 136 Dim c = Compare(This, y) 133 137 Return c = VARCMP_GT 134 138 End Function 135 139 136 ConstFunction Operator >(y As Double) As Boolean140 Function Operator >(y As Double) As Boolean 137 141 Dim c = Compare(This, y) 138 142 Return c = VARCMP_GT 139 143 End Function 140 144 141 ConstFunction Operator <=(y As Currency) As Boolean145 Function Operator <=(y As Currency) As Boolean 142 146 Dim c = Compare(This, y) 143 147 Return c = VARCMP_LT Or c = VARCMP_EQ 144 148 End Function 145 149 146 ConstFunction Operator <=(y As Double) As Boolean150 Function Operator <=(y As Double) As Boolean 147 151 Dim c = Compare(This, y) 148 152 Return c = VARCMP_LT Or c = VARCMP_EQ 149 153 End Function 150 154 151 ConstFunction Operator >=(y As Currency) As Boolean155 Function Operator >=(y As Currency) As Boolean 152 156 Dim c = Compare(This, y) 153 157 Return c = VARCMP_GT Or c = VARCMP_EQ 154 158 End Function 155 159 156 ConstFunction Operator >=(y As Double) As Boolean160 Function Operator >=(y As Double) As Boolean 157 161 Dim c = Compare(This, y) 158 162 Return c = VARCMP_GT Or c = VARCMP_EQ 159 163 End Function 160 164 161 ConstFunction Abs() As Currency165 Function Abs() As Currency 162 166 Abs = New Currency 163 VarCyAbs(This.cy, Abs.cy)164 End Function 165 166 ConstFunction Fix() As Currency167 Windows.ThrowIfFailed(VarCyAbs(This.cy, Abs.cy)) 168 End Function 169 170 Function Fix() As Currency 167 171 Fix = New Currency 168 VarCyFix(This.cy, Fix.cy)169 End Function 170 171 ConstFunction Int() As Currency172 Windows.ThrowIfFailed(VarCyFix(This.cy, Fix.cy)) 173 End Function 174 175 Function Int() As Currency 172 176 Int = New Currency 173 VarCyInt(This.cy, Int.cy)174 End Function 175 176 ConstFunction Round(c = 0 As Long) As Currency177 Windows.ThrowIfFailed(VarCyInt(This.cy, Int.cy)) 178 End Function 179 180 Function Round(c = 0 As Long) As Currency 177 181 Round = New Currency 178 VarCyRound(This.cy, c, Round.cy)179 End Function 180 181 ConstFunction Cy() As CY182 Windows.ThrowIfFailed(VarCyRound(This.cy, c, Round.cy)) 183 End Function 184 185 Function Cy() As CY 182 186 Cy = cy 183 187 End Function 184 188 185 Sub Cy(c As CY) 186 cy = c 187 End Sub 188 189 Const Function ToDouble() As Double 189 Function ToDouble() As Double 190 190 VarR8FromCy(cy, ToDouble) 191 191 End Function 192 192 193 ConstFunction ToInt64() As Int64193 Function ToInt64() As Int64 194 194 VarI8FromCy(cy, ToInt64) 195 195 End Function 196 196 197 ConstFunction ToVariant() As Variant197 Function ToVariant() As Variant 198 198 Return New Variant(This) 199 199 End Function 200 200 201 201 Override Function ToString() As String 202 /*Using*/ Dimbstr = New BString202 Using bstr = New BString 203 203 Dim bs As BSTR 204 204 VarBstrFromCy(cy, LOCALE_USER_DEFAULT, LOCALE_USE_NLS, bs) 205 205 bstr.Attach(bs) 206 ToString = bstr.ToString 207 bstr.Dispose() 'End Using206 ToString = bstr.ToString() 207 End Using 208 208 End Function 209 209 210 210 Override Function GetHashCode() As Long 211 Return HIDWORD(cy) Xor LODWORD(cy) 211 Return (HIDWORD(cy) Xor LODWORD(cy)) As Long 212 End Function 213 214 Override Function Equals(y As Object) As Boolean 215 If This.GetType().Equals(y.GetType()) Then 216 Equals = Equals(y As Currency) 217 Else 218 Equals = False 219 End If 212 220 End Function 213 221 … … 215 223 Dim c = Compare(This, y) 216 224 Return c = VARCMP_EQ 225 End Function 226 227 Function CompareTo(y As Currency) As Long 228 Dim c = Compare(This, y) 229 If c = VARCMP_GT Then 230 CompareTo = 1 231 ElseIf c = VARCMP_LT Then 232 CompareTo = -1 233 Else 234 CompareTo = 0 235 End If 236 End Function 237 238 Function Clone() As Currency 239 Clone = This 217 240 End Function 218 241 Private
Note:
See TracChangeset
for help on using the changeset viewer.