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

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

COM関係を名前空間に入れた

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