Changeset 400 for trunk/Include/Classes


Ignore:
Timestamp:
Jan 22, 2008, 9:19:59 PM (17 years ago)
Author:
イグトランス (egtra)
Message:

_System_CThreadCollectionでのクラスインスタンスへのポインタの使用を除去、参照変数構文へ。

Location:
trunk/Include/Classes
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Include/Classes/ActiveBasic/CType/CType.ab

    r388 r400  
    8686End Function
    8787
     88/*!
     89@brief  ASCIIの表示文字かどうか
     90@author Egtra
     91@date   2007/11/25
     92制御文字でないもの、空白も表示文字に含む
     93*/
    8894Function IsPrint(c As WCHAR) As Boolean
    8995    Return (c As DWord - &h20) < (&h7e - &h20)
     
    98104Function IsPunct(c As WCHAR) As Boolean
    99105    Return c < &h7f And IsGraph(c) And (Not IsAlnum(c))
     106End Function
     107
     108/*!
     109@brief  ASCIIの空白文字かどうか
     110@author Egtra
     111@date   2008/01/22
     112*/
     113Function IsSpace(c As WCHAR) As Boolean
     114    Return c As DWord - 9 < 4 Or c = &h20 ' &h41 = Asc("A")
    100115End Function
    101116
     
    210225@overload
    211226*/
     227Function IsSpace(c As CHAR) As Boolean
     228    Return IsSpace(Detail.Widen(c))
     229End Function
     230
     231/*!
     232@overload
     233*/
    212234Function IsUpper(c As CHAR) As Boolean
    213235    Return IsUpper(Detail.Widen(c))
     
    235257End Function
    236258
    237 End Namespace
    238 End Namespace
     259End Namespace 'CType
     260End Namespace 'ActiveBasic
  • trunk/Include/Classes/ActiveBasic/Core/TypeInfo.ab

    r367 r400  
    160160
    161161    Static Sub InitializeValueType()
    162         types = New System.Collections.Generic.Dictionary<String, TypeBaseImpl>(8192)
     162        types = New System.Collections.Generic.Dictionary<String, TypeBaseImpl>(8191)
    163163
    164164        ' 値型の追加
     
    222222        End If
    223223
    224         If Object.ReferenceEquals( types.Item(fullName), Nothing ) Then
    225             OutputDebugString( "TypeSearch Failed: " )
    226             OutputDebugString( fullName )
    227             OutputDebugString( Ex"\r\n" )
     224        Search = types.Item(fullName)
     225
     226        If Object.ReferenceEquals( Search, Nothing ) Then
     227            OutputDebugString("TypeSearch Failed: ")
     228            If Not ActiveBasic.IsNothing(fullName) Then
     229                OutputDebugStringW(StrPtr(fullName) As PWSTR)
     230                OutputDebugString(Ex"\r\n")
     231                OutputDebugStringA(StrPtr(fullName) As PSTR)
     232            End If
     233            OutputDebugString(Ex"\r\n")
    228234        End If
    229 
    230         Return types.Item(fullName)
    231235    End Function
    232236
  • trunk/Include/Classes/ActiveBasic/Strings/SPrintF.ab

    r391 r400  
    10721072        ReadInt = True
    10731073    Else
    1074         Dim p As PSTR
     1074        Dim p As *StrChar
    10751075        ret = StrToLong(fmt, p)
    10761076        If fmt <> p Then
  • trunk/Include/Classes/ActiveBasic/misc.ab

    r385 r400  
    22
    33Namespace ActiveBasic
     4    Namespace Detail
     5        /*!
     6        @brief baseがderivedの基底クラスかどうか判定する。
     7        @param[in] base 基底クラス
     8        @param[in] derived 派生クラス
     9        @retval True baseがderivedの基底クラスである
     10        @retval False 基底クラスでない
     11        @exception ArgumentNullException 引数のどちらか又は双方がNoghing
     12        @auther Egtra
     13        @date 2008/01/21
     14        */
     15        Function IsBaseOf(base As System.TypeInfo, derived As System.TypeInfo) As Boolean
     16            Imports System
     17            If IsNothing(base) Then
     18                Throw New ArgumentNullException("base")
     19            ElseIf IsNothing(derived) Then
     20                Throw New ArgumentNullException("derived")
     21            End If
     22            Do
     23                IsBaseOf = derived.Equals(base)
     24                If IsBaseOf Then
     25                    Exit Function
     26                End If
     27                derived = derived.BaseType
     28            Loop Until IsNothing(derived)
     29        End Function
     30    End Namespace
     31
    432    Function IsNothing(o As Object) As Boolean
    533        Return Object.ReferenceEquals(o, Nothing)
  • trunk/Include/Classes/System/DateTime.ab

    r370 r400  
    296296        Dim dateTimeFormats = GC_malloc_atomic(SizeOf (TCHAR) * (strLength)) As PTSTR
    297297        GetDateFormat(LOCALE_USER_DEFAULT, 0, time, NULL, dateTimeFormats, dateFormatSize)
    298         dateTimeFormats[dateFormatSize - 1] = Asc(" ")
     298        dateTimeFormats[dateFormatSize - 1] = &H20 As TCHAR 'Asc(" ") As TCHAR
    299299        GetTimeFormat(LOCALE_USER_DEFAULT, 0, time, NULL, dateTimeFormats + dateFormatSize, timeFormatSize)
    300300'Debug
  • trunk/Include/Classes/System/IO/DriveInfo.ab

    r288 r400  
    2121            debug
    2222        End If
    23         driveName.ToUpper()
    24         m_DriveName = driveName + ":\"
     23        m_DriveName = driveName.ToUpper() + ":\"
    2524    End Sub
    2625
     
    3029    'property
    3130    Function AvailableFreeSpace() As QWord
    32         Dim availableFreeSpace As ULARGE_INTEGER
    33         If GetDiskFreeSpaceEx(m_DriveName, availableFreeSpace, ByVal 0, ByVal 0) Then
    34             Return (availableFreeSpace.HighPart << 32) Or availableFreeSpace.LowPart
    35         Else
    36             'IOException
     31        If GetDiskFreeSpaceEx(ToTCStr(m_DriveName), ByVal VarPtr(AvailableFreeSpace) As *ULARGE_INTEGER, ByVal 0, ByVal 0) = FALSE Then
     32            Throw New IOException("DriveInfo.AvailableFreeSpace: Failed to GetDiskFreeSpaceEx.")
    3733        End If
    3834    End Function
     
    4036    Function DriveFormat() As String
    4137        Dim systemName[15] As TCHAR
    42         If GetVolumeInformation(m_DriveName, NULL, 0, NULL, NULL, NULL, systemName, Len (systemName)) Then
    43             Dim resultStr = New String( systemName )
    44             Return resultStr
     38        If GetVolumeInformation(ToTCStr(m_DriveName), NULL, 0, NULL, NULL, NULL, systemName, Len (systemName) \ SizeOf (TCHAR)) Then
     39            DriveFormat = New String( systemName )
    4540        Else
    46             'IOException
     41            Throw New IOException("DriveInfo.DriveFormat: Failed to GetVolumeInformation.")
    4742        End If
    4843    End Function
    4944
    5045    Function DriveType() As Long
    51         Return GetDriveType(m_DriveName)
     46        Return GetDriveType(ToTCStr(m_DriveName))
    5247    End Function
    5348
    5449    Function IsReady() As Boolean
    55         If GetVolumeInformation(m_DriveName, NULL, 0, NULL, NULL, NULL, NULL, 0) Then
     50        If GetVolumeInformation(ToTCStr(m_DriveName), NULL, 0, NULL, NULL, NULL, NULL, 0) Then
    5651            Return True
    5752        Else
     
    6863
    6964    Function TotalFreeSpace() As QWord
    70         Dim totalFreeSpace As ULARGE_INTEGER
    71         If GetDiskFreeSpaceEx(m_DriveName, ByVal 0, ByVal 0, totalFreeSpace) Then
    72             Return (totalFreeSpace.HighPart << 32) Or totalFreeSpace.LowPart
    73         Else
    74             'IOException
     65        If GetDiskFreeSpaceEx(ToTCStr(m_DriveName), ByVal 0, ByVal 0, ByVal VarPtr(TotalFreeSpace) As *ULARGE_INTEGER) = FALSE Then
     66            Throw New IOException("DriveInfo.TotalFreeSpace: Failed to GetDiskFreeSpaceEx.")
    7567        End If
    7668    End Function
    7769
    7870    Function TotalSize() As QWord
    79         Dim totalSize As ULARGE_INTEGER
    80         If GetDiskFreeSpaceEx(m_DriveName, ByVal 0, totalSize, ByVal 0) Then
    81             Return (totalSize.HighPart << 32) Or totalSize.LowPart
    82         Else
    83             'IOException
     71        If GetDiskFreeSpaceEx(ToTCStr(m_DriveName), ByVal 0, ByVal VarPtr(TotalSize) As *ULARGE_INTEGER, ByVal 0) = FALSE Then
     72            Throw New IOException("DriveInfo.TotalSize: Failed to GetDiskFreeSpaceEx.")
    8473        End If
    8574    End Function
     
    8776    Function VolumeLabel() As String
    8877        Dim volumeName[63] As TCHAR
    89         If GetVolumeInformation(m_DriveName, volumeName, 64, NULL, NULL, NULL, NULL, 0) Then
    90             Dim resultStr = New String( volumeName )
    91             Return resultStr
     78        If GetVolumeInformation(ToTCStr(m_DriveName), volumeName, Len (volumeName) \ SizeOf (TCHAR), NULL, NULL, NULL, NULL, 0) Then
     79            VolumeLabel = New String( volumeName )
    9280        Else
    93             'IOException
     81            Throw New IOException("DriveInfo.VolumeLabel: Failed to GetVolumeInformation.")
    9482        End If
    9583    End Function
  • trunk/Include/Classes/System/IO/FileSystemInfo.ab

    r346 r400  
    4040
    4141    Sub Attributes(value As DWord)
    42         If SetFileAttributes(FullPath, value) = FALSE Then
     42        If SetFileAttributes(ToTCStr(FullPath), value) = FALSE Then
    4343            'Exception
    4444            Debug
     
    123123    'Public Methods
    124124    Virtual Sub Delete()
    125         If DeleteFile(FullPath) = FALSE Then
     125        If DeleteFile(ToTCStr(FullPath)) = FALSE Then
    126126            'Exception
    127127            debug
  • trunk/Include/Classes/System/String.ab

    r391 r400  
    311311                Concat = New String
    312312                .AllocStringBuffer(m_Length + lenW)
    313                 ActiveBasic.Strings.ChrCopy(.Chars, This.Chars, m_Length)
     313                ActiveBasic.Strings.ChrCopy(.Chars, This.Chars, m_Length As SIZE_T)
    314314                MultiByteToWideChar(CP_THREAD_ACP, 0, text, len, VarPtr(.Chars[m_Length]), lenW)
    315315                .Chars[m_Length + lenW] = 0
  • trunk/Include/Classes/System/Threading/Thread.ab

    r374 r400  
    1 'threading.sbp
    2 
     1'Thread.ab
    32
    43'--------------------------------------------------------------------
     
    115114    End Sub
    116115
    117 
    118 
    119 
    120 
    121116    Sub Start()
    122117        Dim ThreadId As DWord
     
    133128
    134129        'GCにスレッド開始を通知
    135         _System_pobj_AllThreads->BeginThread(VarPtr(This),_System_GetSp() As *LONG_PTR)
     130        _System_pobj_AllThreads->BeginThread(This, _System_GetSp() As *LONG_PTR)
    136131
    137132
     
    147142
    148143        'GCにスレッド終了を通知
    149         _System_pobj_AllThreads->EndThread(VarPtr(This))
     144        _System_pobj_AllThreads->EndThread(This)
    150145
    151146        '自身のスレッドハンドルを閉じる
     
    201196End Class
    202197
     198Dim _System_pobj_AllThreads As *Detail._System_CThreadCollection
     199
     200Namespace Detail
    203201
    204202'--------------------------------------------------------------------
     
    206204'--------------------------------------------------------------------
    207205' TODO: このクラスをシングルトンにする
     206
    208207Class _System_CThreadCollection
    209208Public
    210     ppobj_Thread As **Thread
    211     pStackBase As **LONG_PTR
     209    collection As *ThreadInfo
    212210    ThreadNum As Long
    213211
     
    215213
    216214    Sub _System_CThreadCollection()
    217         ppobj_Thread=GC_malloc(1)
    218         pStackBase=HeapAlloc(_System_hProcessHeap,0,1)
    219         ppException=HeapAlloc(_System_hProcessHeap,0,1)
    220         ThreadNum=0
    221 
    222         'クリティカルセッションを生成
     215        collection = GC_malloc(1)
     216        ThreadNum = 0
    223217        InitializeCriticalSection(CriticalSection)
    224218    End Sub
     
    227221        Dim i As Long
    228222        For i=0 To ELM(ThreadNum)
    229             If ppobj_Thread[i] Then
    230                 If i = 0 Then
    231                     Delete ppobj_Thread[i]
    232                 End If
    233                 ppobj_Thread[i]=0
    234                 pStackBase[i]=0
    235                 Delete ppException[i]
    236                 ppException[i]=0
    237                 Exit For
     223            With collection[i]
     224                If .thread Then
     225                    .thread = Nothing
     226                    .stackBase = 0
     227                    .exception = Nothing
     228                End If
     229            End With
     230        Next
     231        collection = 0
     232        DeleteCriticalSection(CriticalSection)
     233    End Sub
     234
     235    'スレッドを生成
     236    Sub BeginThread(thread As Thread, NowSp As *LONG_PTR)
     237        EnterCriticalSection(CriticalSection)
     238        Dim i = FindFreeIndex
     239        With collection[i]
     240            .thread = thread
     241            .stackBase = NowSp
     242            .exception = New ExceptionService '例外処理管理用オブジェクトを生成
     243        End With
     244        LeaveCriticalSection(CriticalSection)
     245    End Sub
     246Private
     247    'クリティカルセション内で呼ぶこと
     248    Function FindFreeIndex() As Long
     249        Dim i As Long
     250        For i = 0 To ELM(ThreadNum)
     251            If ActiveBasic.IsNothing(collection[i].thread) Then
     252                FindFreeIndex = i
     253                Exit Function
    238254            End If
    239255        Next
    240 
    241         HeapFree(_System_hProcessHeap,0,pStackBase)
    242         pStackBase=0
    243 
    244         HeapFree(_System_hProcessHeap,0,ppException)
    245         ppException = 0
    246 
    247         ThreadNum=0
    248 
    249         'クリティカルセッションを破棄
    250         DeleteCriticalSection(CriticalSection)
    251     End Sub
    252 
    253     'スレッドを生成
    254     Sub BeginThread(pThread As *Thread,NowSp As *LONG_PTR)
    255         EnterCriticalSection(CriticalSection)
    256 
    257             '例外処理管理用オブジェクトを生成
    258             Dim pException As *ExceptionService
    259             pException = New ExceptionService
    260 
    261             Dim i As Long
    262             For i=0 To ELM(ThreadNum)
    263                 If ppobj_Thread[i] = 0 Then
    264                     ppobj_Thread[i] = pThread
    265                     pStackBase[i] = NowSp
    266                     ppException[i] = pException
    267                     Exit For
    268                 End If
    269             Next
    270 
    271             If i = ThreadNum Then
    272                 ppobj_Thread=realloc(ppobj_Thread,(ThreadNum+1)*SizeOf(*Thread))
    273                 ppobj_Thread[ThreadNum]=pThread
    274                 pStackBase=HeapReAlloc(_System_hProcessHeap,0,pStackBase,(ThreadNum+1)*SizeOf(LONG_PTR))
    275                 pStackBase[ThreadNum]=NowSp
    276                 ppException=HeapReAlloc(_System_hProcessHeap,0,ppException,(ThreadNum+1)*SizeOf(*ExceptionService))
    277                 ppException[ThreadNum]=pException
    278                 ThreadNum++
    279             End If
    280         LeaveCriticalSection(CriticalSection)
    281     End Sub
     256        ThreadNum++
     257        collection = realloc(collection, ThreadNum * SizeOf(ThreadInfo))
     258        FindFreeIndex = i
     259    End Function
     260Public
    282261
    283262    'スレッドを終了
    284     Sub EndThread(pThread As *Thread)
     263    Sub EndThread(thread As Thread)
    285264        EnterCriticalSection(CriticalSection)
    286265            Dim i As Long
    287             For i=0 To ELM(ThreadNum)
    288                 If ppobj_Thread[i] = pThread Then
    289                     If i = 0 Then
    290                         Delete pThread
     266            For i = 0 To ELM(ThreadNum)
     267                With collection[i]
     268                    If thread.Equals(.thread) Then
     269                        .thread = Nothing
     270                        .stackBase = 0
     271                        .exception = Nothing
     272                        Exit For
    291273                    End If
    292                     ppobj_Thread[i]=0
    293                     pStackBase[i]=0
    294                     Delete ppException[i]
    295                     ppException[i]=0
    296                     Exit For
    297                 End If
     274                End With
    298275            Next
    299276        LeaveCriticalSection(CriticalSection)
     
    303280    Sub SuspendAllThread()
    304281        Dim i As Long
    305         For i=0 To ELM(ThreadNum)
    306             If ppobj_Thread[i] Then
    307                 ppobj_Thread[i]->Suspend()
    308             End If
     282        For i = 0 To ELM(ThreadNum)
     283            With collection[i]
     284                If Not ActiveBasic.IsNothing(.thread) Then
     285                    .thread.Suspend()
     286                End If
     287            End With
    309288        Next
    310289    End Sub
     
    313292    Sub ResumeAllThread()
    314293        Dim i As Long
    315         For i=0 To ELM(ThreadNum)
    316             If ppobj_Thread[i] Then
    317                 ppobj_Thread[i]->Resume()
    318             End If
    319         Next
    320     End Sub
    321 
     294        For i = 0 To ELM(ThreadNum)
     295            With collection[i]
     296                If Not ActiveBasic.IsNothing(.thread) Then
     297                    .thread.Resume()
     298                End If
     299            End With
     300        Next
     301    End Sub
     302/*
    322303    ' 自分以外のスレッドを中断
    323304    Sub SuspendAnotherThread()
    324         Dim currentThread = Thread.CurrentThread()
     305        Dim currentThread = CurrentThread()
    325306
    326307        Dim i As Long
    327308        For i=0 To ELM(ThreadNum)
    328 
    329             If currentThread.Equals( ppobj_Thread[i] As Object ) Then
    330                 Continue
    331             End If
    332 
    333             If ppobj_Thread[i] Then
    334                 ppobj_Thread[i]->Suspend()
    335             End If
     309            With collection[i]
     310                If currentThread.Equals(.thread) Then
     311                    Continue
     312                ElseIf Not ActiveBasic.IsNothing(.thread) Then
     313                    .thread.Suspend()
     314                End If
     315            End With
    336316        Next
    337317    End Sub
     
    339319    ' 自分以外のスレッドを再開
    340320    Sub ResumeAnotherThread()
    341         Dim currentThread = Thread.CurrentThread()
     321        Dim currentThread = CurrentThread()
    342322
    343323        Dim i As Long
    344324        For i=0 To ELM(ThreadNum)
    345 
    346             If currentThread.Equals( ppobj_Thread[i] As Object ) Then
    347                 Continue
    348             End If
    349 
    350             If ppobj_Thread[i] Then
    351                 ppobj_Thread[i]->Resume()
    352             End If
    353         Next
    354     End Sub
    355 
     325            With collection[i]
     326                If currentThread.Equals(.thread) Then
     327                    Continue
     328                ElseIf Not ActiveBasic.IsNothing(.thread) Then
     329                    .thread.Resume()
     330                End If
     331            End With
     332        Next
     333    End Sub
     334*/
    356335    'カレントスレッドを取得
    357336    Function CurrentThread() As Thread
    358         Dim dwNowThreadId As DWord
    359         dwNowThreadId=GetCurrentThreadId()
    360 
    361         Dim i As Long
    362         For i=0 To ELM(ThreadNum)
    363             If ppobj_Thread[i]->ThreadId=dwNowThreadId Then
    364                 Return ByVal ppobj_Thread[i]
     337        Dim p = CurrentThreadInfo()
     338        If p = 0 Then
     339            ' TODO: エラー処理
     340            OutputDebugString( Ex"カレントスレッドの取得に失敗\r\n" )
     341            debug
     342            Exit Function
     343        End If
     344        CurrentThread = p->thread
     345    End Function
     346
     347    Function CurrentThreadInfo() As *ThreadInfo
     348        CurrentThreadInfo = FindThreadInfo(GetCurrentThreadId())
     349    End Function
     350
     351    Function FindThreadInfo(threadID As DWord) As *ThreadInfo
     352        Dim i As Long
     353        For i = 0 To ELM(ThreadNum)
     354            If collection[i].thread.ThreadId = threadID Then
     355                FindThreadInfo = VarPtr(collection[i])
     356                Exit Function
    365357            End If
    366358        Next
    367 
    368         ' TODO: エラー処理
    369         OutputDebugString( "カレントスレッドの取得に失敗" )
    370         debug
    371     End Function
    372 
     359    End Function
    373360
    374361Private
     
    376363    ' スレッド固有の例外処理制御
    377364    '------------------------------------------
    378     ppException As **ExceptionService
    379 
    380 Public
    381     Function GetCurrentException() As *ExceptionService
    382         Dim dwNowThreadId As DWord
    383         dwNowThreadId=GetCurrentThreadId()
     365
     366Public
     367    Function GetCurrentException() As ExceptionService
     368        Dim dwNowThreadId = GetCurrentThreadId()
    384369
    385370        Dim i As Long
    386371        For i=0 To ELM(ThreadNum)
    387             If ppobj_Thread[i]->ThreadId=dwNowThreadId Then
    388                 Return ppException[i]
    389             End If
    390         Next
    391 
    392         Return NULL
     372            With collection[i]
     373                If .thread.ThreadId = dwNowThreadId Then
     374                    Return .exception
     375                End If
     376            End With
     377        Next
     378
     379        OutputDebugString( Ex"カレントスレッドの取得に失敗\r\n" )
     380        Return Nothing
    393381    End Function
    394382End Class
    395 Dim _System_pobj_AllThreads As *_System_CThreadCollection
     383
     384Type ThreadInfo
     385    thread As Thread
     386    stackBase As *LONG_PTR
     387    exception As ExceptionService
     388End Type
     389
     390End Namespace 'Detail
  • trunk/Include/Classes/System/misc.ab

    r391 r400  
    1616End Interface
    1717
    18 Interface IClonable
     18Interface ICloneable
    1919    ' Method
    2020    Function Clone() As Object
Note: See TracChangeset for help on using the changeset viewer.