unit uutlInterfaces; {$mode objfpc}{$H+} interface uses Classes, SysUtils {$IFDEF UTL_ENUMERATORS} , uutlTypes {$ENDIF}; type //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// generic IutlEqualityComparer = interface(IUnknown) ['{C0FB90CC-D071-490F-BFEE-BAA5C94D1A5B}'] function EqualityCompare(constref i1, i2: T): Boolean; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// generic IutlComparer = interface(specialize IutlEqualityComparer) ['{7D2EC014-2878-4F60-9E43-4CFB54268995}'] function Compare(constref i1, i2: T): Integer; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// generic IutlFilter = interface(IUnknown) function Filter(constref i: T): Boolean; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// generic IutlSelector = interface(IUnknown) function Select(constref i: Tin): Tout; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// generic IutlEnumerator = interface(specialize IEnumerator) // TODO: Aggregate, Join {$IFDEF UTL_ENUMERATORS} function GetEnumerator: specialize IutlEnumerator; // the following functions will execute the query function Count (): Integer; function Any (): Boolean; function ToArray (): specialize TutlArray; function Contains (constref aElement: T; aComparer: specialize IutlEqualityComparer): Boolean; // the following functions will describe the query and do not execute any code in the enumerated items function Skip (aCount: Integer): specialize IutlEnumerator; function Take (aCount: Integer): specialize IutlEnumerator; function Concat (aEnumerator: specialize IutlEnumerator): specialize IutlEnumerator; function Reverse (): specialize IutlEnumerator; {$IFDEF UTL_ADVANCED_ENUMERATORS} function Sort (aComparer: specialize IutlComparer): specialize IutlEnumerator; function Where (aFilter: specialize IutlFilter): specialize IutlEnumerator; function Distinct (aComparer: specialize IutlComparer): specialize IutlEnumerator; function Intersect (aEnumerator: specialize IutlEnumerator; aComparer: specialize IutlComparer): specialize IutlEnumerator; function Union (aEnumerator: specialize IutlEnumerator; aComparer: specialize IutlComparer): specialize IutlEnumerator; function Without (aEnumerator: specialize IutlEnumerator; aComparer: specialize IutlComparer): specialize IutlEnumerator; // TODO: interfaces do not support generic functions yet // generic function Select (aSelector: specialize IutlSelector): specialize IutlEnumerator; // generic function SelectMany(aSelector: specialize IutlSelector>): specialize IutlEnumerator; // generic function Aggregate (constref aSeed: S; aAggregator: specialize IutlAggregator): S; // generic function Zip (aEnumerator: specialize IutlEnumerator): specialize IutlEnumerator>; {$ENDIF} {$ENDIF} end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// generic IutlEnumerable = interface(specialize IEnumerable) ['{963214EB-EF7C-4785-8B48-8DD9DE0ABDAF}'] function GetUtlEnumerator: specialize IutlEnumerator; property UtlEnumerator: specialize IutlEnumerator read GetUtlEnumerator; property Enumerator: specialize IEnumerator read GetEnumerator; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// generic IutlReadOnlyArray = interface(specialize {$IFDEF UTL_ADVANCED_ENUMERATORS}IutlEnumerable{$ELSE}IEnumerable{$ENDIF}) ['{B0938B6F-4E0D-45E3-A813-056AD4C0A2F2}'] function GetCount: Integer; function GetItem(const aIndex: Integer): T; property Count: Integer read GetCount; property Items[const aIndex: Integer]: T read GetItem; default; end; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// generic IutlArray = interface(specialize IutlReadOnlyArray) ['{D3618E88-3BF7-4E63-850F-6893A334564A}'] procedure SetCount(const aValue: Integer); procedure SetItem(const aIndex: Integer; aItem: T); property Count: Integer read GetCount write SetCount; property Items[const aIndex: Integer]: T read GetItem write SetItem; default; end; implementation end.