Updated Branches: refs/heads/master 6f2a50371 -> 67065d7bf
THRIFT-2084 Delphi: Ability to create entity Thrift-generated instances based on TypeInfo Patch: Jens Geyer Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/67065d7b Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/67065d7b Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/67065d7b Branch: refs/heads/master Commit: 67065d7bf8405ccc38d911b928c88a64d79902c6 Parents: 6f2a503 Author: Jens Geyer <[email protected]> Authored: Sat Jul 6 14:28:43 2013 +0200 Committer: Jens Geyer <[email protected]> Committed: Sat Jul 13 13:24:10 2013 +0200 ---------------------------------------------------------------------- lib/delphi/src/Thrift.TypeRegistry.pas | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/67065d7b/lib/delphi/src/Thrift.TypeRegistry.pas ---------------------------------------------------------------------- diff --git a/lib/delphi/src/Thrift.TypeRegistry.pas b/lib/delphi/src/Thrift.TypeRegistry.pas index 1b863d2..cc22952 100644 --- a/lib/delphi/src/Thrift.TypeRegistry.pas +++ b/lib/delphi/src/Thrift.TypeRegistry.pas @@ -22,7 +22,8 @@ unit Thrift.TypeRegistry; interface uses - Generics.Collections; + Generics.Collections, TypInfo, + Thrift.Protocol; type TFactoryMethod<T> = function:T; @@ -35,12 +36,11 @@ type class destructor Destroy; class procedure RegisterTypeFactory<F>(const aFactoryMethod: TFactoryMethod<F>); class function Construct<F>: F; + class function ConstructFromTypeInfo(const aTypeInfo: PTypeInfo): IBase; end; implementation -uses - TypInfo; { TypeRegistration } @@ -80,5 +80,16 @@ begin end; end; +class function TypeRegistry.ConstructFromTypeInfo(const aTypeInfo: PTypeInfo): IBase; +var + Factory : Pointer; +begin + Result := nil; + if FTypeInfoToFactoryLookup.TryGetValue(aTypeInfo, Factory) + then Result := IBase(TFactoryMethod<IBase>(Factory)()); +end; + + + end.
