Changeset 340 for trunk


Ignore:
Timestamp:
Sep 28, 2007, 3:32:25 AM (17 years ago)
Author:
dai
Message:

デリゲートを試験実装
【現状のデリゲート制約】
・ダイナミックメソッド限定
・パラメータ相違チェックは行っていない

GCHandle.allocatedメンバをListクラスに変更。
List.Removeメソッドを追加

Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Include/Classes/System/Collections/Generic/List.ab

    r305 r340  
    9797        size++
    9898    End Sub
     99
     100    /*!
     101    @brief  List内で最初に出現する値を削除する
     102    @author Daisuke Yamamoto
     103    @date   2007/09/28
     104    @return 値が削除されたときはTrue、されなかったときはFlaseが返る
     105    */
     106    Function Remove( item As T ) As Boolean
     107        Dim index = IndexOf( item )
     108        If index = -1 Then
     109            Return False
     110        End If
     111        memmove( items + index*SizeOf(VoidPtr), items + (index+1)*SizeOf(VoidPtr), (size-(index+1))*SizeOf(VoidPtr) )
     112        Realloc( size - 1 )
     113        Return True
     114    End Function
    99115End Class
    100116
  • trunk/Include/Classes/System/Delegate.ab

    r338 r340  
    11Namespace System
     2
    23
    34Class _SimpleDelegate
    45Public
     6    hasThisPtr As Boolean
    57    object As Object
    68    methodPtr As VoidPtr
    79
    810    Sub _SimpleDelegate( object As Object, methodPtr As VoidPtr )
     11        This.hasThisPtr = True
    912        This.object = object
     13        This.methodPtr = methodPtr
     14    End Sub
     15    Sub _SimpleDelegate( methodPtr As VoidPtr )
     16        This.hasThisPtr = False
     17        This.object = Nothing
    1018        This.methodPtr = methodPtr
    1119    End Sub
     
    1624    simpleDelegates As System.Collections.Generic.List<_SimpleDelegate>
    1725
     26    Sub _Add( dg As DelegateBase )
     27        Dim i As Long
     28        For i=0 To ELM(dg.simpleDelegates.Count)
     29            simpleDelegates.Add( dg.simpleDelegates[i] )
     30        Next
     31    End Sub
     32
    1833Public
    1934    Sub DelegateBase()
    2035        simpleDelegates = New System.Collections.Generic.List<_SimpleDelegate>()
    2136    End Sub
    22     Sub Add( sd As System._SimpleDelegate )
    23         simpleDelegates.Add( sd )
    24     End Sub
     37
     38/*
     39    Sub Operator + ( sd As System._SimpleDelegate )
     40        Add( sd )
     41    End Sub*/
    2542Public
    2643End Class
     
    2845
    2946End Namespace
     47
     48
     49Function _System_CreateSimpleDynamicDelegate( object As Object, methodPtr As VoidPtr ) As System._SimpleDelegate
     50    Return New System._SimpleDelegate( object, methodPtr )
     51End Function
     52Function _System_CreateSimpleStaticDelegate( methodPtr As VoidPtr ) As System._SimpleDelegate
     53    Return New System._SimpleDelegate( methodPtr )
     54End Function
  • trunk/Include/Classes/System/Runtime/InteropServices/GCHandle.ab

    r282 r340  
    11' Classes/System/Runtime/InteropServices/GCHandle.ab
    2 
    3 #require <Classes/System/Collections/ArrayList.ab>
    42
    53Namespace System
     
    6967    handle As VoidPtr
    7068
    71     Static allocated As /*System.Collections.*/ArrayList
     69    Static allocated = New System.Collections.Generic.List<Object>
    7270End Class
    7371
  • trunk/TestCase/SimpleTestCase/SimpleTestCase.idx

    r338 r340  
    2424#include "SPrintFTest.ab"
    2525_ClearNamespaceImported
     26#include "DelegateTest.ab"
     27_ClearNamespaceImported
     28
     29'リソースファイル
     30#include "resource.ab"
     31#resource "SimpleTestCase.rc"
  • trunk/TestCase/SimpleTestCase/SimpleTestCase.pj

    r338 r340  
    2323#DEBUG_EXE_PATH=
    2424
    25 #RESOURCE=0
     25#RESOURCE=SimpleTestCase.rc
    2626
    2727#SOURCE
     
    3737BlittableTest.ab
    3838SPrintFTest.ab
     39DelegateTest.ab
  • trunk/bin/SubOperation/templates/delegate_class.tab

    r338 r340  
    1 Class Delegate #name#
    2     Inherits System.DelegateBase
     1#namespace_begin#
     2    Class Delegate #name#
     3        Inherits System.DelegateBase
    34
    4 Public
    5     Sub Callback()
    6     End Sub
    7     Sub Callback( sd As System._SimpleDelegate )
    8         Add( sd )
    9     End Sub
    10     Sub Call(#params#)
    11         Dim i As Long
    12         For i = 0 To ELM(simpleDelegates.Count)
    13             Dim sd = simpleDelegates[i]
    14             __call sd.methodPtr, sd.object, #params#
    15         Next
    16     End Sub
    17 End Class
     5    Public
     6        Sub #name#()
     7        End Sub
     8        Sub #name#( dg As #name# )
     9            Add( dg )
     10        End Sub
     11
     12        #call_method_begin#
     13        'Sub Call(...)
     14            Dim i As Long
     15            For i = 0 To ELM(simpleDelegates.Count)
     16                Dim sd = simpleDelegates[i]
     17                #result# __delegate_dynamicmethod_call(sd.methodPtr, sd.object, #params#)
     18            Next
     19        'End Sub
     20        #call_method_end#
     21
     22        Sub Add( dg As #name# )
     23            _Add( dg )
     24        End Sub
     25
     26        Function Operator+ ( dg As #name# ) As #name#
     27            Dim result = New #name#( This )
     28            result._Add( dg )
     29            Return result
     30        End Function
     31
     32        Static Function _CreateDelegate( object As Object, methodPtr As VoidPtr ) As #name#
     33            Dim dg = New #name#
     34            dg.simpleDelegates.Add( New System._SimpleDelegate( object, methodPtr ) )
     35            Return dg
     36        End Function
     37    End Class
     38#namespace_end#
Note: See TracChangeset for help on using the changeset viewer.