source: trunk/Include/com/currency.ab@ 495

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

現在向けに修正(参照型のポインタの排除など)

File size: 4.8 KB
Line 
1' com/currency.ab
2
3#require <com/variant.ab>
4
5Namespace ActiveBasic
6Namespace COM
7
8Class Currency
9Public
10 Sub Currency()
11 cy = 0
12 End Sub
13
14/*
15 Sub Currency(x As CY)
16 cy = x
17 End Sub
18*/
19 Sub Currency(x As Double)
20 VarCyFromR8(x, cy)
21 End Sub
22/*
23 Sub Currency(x As Int64)
24 VarCyFromI8(x, cy)
25 End Sub
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
57 Dim vx = New Variant(This)
58 Dim ret = vx / y
59 Return ret.ValR8
60 End Function
61
62 Const Function Operator /(y As Currency) As Double
63 Dim vx = New Variant(This)
64 Dim vy = New Variant(y)
65 Dim ret = vx / vy
66 Return ret.ValR8
67 End Function
68
69 Const Function Operator +(y As Currency) As Currency
70 Dim ret = New Currency
71 VarCyAdd(This.cy, y.cy, ret.cy)
72 Return ret
73 End Function
74
75 Const Function Operator -(y As Currency) As Currency
76 Dim ret = New Currency
77 VarCySub(This.cy, y.cy, ret.cy)
78 Return ret
79 End Function
80
81 Static Function Compare(x As Currency, y As Currency) As HRESULT
82 Return VarCyCmp(x.cy, y.cy)
83 End Function
84
85 Static Function Compare(x As Currency, y As Double) As HRESULT
86 Return VarCyCmpR8(x.cy, y)
87 End Function
88
89 Static Function Compare(x As Double, y As Currency) As HRESULT
90 Dim ret = VarCyCmpR8(y.cy, x)
91 Select Case ret
92 Case VARCMP_LT
93 Return VARCMP_GT
94 Case VARCMP_GT
95 Return VARCMP_LT
96 Case Else
97 Return ret
98 End Select
99 End Function
100
101 Const Function Operator ==(y As Currency) As Boolean
102 Dim c = Compare(This, y)
103 Return c = VARCMP_EQ
104 End Function
105
106 Const Function Operator ==(y As Double) As Boolean
107 Dim c = Compare(This, y)
108 Return c = VARCMP_EQ
109 End Function
110
111 Const Function Operator <>(y As Currency) As Boolean
112 Dim c = Compare(This, y)
113 Return c <> VARCMP_EQ
114 End Function
115
116 Const Function Operator <>(y As Double) As Boolean
117 Dim c = Compare(This, y)
118 Return c <> VARCMP_EQ
119 End Function
120
121 Const Function Operator <(y As Currency) As Boolean
122 Dim c = Compare(This, y)
123 Return c = VARCMP_LT
124 End Function
125
126 Const Function Operator <(y As Double) As Boolean
127 Dim c = Compare(This, y)
128 Return c = VARCMP_LT
129 End Function
130
131 Const Function Operator >(y As Currency) As Boolean
132 Dim c = Compare(This, y)
133 Return c = VARCMP_GT
134 End Function
135
136 Const Function Operator >(y As Double) As Boolean
137 Dim c = Compare(This, y)
138 Return c = VARCMP_GT
139 End Function
140
141 Const Function Operator <=(y As Currency) As Boolean
142 Dim c = Compare(This, y)
143 Return c = VARCMP_LT Or c = VARCMP_EQ
144 End Function
145
146 Const Function Operator <=(y As Double) As Boolean
147 Dim c = Compare(This, y)
148 Return c = VARCMP_LT Or c = VARCMP_EQ
149 End Function
150
151 Const Function Operator >=(y As Currency) As Boolean
152 Dim c = Compare(This, y)
153 Return c = VARCMP_GT Or c = VARCMP_EQ
154 End Function
155
156 Const Function Operator >=(y As Double) As Boolean
157 Dim c = Compare(This, y)
158 Return c = VARCMP_GT Or c = VARCMP_EQ
159 End Function
160
161 Const Function Abs() As Currency
162 Abs = New Currency
163 VarCyAbs(This.cy, Abs.cy)
164 End Function
165
166 Const Function Fix() As Currency
167 Fix = New Currency
168 VarCyFix(This.cy, Fix.cy)
169 End Function
170
171 Const Function Int() As Currency
172 Int = New Currency
173 VarCyInt(This.cy, Int.cy)
174 End Function
175
176 Const Function Round(c = 0 As Long) As Currency
177 Round = New Currency
178 VarCyRound(This.cy, c, Round.cy)
179 End Function
180
181 Const Function Cy() As CY
182 Cy = cy
183 End Function
184
185 Sub Cy(c As CY)
186 cy = c
187 End Sub
188
189 Const Function ToDouble() As Double
190 VarR8FromCy(cy, ToDouble)
191 End Function
192
193 Const Function ToInt64() As Int64
194 VarI8FromCy(cy, ToInt64)
195 End Function
196
197 Const Function ToVariant() As Variant
198 Return New Variant(This)
199 End Function
200
201 Override Function ToString() As String
202 /*Using*/ Dim bstr = New BString
203 Dim bs As BSTR
204 VarBstrFromCy(cy, LOCALE_USER_DEFAULT, LOCALE_USE_NLS, bs)
205 bstr.Attach(bs)
206 ToString = bstr.ToString
207 bstr.Dispose() 'End Using
208 End Function
209
210 Override Function GetHashCode() As Long
211 Return HIDWORD(cy) Xor LODWORD(cy)
212 End Function
213
214 Function Equals(y As Currency) As Boolean
215 Dim c = Compare(This, y)
216 Return c = VARCMP_EQ
217 End Function
218Private
219 cy As CY
220End Class
221
222End Namespace 'COM
223End Namespace 'ActiveBasic
Note: See TracBrowser for help on using the repository browser.