THRIFT-2084 Delphi: Ability to create entity Thrift-generated instances based on...
authorJens Geyer <jensg@apache.org>
Sat, 6 Jul 2013 12:28:43 +0000 (14:28 +0200)
committerJens Geyer <jensg@apache.org>
Sat, 13 Jul 2013 11:24:10 +0000 (13:24 +0200)
Patch: Jens Geyer

lib/delphi/src/Thrift.TypeRegistry.pas

index 1b863d2..cc22952 100644 (file)
@@ -22,7 +22,8 @@ unit Thrift.TypeRegistry;
 interface\r
 \r
 uses\r
-  Generics.Collections;\r
+  Generics.Collections, TypInfo,\r
+  Thrift.Protocol;\r
 \r
 type\r
   TFactoryMethod<T> = function:T;\r
@@ -35,12 +36,11 @@ type
     class destructor Destroy;\r
     class procedure RegisterTypeFactory<F>(const aFactoryMethod: TFactoryMethod<F>);\r
     class function  Construct<F>: F;\r
+    class function  ConstructFromTypeInfo(const aTypeInfo: PTypeInfo): IBase;\r
   end;\r
 \r
 implementation\r
 \r
-uses\r
-  TypInfo;\r
 \r
 { TypeRegistration }\r
 \r
@@ -80,5 +80,16 @@ begin
   end;\r
 end;\r
 \r
+class function TypeRegistry.ConstructFromTypeInfo(const aTypeInfo: PTypeInfo): IBase;\r
+var\r
+  Factory      : Pointer;\r
+begin\r
+  Result := nil;\r
+  if FTypeInfoToFactoryLookup.TryGetValue(aTypeInfo, Factory)\r
+  then Result := IBase(TFactoryMethod<IBase>(Factory)());\r
+end;\r
+\r
+\r
+\r
 \r
 end.\r