source: Include/com/currency.ab@ 208

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

[207]参照型変数のNothing初期化に対応する修正

File size: 4.6 KB
Line 
1' com/currency.ab
2
3#require <com/variant.ab>
4
5#ifndef _COM_CURRENCY_AB
6#define _COM_CURRENCY_AB
7
8Class Currency
9Public
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*/
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 Static Function Compare(x As Currency, y As Currency) As HRESULT
74 Return VarCyCmp(x, y)
75 End Function
76
77 Static Function Compare(x As Currency, y As Double) As HRESULT
78 Return VarCyCmpR8(x, y)
79 End Function
80
81 Static Function Compare(x As Double, y As Currency) As HRESULT
82 Dim ret = VarCyCmpR8(y, x)
83 Select Case ret
84 Case VARCMP_LT
85 Return VARCMP_GT
86 Case VARCMP_GT
87 Return VARCMP_LT
88 Case Else
89 Return ret
90 End Select
91 End Function
92
93 Const Function Operator ==(y As Currency) As Boolean
94 Dim c = Compare(This, y)
95 Return c = VARCMP_EQ
96 End Function
97
98 Const Function Operator ==(y As Double) As Boolean
99 Dim c = Compare(This, y)
100 Return c = VARCMP_EQ
101 End Function
102
103 Const Function Operator <>(y As Currency) As Boolean
104 Dim c = Compare(This, y)
105 Return c <> VARCMP_EQ
106 End Function
107
108 Const Function Operator <>(y As Double) As Boolean
109 Dim c = Compare(This, y)
110 Return c <> VARCMP_EQ
111 End Function
112
113 Const Function Operator <(y As Currency) As Boolean
114 Dim c = Compare(This, y)
115 Return c = VARCMP_LT
116 End Function
117
118 Const Function Operator <(y As Double) As Boolean
119 Dim c = Compare(This, y)
120 Return c = VARCMP_LT
121 End Function
122/*
123 Const Function Operator >(y As Currency) As Boolean
124 Dim c = Compare(This, y)
125 Return c = VARCMP_GT
126 End Function
127
128 Const Function Operator >(y As Double) As Boolean
129 Dim c = Compare(This, y)
130 Return c = VARCMP_GT
131 End Function
132*/
133 Const Function Operator <=(y As Currency) As Boolean
134 Dim c = Compare(This, y)
135 Return result = VARCMP_LT Or result = VARCMP_EQ
136 End Function
137
138 Const Function Operator <=(y As Double) As Boolean
139 Dim c = Compare(This, y)
140 Return result = VARCMP_LT Or result = VARCMP_EQ
141 End Function
142
143 Const Function Operator >=(y As Currency) As Boolean
144 Dim c = Compare(This, y)
145 Return result = VARCMP_GT Or result = VARCMP_EQ
146 End Function
147
148 Const Function Operator >=(y As Double) As Boolean
149 Dim c = Compare(This, y)
150 Return result = VARCMP_GT Or result = VARCMP_EQ
151 End Function
152
153 Const Function Abs() As Currency
154 Abs = New Currency
155 VarCyAbs(This.cy, Abs.cy)
156 End Function
157
158 Const Function Fix() As Currency
159 Fix = New Currency
160 VarCyFix(This.cy, Fix.cy)
161 End Function
162
163 Const Function Int() As Currency
164 Int = New Currency
165 VarCyInt(This.cy, Int.cy)
166 End Function
167
168 Const Function Round(c = 0 As Long) As Currency
169 Round = New Currency
170 VarCyRound(This.cy, c, Round.cy)
171 End Function
172
173 Const Function Cy() As CY
174 Return cy
175 End Function
176
177 Sub Cy(c As CY)
178 cy = c
179 End Sub
180
181 Const Function ToDouble() As Double
182 VarR8FromCy(cy, ToDouble)
183 End Function
184
185 Const Function ToInt64() As Int64
186 VarI8FromCy(cy, ToInt64)
187 End Function
188
189 Const Function ToVariant() As Variant
190 Return New Variant(This)
191 End Function
192
193 Override Function ToString() As String
194 Dim bs As BSTR
195 VarBstrFromCy(cy, LOCALE_USER_DEFAULT, LOCALE_USE_NLS, bs)
196 ToString = New String(bs As PCWSTR, SysStringLen(bs) As Long)
197 SysFreeString(bs)
198 End Function
199
200 Override Function GetHashCode() As Long
201 Return HIDWORD(cy) Xor LODWORD(cy)
202 End Function
203Private
204 cy As CY
205End Class
206
207#endif '_COM_CURRENCY_AB
Note: See TracBrowser for help on using the repository browser.