gqueue.pp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. {
  2. This file is part of the Free Pascal FCL library.
  3. BSD parts (c) 2011 Vlado Boza
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY;without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. {$mode objfpc}
  11. {$IFNDEF FPC_DOTTEDUNITS}
  12. unit gqueue;
  13. {$ENDIF FPC_DOTTEDUNITS}
  14. interface
  15. {$IFDEF FPC_DOTTEDUNITS}
  16. uses System.Stl.Deque;
  17. {$ELSE FPC_DOTTEDUNITS}
  18. uses gdeque;
  19. {$ENDIF FPC_DOTTEDUNITS}
  20. type
  21. generic TQueue<T>=class
  22. private
  23. type
  24. TContainer = specialize TDeque<T>;
  25. var
  26. FData:TContainer;
  27. public
  28. procedure Push(value:T);inline;
  29. procedure Pop();inline;
  30. function Front():T;inline;
  31. function Size():SizeUInt;inline;
  32. function IsEmpty():boolean;inline;
  33. constructor Create;
  34. destructor Destroy;override;
  35. end;
  36. implementation
  37. constructor TQueue.Create;
  38. begin
  39. FData:=TContainer.Create;
  40. end;
  41. destructor TQueue.Destroy;
  42. begin
  43. FData.Destroy;
  44. end;
  45. procedure TQueue.Push(value:T);inline;
  46. begin
  47. FData.PushBack(value);
  48. end;
  49. procedure TQueue.Pop();inline;
  50. begin
  51. FData.PopFront;
  52. end;
  53. function TQueue.Front:T;inline;
  54. begin
  55. Front:=FData.Front;
  56. end;
  57. function TQueue.Size:SizeUInt;inline;
  58. begin
  59. Size:=FData.Size;
  60. end;
  61. function TQueue.IsEmpty:boolean;inline;
  62. begin
  63. IsEmpty:=FData.IsEmpty;
  64. end;
  65. end.