[192] | 1 | ' com/currency.ab
|
---|
| 2 |
|
---|
[200] | 3 | #require <com/variant.ab>
|
---|
| 4 |
|
---|
| 5 | #ifndef _COM_CURRENCY_AB
|
---|
| 6 | #define _COM_CURRENCY_AB
|
---|
| 7 |
|
---|
[192] | 8 | Class Currency
|
---|
| 9 | Public
|
---|
[200] | 10 | /*
|
---|
| 11 | Sub Currency(x As CY)
|
---|
| 12 | cy = x
|
---|
| 13 | End Sub
|
---|
| 14 | */
|
---|
| 15 | Sub Currency(x As Double)
|
---|
| 16 | VarCyFromR8(x, cy)
|
---|
| 17 | End Sub
|
---|
| 18 | /*
|
---|
| 19 | Sub Currency(x As Int64)
|
---|
| 20 | VarCyFromI8(x, cy)
|
---|
| 21 | End Sub
|
---|
| 22 | */
|
---|
[192] | 23 | Const Function Operator +() As Currency
|
---|
| 24 | Return New Currency(This)
|
---|
| 25 | End Function
|
---|
| 26 |
|
---|
| 27 | Const Function Operator -() As Currency
|
---|
| 28 | Dim ret = New Currency
|
---|
| 29 | VarCyNeg(This.cy, ret.cy)
|
---|
| 30 | Return ret
|
---|
| 31 | End Function
|
---|
| 32 |
|
---|
| 33 | Const Function Operator *(y As Currency) As Currency
|
---|
| 34 | Dim ret = New Currency
|
---|
| 35 | VarCyMul(This.cy, y.cy, ret.cy)
|
---|
| 36 | Return ret
|
---|
| 37 | End Function
|
---|
| 38 |
|
---|
| 39 | Const Function Operator *(y As Long) As Currency
|
---|
| 40 | Dim ret = New Currency
|
---|
| 41 | VarCyMulI4(This.cy, y, ret.cy)
|
---|
| 42 | Return ret
|
---|
| 43 | End Function
|
---|
| 44 |
|
---|
| 45 | Const Function Operator *(y As Int64) As Currency
|
---|
| 46 | Dim ret = New Currency
|
---|
| 47 | VarCyMulI8(This.cy, y, ret.cy)
|
---|
| 48 | Return ret
|
---|
| 49 | End Function
|
---|
| 50 |
|
---|
| 51 | Const Function Operator /(y As Variant) As Double
|
---|
| 52 | Dim vx = New Variant(This)
|
---|
| 53 | Dim ret= vx / y
|
---|
| 54 | Return ret.ValR4
|
---|
| 55 | End Function
|
---|
| 56 |
|
---|
| 57 | Const Function Operator /(y As Currency) As Double
|
---|
| 58 | Return This / New Varinat(y)
|
---|
| 59 | End Function
|
---|
| 60 |
|
---|
| 61 | Const Function Operator +(y As Currency) As Currency
|
---|
| 62 | Dim ret = New Currency
|
---|
| 63 | VarCyAdd(This.cy, y.cy, ret.cy)
|
---|
| 64 | Return ret
|
---|
| 65 | End Function
|
---|
| 66 |
|
---|
| 67 | Const Function Operator -(y As Currency) As Currency
|
---|
| 68 | Dim ret = New Currency
|
---|
| 69 | VarCySub(This.cy, y.cy, ret.cy)
|
---|
| 70 | Return ret
|
---|
| 71 | End Function
|
---|
| 72 |
|
---|
| 73 | Const Function Abs() As Currency
|
---|
| 74 | VarCyAbs(This.cy, Abs.cy)
|
---|
| 75 | End Function
|
---|
| 76 |
|
---|
| 77 | Const Function Fix() As Currency
|
---|
| 78 | VarCyFix(This.cy, Fix.cy)
|
---|
| 79 | End Function
|
---|
| 80 |
|
---|
| 81 | Const Function Int() As Currency
|
---|
| 82 | VarCyInt(This.cy, Int.cy)
|
---|
| 83 | End Function
|
---|
| 84 |
|
---|
| 85 | Const Function Round(c = 0 As Long) As Currency
|
---|
| 86 | VarCyRound(This.cy, c, Round.cy)
|
---|
| 87 | End Function
|
---|
[200] | 88 |
|
---|
| 89 | Const Function Cy() As CY
|
---|
| 90 | Return cy
|
---|
| 91 | End Function
|
---|
| 92 |
|
---|
| 93 | Sub Cy(c As CY)
|
---|
| 94 | cy = c
|
---|
| 95 | End Sub
|
---|
| 96 |
|
---|
| 97 | Const Function ToDouble() As Double
|
---|
| 98 | VarR8FromCy(cy, ToDouble)
|
---|
| 99 | End Function
|
---|
| 100 |
|
---|
| 101 | Const Function ToInt64() As Int64
|
---|
| 102 | VarI8FromCy(cy, ToInt64)
|
---|
| 103 | End Function
|
---|
| 104 |
|
---|
| 105 | Const Function ToVariant() As Variant
|
---|
| 106 | Return New Variant(This)
|
---|
| 107 | End Function
|
---|
| 108 |
|
---|
| 109 | Override Function ToString() As String
|
---|
| 110 | Dim bs As BSTR
|
---|
| 111 | VarBstrFromCy(cy, LOCALE_USER_DEFAULT, LOCALE_USE_NLS, bs)
|
---|
| 112 | ToString = New String(bs As PCWSTR, SysStringLen(bs) As Long)
|
---|
| 113 | SysFreeString(bs)
|
---|
| 114 | End Function
|
---|
| 115 |
|
---|
| 116 | Override Function GetHashCode() As Long
|
---|
| 117 | Return HIDWORD(cy) Xor LODWORD(cy)
|
---|
| 118 | End Function
|
---|
[192] | 119 | Private
|
---|
| 120 | cy As CY
|
---|
| 121 | End Class
|
---|
[200] | 122 |
|
---|
| 123 | #endif '_COM_CURRENCY_AB
|
---|