Changeset 268 for Include/Classes/System


Ignore:
Timestamp:
Jun 2, 2007, 7:04:19 PM (17 years ago)
Author:
イグトランス (egtra)
Message:

StringのResizeを呼ぶコンストラクタでメモリ確保されない場合を排除、ほか微修正

Location:
Include/Classes/System
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • Include/Classes/System/DateTime.ab

    r263 r268  
    5252
    5353    'Copy Constructor
    54     Sub DateTime(ByRef dateTime As DateTime)
     54    Sub DateTime(dateTime As DateTime)
    5555        This.m_Date = dateTime.m_Date
    5656    End Sub
     
    5959    End Sub
    6060
    61     Function Operator + (ByRef value As TimeSpan) As DateTime
     61    Function Operator + (value As TimeSpan) As DateTime
    6262        Return New DateTime(Ticks + value.Ticks)
    6363    End Function
    6464
    65     Function Operator - (ByRef value As DateTime) As TimeSpan
     65    Function Operator - (value As DateTime) As TimeSpan
    6666        Return TimeSpan.FromTicks(Ticks - value.Ticks)
    6767    End Function
    6868
    69     Function Operator - (ByRef value As TimeSpan) As DateTime
     69    Function Operator - (value As TimeSpan) As DateTime
    7070        Return New DateTime(Ticks - value.Ticks)
    7171    End Function
    7272
    73     Function Operator == (ByRef value As DateTime) As Boolean
     73    Function Operator == (value As DateTime) As Boolean
    7474        Return Equals(value)
    7575    End Function
    7676
    77     Function Operator <> (ByRef value As DateTime) As Boolean
     77    Function Operator <> (value As DateTime) As Boolean
    7878        Return Not Equals(value)
    7979    End Function
    8080
    81     Function Operator > (ByRef value As DateTime) As Boolean
     81    Function Operator > (value As DateTime) As Boolean
    8282        If DateTime.Compare(This, value) > 0 Then
    8383            Return True
     
    8787    End Function
    8888
    89     Function Operator < (ByRef value As DateTime) As Boolean
     89    Function Operator < (value As DateTime) As Boolean
    9090        If DateTime.Compare(This, value) < 0 Then
    9191            Return True
     
    9595    End Function
    9696
    97     Function Operator >= (ByRef value As DateTime) As Boolean
     97    Function Operator >= (value As DateTime) As Boolean
    9898        If DateTime.Compare(This, value) => 0 Then
    9999            Return True
     
    103103    End Function
    104104
    105     Function Operator <= (ByRef value As DateTime) As Boolean
     105    Function Operator <= (value As DateTime) As Boolean
    106106        If DateTime.Compare(This, value) <= 0 Then
    107107            Return True
     
    191191       
    192192    'Public Methods
    193     Static Function Compare(ByRef t1 As DateTime, ByRef t2 As DateTime) As Int64
     193    Static Function Compare(t1 As DateTime, t2 As DateTime) As Int64
    194194        Return t1.Ticks - t2.Ticks
    195195    End Function
    196196
    197     Function Equals(ByRef value As DateTime) As Boolean
     197    Function Equals(value As DateTime) As Boolean
    198198        If value.m_Date = m_Date Then
    199199            Return True
     
    203203    End Function
    204204
    205     Static Function Equals(ByRef t1 As DateTime, ByRef t2 As DateTime) As Boolean
     205    Static Function Equals(t1 As DateTime, t2 As DateTime) As Boolean
    206206        If t1.m_Date = t2.m_Date Then
    207207            Return True
     
    215215    End Function
    216216
    217     Function Add(ByRef value As TimeSpan) As DateTime
     217    Function Add(value As TimeSpan) As DateTime
    218218        Return This + value
    219219    End Function
     
    259259    End Function
    260260
    261     Function Subtract(ByRef value As DateTime) As TimeSpan
    262         Return New DateTime(This - value)
    263     End Function
    264 
    265     Function Subtract(ByRef value As TimeSpan) As DateTime
    266         Return New DateTime(This - value)
     261    Function Subtract(value As DateTime) As TimeSpan
     262        Return This - value
     263    End Function
     264
     265    Function Subtract(value As TimeSpan) As DateTime
     266        Return This - value
    267267    End Function
    268268
  • Include/Classes/System/Environment.ab

    r258 r268  
    33#require <api_psapi.sbp>
    44#require <Classes/System/OperatingSystem.ab>
     5#require <Classes/ActiveBasic/Windows/index.ab>
     6
     7Declare Function _System_SetEnvironmentVariable Lib "kernel32" Alias _FuncName_SetEnvironmentVariable (lpName As LPCTSTR, lpValue As LPTSTR) As BOOL
     8Declare Function _System_GetEnvironmentVariable Lib "kernel32" Alias _FuncName_GetEnvironmentVariable (lpName As PCTSTR, lpBuffer As PTSTR, nSize As DWord) As DWord
    59
    610Namespace System
     
    812Namespace Detail
    913    TypeDef PFNGetProcessMemoryInfo = *Function(Process As HANDLE, ByRef mc As PROCESS_MEMORY_COUNTERS, cb As DWord) As BOOL
     14
     15    Dim hasShutdownStarted As Boolean
    1016End Namespace
    1117
     
    4854
    4955    Static Function HasShutdownStarted() As Boolean
    50         Return False
     56        Return Detail.hasShutdownStarted
    5157    End Function
    5258
     
    5965        End If
    6066        Return machineName
    61     End Function           
     67    End Function
    6268
    6369    Static Function NewLine() As String
     
    9298            sysDir = New String(p, len As Long)
    9399            _System_free(p)
    94         End IF
     100        End If
    95101        Return sysDir
    96102    End Function
     
    112118        End If
    113119        Return userName
    114     End Function           
     120    End Function
    115121
    116122    ' Version
     
    126132            If pGetProcessMemoryInfo(GetCurrentProcess(), mc, Len (mc)) <> FALSE Then
    127133                WorkingSet = mc.WorkingSetSize
    128                
    129134            End If
    130135        End If
     
    154159    ' GetCommandLineArgs
    155160
    156     ' GetEnvironmentVariable
     161    Static Function GetEnvironmentVariable(variable As String) As String
     162        Dim tcsVariable = ToTCStr(variable)
     163        Dim size = _System_GetEnvironmentVariable(tcsVariable, 0, 0)
     164        Dim p = _System_malloc(SizeOf (TCHAR) * size) As PTSTR
     165        Dim len = _System_GetEnvironmentVariable(tcsVariable, p, size)
     166        GetEnvironmentVariable = New String(p, len As Long)
     167        _System_free(p)
     168    End Function
    157169
    158170    ' GetEnvironmentVariables
     
    169181    ' GetLogicalDrives
    170182
    171     ' SetEnvironmentVariable
     183    Static Sub SetEnvironmentVariable(variable As String, value As String)
     184        _System_SetEnvironmentVariable(ToTCStr(variable), ToTCStr(value))
     185    End Sub
    172186
    173187Private
     
    207221End Enum
    208222
    209 
    210223End Namespace 'System
  • Include/Classes/System/Math.ab

    r257 r268  
    11' Classes/System/Math.ab
     2
     3#require <Classes/ActiveBasic/Math/Math.ab>
    24
    35#ifndef __SYSTEM_MATH_AB__
    46#define __SYSTEM_MATH_AB__
     7
     8Namespace System
    59
    610Class Math
     
    5660    Static Function Acos(x As Double) As Double
    5761        If x < -1 Or x > 1 Then
    58             Acos = _System_GetNaN()
     62            Acos = ActiveBasic.Math.Detail.GetNaN()
    5963        Else
    6064            Acos = _System_HalfPI - Asin(x)
     
    6468    Static Function Asin(x As Double) As Double
    6569        If x < -1 Or x > 1 Then
    66             Asin = _System_GetNaN()
     70            Asin = ActiveBasic.Math.Detail.GetNaN()
    6771        Else
    6872            Asin = Math.Atan(x / Sqrt(1 - x * x))
     
    7175
    7276    Static Function Atan(x As Double) As Double
    73         If IsNaN(x) Then
     77        If ActiveBasic.Math.IsNaN(x) Then
    7478            Atan = x
    7579            Exit Function
    76         ElseIf IsInf(x) Then
    77             Atan = CopySign(_System_PI, x)
     80        ElseIf ActiveBasic.Math.IsInf(x) Then
     81            Atan = ActiveBasic.Math.CopySign(_System_PI, x)
    7882            Exit Function
    7983        End If
     
    113117            Atan2 = Atn(y / x)
    114118            If x < 0 Then
    115                 Atan2 += CopySign(_System_PI, y)
     119                Atan2 += ActiveBasic.Math.CopySign(_System_PI, y)
    116120            End If
    117121        End If
     
    131135
    132136    Static Function Cos(x As Double) As Double
    133         If IsNaN(x) Then
     137        If ActiveBasic.Math.IsNaN(x) Then
    134138            Return x
    135         ElseIf IsInf(x) Then
    136             Return _System_GetNaN()
     139        ElseIf ActiveBasic.Math.IsInf(x) Then
     140            Return ActiveBasic.Math.Detail.GetNaN()
    137141        End If
    138142
     
    159163
    160164    Static Function Exp(x As Double) As Double
    161         If IsNaN(x) Then
     165        If ActiveBasic.Math.IsNaN(x) Then
    162166            Return x
    163         Else If IsInf(x) Then
     167        Else If ActiveBasic.Math.IsInf(x) Then
    164168            If 0 > x Then
    165169                Return 0
     
    200204
    201205    Static Function IEEERemainder(x As Double, y As Double) As Double
    202         If y = 0 Then Return _System_GetNaN()
     206        If y = 0 Then Return ActiveBasic.Math.Detail.GetNaN()
    203207        Dim q = x / y
    204208        If q <> Int(q) Then
     
    224228    Static Function Log(x As Double) As Double
    225229        If x = 0 Then
    226             Log = _System_GetInf(True)
    227         ElseIf x < 0 Or IsNaN(x) Then
    228             Log = _System_GetNaN()
    229         ElseIf IsInf(x) Then
     230            Log = ActiveBasic.Math.Detail.GetInf(True)
     231        ElseIf x < 0 Or ActiveBasic.Math.IsNaN(x) Then
     232            Log = ActiveBasic.Math.Detail.GetNaN()
     233        ElseIf ActiveBasic.Math.IsInf(x) Then
    230234            Log = x
    231235        Else
     
    236240            SetQWord(p, m + &h0010000000000000)
    237241            x /= tmp
    238             Log = _System_LOG2 * k + _System_Log1p(x - 1)
     242            Log = _System_LOG2 * k + ActiveBasic.Math.Detail.Log1p(x - 1)
    239243        End If
    240244    End Function
     
    481485
    482486    Static Function Sin(value As Double) As Double
    483         If IsNaN(value) Then
     487        If ActiveBasic.Math.IsNaN(value) Then
    484488            Return value
    485         ElseIf IsInf(value) Then
    486             Return _System_GetNaN()
     489        ElseIf ActiveBasic.Math.IsInf(value) Then
     490            Return ActiveBasic.Math.Detail.GetNaN()
    487491            Exit Function
    488492        End If
     
    514518        Dim i As *Word, j As Long, jj As Long, k As Long
    515519        If x > 0 Then
    516             If IsInf(x) Then
     520            If ActiveBasic.Math.IsInf(x) Then
    517521                Sqrt = x
    518522            Else
     
    530534            End If
    531535        ElseIf x < 0 Then
    532             Sqrt = _System_GetNaN()
     536            Sqrt = ActiveBasic.Math.Detail.GetNaN()
    533537        Else
    534538            'x = 0 Or NaN
     
    538542
    539543    Static Function Tan(x As Double) As Double
    540         If IsNaN(x) Then
     544        If ActiveBasic.Math.IsNaN(x) Then
    541545            Tan = x
    542546            Exit Function
    543         ElseIf IsInf(x) Then
    544             Tan = _System_GetNaN()
     547        ElseIf ActiveBasic.Math.IsInf(x) Then
     548            Tan = ActiveBasic.Math.Detail.GetNaN()
    545549            Exit Function
    546550        End If
     
    554558            Return -1 / t
    555559        Else
    556             Return CopySign(_System_GetInf(FALSE), -t)
     560            Return ActiveBasic.Math.CopySign(ActiveBasic.Math.Detail.GetInf(False), -t)
    557561        End If
    558562    End Function
     
    599603End Class
    600604
     605End Namespace
     606
    601607Const _System_HalfPI = (_System_PI * 0.5)
    602608Const _System_InverseHalfPI = (2 / _System_PI) '1 / (PI / 2)
     
    604610Const _System_InverseSqrt2 = 0.70710678118654752440084436210485 '1 / (√2)
    605611
    606 
    607612#endif '__SYSTEM_MATH_AB__
  • Include/Classes/System/String.ab

    r253 r268  
    216216        Sub ReSize(allocLength As Long)
    217217            If allocLength < 0 Then Exit Sub
    218             If allocLength > m_Length Then
    219                 Dim oldLength As Long
    220                 oldLength = m_Length
    221                 If AllocStringBuffer(allocLength) <> 0 Then
     218            Dim oldLength  = m_Length
     219            If AllocStringBuffer(allocLength) <> 0 Then
     220                If allocLength > oldLength Then
    222221                    ZeroMemory(VarPtr(Chars[oldLength]), SizeOf (StrChar) * (m_Length - oldLength + 1))
     222                Else
     223                    Chars[m_Length] = 0
    223224                End If
    224             Else
    225                 m_Length = allocLength
     225            End If
     226        End Sub
     227
     228        Sub ReSize(allocLength As Long, c As StrChar)
     229            If allocLength < 0 Then Exit Sub
     230            Dim oldLength = m_Length
     231            If AllocStringBuffer(allocLength) <> 0 Then
     232                If allocLength > oldLength Then
     233                    _System_FillChar(VarPtr(Chars[oldLength]), (m_Length - oldLength) As SIZE_T, c)
     234                End If
    226235                Chars[m_Length] = 0
    227236            End If
    228         End Sub
    229 
    230         Sub ReSize(allocLength As Long, c As StrChar)
    231             If allocLength < 0 Then
    232                 Exit Sub
    233             ElseIf allocLength > m_Length Then
    234                 Dim oldLength As Long
    235                 oldLength = m_Length
    236                 If AllocStringBuffer(allocLength) <> 0 Then
    237                     Dim p = VarPtr(Chars[oldLength]) As *StrChar
    238                     Dim fillLen = m_Length - oldLength
    239                     Dim i As Long
    240                     For i = 0 To ELM(fillLen)
    241                         p[i] = c
    242                     Next
    243                 End If
    244             Else
    245                 m_Length = allocLength
    246             End If
    247             Chars[m_Length] = 0
    248237        End Sub
    249238
  • Include/Classes/System/TimeSpan.ab

    r265 r268  
    2020    End Sub
    2121
    22     Sub TimeSpan(ByRef ts As TimeSpan)
     22    Sub TimeSpan(ts As TimeSpan)
    2323        m_Time = ts.m_Time
    2424    End Sub
     
    2727    End Sub
    2828
    29     Function Operator+ (ByRef ts As TimeSpan) As TimeSpan
     29    Function Operator+ (ts As TimeSpan) As TimeSpan
    3030        Return FromTicks(m_Time + ts.m_Time)
    3131    End Function
    3232
    33     Function Operator- (ByRef ts As TimeSpan) As TimeSpan
     33    Function Operator- (ts As TimeSpan) As TimeSpan
    3434        Return FromTicks(m_Time - ts.m_Time)
    3535    End Function
     
    4343    End Function
    4444
    45     Function Operator== (ByRef ts As TimeSpan) As Boolean
     45    Function Operator== (ts As TimeSpan) As Boolean
    4646        Return Equals(ts)
    4747    End Function
    4848
    49     Function Operator<> (ByRef ts As TimeSpan) As Boolean
     49    Function Operator<> (ts As TimeSpan) As Boolean
    5050        Return Not Equals(ts)
    5151    End Function
    5252
    53     Function Operator> (ByRef ts As TimeSpan) As Boolean
     53    Function Operator> (ts As TimeSpan) As Boolean
    5454        If CompareTo(ts) > 0 Then
    5555            Return True
     
    5959    End Function
    6060
    61     Function Operator< (ByRef ts As TimeSpan) As Boolean
     61    Function Operator< (ts As TimeSpan) As Boolean
    6262        If CompareTo(ts) < 0 Then
    6363            Return True
     
    6767    End Function
    6868
    69     Function Operator>= (ByRef ts As TimeSpan) As Boolean
     69    Function Operator>= (ts As TimeSpan) As Boolean
    7070        If CompareTo(ts) => 0 Then
    7171            Return True
     
    7575    End Function
    7676
    77     Function Operator<= (ByRef ts As TimeSpan) As Boolean
     77    Function Operator<= (ts As TimeSpan) As Boolean
    7878        If CompareTo(ts) <= 0 Then
    7979            Return True
     
    128128    End Function
    129129
    130     Function Add(ByRef ts As TimeSpan) As TimeSpan
     130    Function Add(ts As TimeSpan) As TimeSpan
    131131        Return FromTicks(m_Time + ts.m_Time)
    132132    End Function
    133133
    134     Static Function Compare(ByRef ts1 As TimeSpan, ByRef ts2 As TimeSpan) As Long
     134    Static Function Compare(ts1 As TimeSpan, ts2 As TimeSpan) As Long
    135135        If ts1.m_Time < ts2.m_Time Then
    136136            Return -1
     
    142142    End Function
    143143
    144     Function CompareTo(ByRef ts As TimeSpan) As Long
     144    Function CompareTo(ts As TimeSpan) As Long
    145145        Return (m_Time - ts.m_Time) As Long
    146146    End Function
    147147
    148148    Function Duration() As TimeSpan
    149         Return FromTicks(Math.Abs(m_Time))
    150     End Function
    151 
    152     Function Equals(ByRef ts As TimeSpan) As Boolean
     149        Return FromTicks(System.Math.Abs(m_Time))
     150    End Function
     151
     152    Function Equals(ts As TimeSpan) As Boolean
    153153        Return Equals(This, ts)
    154154    End Function
    155155
    156     Static Function Equals(ByRef ts1 As TimeSpan, ByRef ts2 As TimeSpan) As Boolean
     156    Static Function Equals(ts1 As TimeSpan, ts2 As TimeSpan) As Boolean
    157157        If ts1.m_Time = ts2.m_Time Then
    158158            Return True
     
    195195    End Function
    196196
    197     Function Subtract(ByRef ts As TimeSpan) As TimeSpan
     197    Function Subtract(ts As TimeSpan) As TimeSpan
    198198        Return FromTicks(m_Time - ts.m_Time)
    199199    End Function
Note: See TracChangeset for help on using the changeset viewer.