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/decimal.ab

    r478 r709  
    88
    99Class Decimal
     10    Implements System.ICloneable, System.IEquatable<Decimal>', System.IComparable<Decimal>
    1011Public
     12
    1113    Sub Decimal()
    1214    End Sub
     
    2224    Sub Decimal(lo As Long, mid As Long, hi As Long, isNegative As Boolean, scale As Byte)
    2325        If scale > 28 Then
    24             Throw New ArgumentOutOfRangeException("scale")
     26            Throw New System.ArgumentOutOfRangeException("scale - Decimal constructor")
    2527        End If
    2628        Dim sign As Byte
     
    3638
    3739    Sub Decimal(x As Long)
    38         VarDecFromI4(x, dec)
     40        Windows.ThrowIfFailed(VarDecFromI4(x, dec))
    3941    End Sub
    4042
    4143    Sub Decimal(x As DWord)
    42         VarDecFromUI4(x, dec)
     44        Windows.ThrowIfFailed(VarDecFromUI4(x, dec))
    4345    End Sub
    4446
    4547    Sub Decimal(x As Int64)
    46         VarDecFromI8(x, dec)
     48        Windows.ThrowIfFailed(VarDecFromI8(x, dec))
    4749    End Sub
    4850
    4951    Sub Decimal(x As QWord)
    50         VarDecFromUI8(x, dec)
     52        Windows.ThrowIfFailed(VarDecFromUI8(x, dec))
    5153    End Sub
    5254
    5355    Sub Decimal(x As Single)
    54         VarDecFromR4(x, dec)
     56        Windows.ThrowIfFailed(VarDecFromR4(x, dec))
    5557    End Sub
    5658
    5759    Sub Decimal(x As Double)
    58         VarDecFromR8(x, dec)
    59     End Sub
    60 /*
     60        Windows.ThrowIfFailed(VarDecFromR8(x, dec))
     61    End Sub
     62
    6163    Const Function Operator() As Variant
    6264        Return New Variant(This)
     
    197199    End Function
    198200*/
    199 /*
     201
    200202    Const Function Operator +() As Decimal
    201203        Return New Decimal(dec)
    202204    End Function
    203 */
     205
    204206    Const Function Operator -() As Decimal
    205207        Dim ret = New Decimal
    206         VarDecNeg(This.dec, ret.dec)
     208        Windows.ThrowIfFailed(VarDecNeg(This.dec, ret.dec))
    207209        Return ret
    208210    End Function
     
    210212    Const Function Operator *(y As Decimal) As Decimal
    211213        Dim ret = New Decimal
    212         VarDecMul(This.dec, y.dec, ret.dec)
     214        Windows.ThrowIfFailed(VarDecMul(This.dec, y.dec, ret.dec))
    213215        Return ret
    214216    End Function
     
    216218    Const Function Operator /(y As Decimal) As Decimal
    217219        Dim ret = New Decimal
    218         VarDecDiv(This.dec, y.dec, ret.dec)
     220        Windows.ThrowIfFailed(VarDecDiv(This.dec, y.dec, ret.dec))
    219221        Return ret
    220222    End Function
     
    222224    Const Function Operator +(y As Decimal) As Decimal
    223225        Dim ret = New Decimal
    224         VarDecAdd(This.dec, y.dec, ret.dec)
     226        Windows.ThrowIfFailed(VarDecAdd(This.dec, y.dec, ret.dec))
    225227        Return ret
    226228    End Function
     
    228230    Const Function Operator -(y As Decimal) As Decimal
    229231        Dim ret = New Decimal
    230         VarDecSub(This.dec, y.dec, ret.dec)
    231         Return ret
    232     End Function
    233 
     232        Windows.ThrowIfFailed(VarDecSub(This.dec, y.dec, ret.dec))
     233        Return ret
     234    End Function
     235
     236    ' ThrowIfFailedしていないことに注意
    234237    Static Function Compare(x As Decimal, y As Decimal) As HRESULT
    235         Return VarDecCmp(x.dec, y.dec)
    236     End Function
    237 
     238        Compare = VarDecCmp(x.dec, y.dec)
     239    End Function
     240
     241    ' ThrowIfFailedしていないことに注意
    238242    Static Function Compare(x As Decimal, y As Double) As HRESULT
    239243        Return VarDecCmpR8(x.dec, y)
     
    314318    Const Function Abs() As Decimal
    315319        Abs = New Decimal
    316         VarDecAbs(This.dec, Abs.dec)
     320        Windows.ThrowIfFailed(VarDecAbs(This.dec, Abs.dec))
    317321    End Function
    318322
    319323    Const Function Fix() As Decimal
    320324        Fix = New Decimal
    321         VarDecFix(This.dec, Fix.dec)
     325        Windows.ThrowIfFailed(VarDecFix(This.dec, Fix.dec))
    322326    End Function
    323327
    324328    Const Function Int() As Decimal
    325329        Int = New Decimal
    326         VarDecInt(This.dec, Int.dec)
     330        Windows.ThrowIfFailed(VarDecInt(This.dec, Int.dec))
    327331    End Function
    328332
    329333    Const Function Round(c = 0 As Long) As Decimal
    330334        Round = New Decimal
    331         VarDecRound(This.dec, c, Round.dec)
     335        Windows.ThrowIfFailed(VarDecRound(This.dec, c, Round.dec))
    332336    End Function
    333337
     
    336340    End Function
    337341
    338     Sub Dec(ByRef d As DECIMAL)
    339         dec = d
    340     End Sub
    341 
    342342    Const Function ToVariant() As Variant
    343343        Return New Variant(This)
    344344    End Function
    345345
     346    Function ToBString() As BString
     347        ToBString = New BString
     348        Dim bs As BSTR
     349        VarBstrFromDec(dec, LOCALE_USER_DEFAULT, LOCALE_USE_NLS, bs)
     350        ToBString.Attach(bs)
     351    End Function
     352
    346353    Override Function ToString() As String
    347         /*Using*/ Dim bstr = New BString
    348             Dim bs As BSTR
    349             VarBstrFromDec(dec, LOCALE_USER_DEFAULT, LOCALE_USE_NLS, bs)
    350             bstr.Attach(bs)
     354        Using bstr = ToBString()
    351355            ToString = bstr.ToString
    352         bstr.Dispose() 'End Using
     356        End Using
    353357    End Function
    354358
     
    362366        Return c = VARCMP_EQ
    363367    End Function
     368
     369    Override Function Equals(y As Object) As Boolean
     370        If This.GetType().Equals(y.GetType()) Then
     371            Equals = Equals(y As Decimal)
     372        End If
     373    End Function
     374
     375    Function Clone() As Decimal
     376        Clone = New Decimal(This)
     377    End Function
     378
    364379Private
    365380    dec As DECIMAL
Note: See TracChangeset for help on using the changeset viewer.