-
Notifications
You must be signed in to change notification settings - Fork 1
/
methodregistry.pas
53 lines (42 loc) · 1.09 KB
/
methodregistry.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{$MODE OBJFPC} { -*- delphi -*- }
{$INCLUDE settings.inc}
unit methodregistry;
interface
uses
typinfo;
procedure RegisterMethod(Address: Pointer; Signature: PTypeInfo);
{$IFOPT C+} procedure AssertMethodRegistered(Address: Pointer); {$ENDIF}
function GetTypeInfo(Address: Pointer): PTypeInfo;
implementation
uses
hashtable;
type
TMethodHashTable = specialize THashTable<Pointer, PTypeInfo>;
var
Registry: TMethodHashTable;
procedure RegisterMethod(Address: Pointer; Signature: PTypeInfo);
begin
Assert(Assigned(Address));
Assert(Assigned(Signature));
Assert(not Registry.Has(Address));
Assert(Signature^.Kind = tkMethod);
Registry.Add(Address, Signature);
end;
{$IFOPT C+}
procedure AssertMethodRegistered(Address: Pointer);
begin
Assert(Assigned(Address));
Assert(Registry.Has(Address));
end;
{$ENDIF}
function GetTypeInfo(Address: Pointer): PTypeInfo;
begin
Assert(Assigned(Address));
Assert(Registry.Has(Address));
Result := Registry[Address];
end;
initialization
Registry := TMethodHashTable.Create(@PointerHash32);
finalization
Registry.Free();
end.