Ignore:
Timestamp:
Jun 29, 2009, 4:03:45 AM (15 years ago)
Author:
イグトランス (egtra)
Message:

最新のコンパイラに通るように修正。参照クラスのセマンティクスに合うように修正(Setter系プロパティの削除など)。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/ablib/src/com/currency.ab

    r478 r709  
    77
    88Class Currency
     9    Implements System.ICloneable, System.IEquatable<Currency>', System.IComparable<Currency>
    910Public
    1011    Sub Currency()
    1112        cy = 0
    1213    End Sub
    13 
    1414/*
    1515    Sub Currency(x As CY)
     
    2525    End Sub
    2626*/
    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
    5761        Dim vx = New Variant(This)
    5862        Dim ret = vx / y
     
    6064    End Function
    6165
    62     Const Function Operator /(y As Currency) As Double
     66    Function Operator /(y As Currency) As Double
    6367        Dim vx = New Variant(This)
    6468        Dim vy = New Variant(y)
     
    6771    End Function
    6872
    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)
     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))
    7882        Return ret
    7983    End Function
     
    99103    End Function
    100104
    101     Const Function Operator ==(y As Currency) As Boolean
     105    Function Operator ==(y As Currency) As Boolean
    102106        Dim c = Compare(This, y)
    103107        Return c = VARCMP_EQ
    104108    End Function
    105109
    106     Const Function Operator ==(y As Double) As Boolean
     110    Function Operator ==(y As Double) As Boolean
    107111        Dim c = Compare(This, y)
    108112        Return c = VARCMP_EQ
    109113    End Function
    110114
    111     Const Function Operator <>(y As Currency) As Boolean
     115    Function Operator <>(y As Currency) As Boolean
    112116        Dim c = Compare(This, y)
    113117        Return c <> VARCMP_EQ
    114118    End Function
    115119
    116     Const Function Operator <>(y As Double) As Boolean
     120    Function Operator <>(y As Double) As Boolean
    117121        Dim c = Compare(This, y)
    118122        Return c <> VARCMP_EQ
    119123    End Function
    120124
    121     Const Function Operator <(y As Currency) As Boolean
     125    Function Operator <(y As Currency) As Boolean
    122126        Dim c = Compare(This, y)
    123127        Return c = VARCMP_LT
    124128    End Function
    125129
    126     Const Function Operator <(y As Double) As Boolean
     130    Function Operator <(y As Double) As Boolean
    127131        Dim c = Compare(This, y)
    128132        Return c = VARCMP_LT
    129133    End Function
    130134
    131     Const Function Operator >(y As Currency) As Boolean
     135    Function Operator >(y As Currency) As Boolean
    132136        Dim c = Compare(This, y)
    133137        Return c = VARCMP_GT
    134138    End Function
    135139
    136     Const Function Operator >(y As Double) As Boolean
     140    Function Operator >(y As Double) As Boolean
    137141        Dim c = Compare(This, y)
    138142        Return c = VARCMP_GT
    139143    End Function
    140144
    141     Const Function Operator <=(y As Currency) As Boolean
     145    Function Operator <=(y As Currency) As Boolean
    142146        Dim c = Compare(This, y)
    143147        Return c = VARCMP_LT Or c = VARCMP_EQ
    144148    End Function
    145149
    146     Const Function Operator <=(y As Double) As Boolean
     150    Function Operator <=(y As Double) As Boolean
    147151        Dim c = Compare(This, y)
    148152        Return c = VARCMP_LT Or c = VARCMP_EQ
    149153    End Function
    150154
    151     Const Function Operator >=(y As Currency) As Boolean
     155    Function Operator >=(y As Currency) As Boolean
    152156        Dim c = Compare(This, y)
    153157        Return c = VARCMP_GT Or c = VARCMP_EQ
    154158    End Function
    155159
    156     Const Function Operator >=(y As Double) As Boolean
     160    Function Operator >=(y As Double) As Boolean
    157161        Dim c = Compare(This, y)
    158162        Return c = VARCMP_GT Or c = VARCMP_EQ
    159163    End Function
    160164
    161     Const Function Abs() As Currency
     165    Function Abs() As Currency
    162166        Abs = New Currency
    163         VarCyAbs(This.cy, Abs.cy)
    164     End Function
    165 
    166     Const Function Fix() As Currency
     167        Windows.ThrowIfFailed(VarCyAbs(This.cy, Abs.cy))
     168    End Function
     169
     170    Function Fix() As Currency
    167171        Fix = New Currency
    168         VarCyFix(This.cy, Fix.cy)
    169     End Function
    170 
    171     Const Function Int() As Currency
     172        Windows.ThrowIfFailed(VarCyFix(This.cy, Fix.cy))
     173    End Function
     174
     175    Function Int() As Currency
    172176        Int = New Currency
    173         VarCyInt(This.cy, Int.cy)
    174     End Function
    175 
    176     Const Function Round(c = 0 As Long) As Currency
     177        Windows.ThrowIfFailed(VarCyInt(This.cy, Int.cy))
     178    End Function
     179
     180    Function Round(c = 0 As Long) As Currency
    177181        Round = New Currency
    178         VarCyRound(This.cy, c, Round.cy)
    179     End Function
    180 
    181     Const Function Cy() As CY
     182        Windows.ThrowIfFailed(VarCyRound(This.cy, c, Round.cy))
     183    End Function
     184
     185    Function Cy() As CY
    182186        Cy = cy
    183187    End Function
    184188
    185     Sub Cy(c As CY)
    186         cy = c
    187     End Sub
    188 
    189     Const Function ToDouble() As Double
     189    Function ToDouble() As Double
    190190        VarR8FromCy(cy, ToDouble)
    191191    End Function
    192192
    193     Const Function ToInt64() As Int64
     193    Function ToInt64() As Int64
    194194        VarI8FromCy(cy, ToInt64)
    195195    End Function
    196196
    197     Const Function ToVariant() As Variant
     197    Function ToVariant() As Variant
    198198        Return New Variant(This)
    199199    End Function
    200200
    201201    Override Function ToString() As String
    202         /*Using*/ Dim bstr = New BString
     202        Using bstr = New BString
    203203            Dim bs As BSTR
    204204            VarBstrFromCy(cy, LOCALE_USER_DEFAULT, LOCALE_USE_NLS, bs)
    205205            bstr.Attach(bs)
    206             ToString = bstr.ToString
    207         bstr.Dispose() 'End Using
     206            ToString = bstr.ToString()
     207        End Using
    208208    End Function
    209209
    210210    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
    212220    End Function
    213221
     
    215223        Dim c = Compare(This, y)
    216224        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
    217240    End Function
    218241Private
Note: See TracChangeset for help on using the changeset viewer.