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