You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
5.2 KiB

  1. unit uutlInterfaces;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils
  6. {$IFDEF UTL_ENUMERATORS}
  7. , uutlTypes
  8. {$ENDIF};
  9. type
  10. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  11. generic IutlEqualityComparer<T> = interface(IUnknown)
  12. ['{C0FB90CC-D071-490F-BFEE-BAA5C94D1A5B}']
  13. function EqualityCompare(constref i1, i2: T): Boolean;
  14. end;
  15. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  16. generic IutlComparer<T> = interface(specialize IutlEqualityComparer<T>)
  17. ['{7D2EC014-2878-4F60-9E43-4CFB54268995}']
  18. function Compare(constref i1, i2: T): Integer;
  19. end;
  20. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  21. generic IutlFilter<T> = interface(IUnknown)
  22. function Filter(constref i: T): Boolean;
  23. end;
  24. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  25. generic IutlSelector<Tin, Tout> = interface(IUnknown)
  26. function Select(constref i: Tin): Tout;
  27. end;
  28. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  29. generic IutlEnumerator<T> = interface(specialize IEnumerator<T>)
  30. // TODO: Aggregate, Join
  31. {$IFDEF UTL_ENUMERATORS}
  32. function GetEnumerator: specialize IutlEnumerator<T>;
  33. // the following functions will execute the query
  34. function Count (): Integer;
  35. function Any (): Boolean;
  36. function ToArray (): specialize TutlArray<T>;
  37. function Contains (constref aElement: T; aComparer: specialize IutlEqualityComparer<T>): Boolean;
  38. // the following functions will describe the query and do not execute any code in the enumerated items
  39. function Skip (aCount: Integer): specialize IutlEnumerator<T>;
  40. function Take (aCount: Integer): specialize IutlEnumerator<T>;
  41. function Concat (aEnumerator: specialize IutlEnumerator<T>): specialize IutlEnumerator<T>;
  42. function Reverse (): specialize IutlEnumerator<T>;
  43. {$IFDEF UTL_ADVANCED_ENUMERATORS}
  44. function Sort (aComparer: specialize IutlComparer<T>): specialize IutlEnumerator<T>;
  45. function Where (aFilter: specialize IutlFilter<T>): specialize IutlEnumerator<T>;
  46. function Distinct (aComparer: specialize IutlComparer<T>): specialize IutlEnumerator<T>;
  47. function Intersect (aEnumerator: specialize IutlEnumerator<T>; aComparer: specialize IutlComparer<T>): specialize IutlEnumerator<T>;
  48. function Union (aEnumerator: specialize IutlEnumerator<T>; aComparer: specialize IutlComparer<T>): specialize IutlEnumerator<T>;
  49. function Without (aEnumerator: specialize IutlEnumerator<T>; aComparer: specialize IutlComparer<T>): specialize IutlEnumerator<T>;
  50. // TODO: interfaces do not support generic functions yet
  51. // generic function Select<S> (aSelector: specialize IutlSelector<T, S>): specialize IutlEnumerator<S>;
  52. // generic function SelectMany<S>(aSelector: specialize IutlSelector<T, specialize IutlEnumerator<S>>): specialize IutlEnumerator<S>;
  53. // generic function Aggregate<S> (constref aSeed: S; aAggregator: specialize IutlAggregator<T, S>): S;
  54. // generic function Zip<S> (aEnumerator: specialize IutlEnumerator<S>): specialize IutlEnumerator<specialize Pair<T, S>>;
  55. {$ENDIF}
  56. {$ENDIF}
  57. end;
  58. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  59. generic IutlEnumerable<T> = interface(specialize IEnumerable<T>)
  60. ['{963214EB-EF7C-4785-8B48-8DD9DE0ABDAF}']
  61. function GetUtlEnumerator: specialize IutlEnumerator<T>;
  62. property UtlEnumerator: specialize IutlEnumerator<T> read GetUtlEnumerator;
  63. property Enumerator: specialize IEnumerator<T> read GetEnumerator;
  64. end;
  65. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  66. generic IutlReadOnlyArray<T> = interface(specialize {$IFDEF UTL_ADVANCED_ENUMERATORS}IutlEnumerable{$ELSE}IEnumerable{$ENDIF}<T>)
  67. ['{B0938B6F-4E0D-45E3-A813-056AD4C0A2F2}']
  68. function GetCount: Integer;
  69. function GetItem(const aIndex: Integer): T;
  70. property Count: Integer read GetCount;
  71. property Items[const aIndex: Integer]: T read GetItem; default;
  72. end;
  73. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  74. generic IutlArray<T> = interface(specialize IutlReadOnlyArray<T>)
  75. ['{D3618E88-3BF7-4E63-850F-6893A334564A}']
  76. procedure SetCount(const aValue: Integer);
  77. procedure SetItem(const aIndex: Integer; aItem: T);
  78. property Count: Integer read GetCount write SetCount;
  79. property Items[const aIndex: Integer]: T read GetItem write SetItem; default;
  80. end;
  81. implementation
  82. end.