mirror of
				https://gitlab.com/freepascal.org/fpc/source.git
				synced 2025-11-04 02:19:22 +01:00 
			
		
		
		
	rtl: add enumerator for the TFPGList type
git-svn-id: trunk@14245 -
This commit is contained in:
		
							parent
							
								
									5684e3acc7
								
							
						
					
					
						commit
						64b6700c61
					
				@ -84,12 +84,24 @@ const
 | 
				
			|||||||
  MaxGListSize = MaxInt div 1024;
 | 
					  MaxGListSize = MaxInt div 1024;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type
 | 
					type
 | 
				
			||||||
 | 
					  generic TFPGListEnumerator<T> = class(TObject)
 | 
				
			||||||
 | 
					  var protected
 | 
				
			||||||
 | 
					    FList: TFPSList;
 | 
				
			||||||
 | 
					    FPosition: Integer;
 | 
				
			||||||
 | 
					    function GetCurrent: T;
 | 
				
			||||||
 | 
					  public
 | 
				
			||||||
 | 
					    constructor Create(AList: TFPSList);
 | 
				
			||||||
 | 
					    function MoveNext: Boolean;
 | 
				
			||||||
 | 
					    property Current: T read GetCurrent;
 | 
				
			||||||
 | 
					  end;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  generic TFPGList<T> = class(TFPSList)
 | 
					  generic TFPGList<T> = class(TFPSList)
 | 
				
			||||||
  type public
 | 
					  type public
 | 
				
			||||||
    TCompareFunc = function(const Item1, Item2: T): Integer;
 | 
					    TCompareFunc = function(const Item1, Item2: T): Integer;
 | 
				
			||||||
    TTypeList = array[0..MaxGListSize] of T;
 | 
					    TTypeList = array[0..MaxGListSize] of T;
 | 
				
			||||||
    PTypeList = ^TTypeList;
 | 
					    PTypeList = ^TTypeList;
 | 
				
			||||||
    PT = ^T;
 | 
					    PT = ^T;
 | 
				
			||||||
 | 
					    TFPGListEnumeratorSpec = specialize TFPGListEnumerator<T>;
 | 
				
			||||||
  var protected
 | 
					  var protected
 | 
				
			||||||
    FOnCompare: TCompareFunc;
 | 
					    FOnCompare: TCompareFunc;
 | 
				
			||||||
    procedure CopyItem(Src, Dest: Pointer); override;
 | 
					    procedure CopyItem(Src, Dest: Pointer); override;
 | 
				
			||||||
@ -103,6 +115,7 @@ type
 | 
				
			|||||||
    function Add(const Item: T): Integer; {$ifdef CLASSESINLINE} inline; {$endif}
 | 
					    function Add(const Item: T): Integer; {$ifdef CLASSESINLINE} inline; {$endif}
 | 
				
			||||||
    function Extract(const Item: T): T; {$ifdef CLASSESINLINE} inline; {$endif}
 | 
					    function Extract(const Item: T): T; {$ifdef CLASSESINLINE} inline; {$endif}
 | 
				
			||||||
    function First: T; {$ifdef CLASSESINLINE} inline; {$endif}
 | 
					    function First: T; {$ifdef CLASSESINLINE} inline; {$endif}
 | 
				
			||||||
 | 
					    function GetEnumerator: TFPGListEnumeratorSpec; {$ifdef CLASSESINLINE} inline; {$endif}
 | 
				
			||||||
    function IndexOf(const Item: T): Integer;
 | 
					    function IndexOf(const Item: T): Integer;
 | 
				
			||||||
    procedure Insert(Index: Integer; const Item: T); {$ifdef CLASSESINLINE} inline; {$endif}
 | 
					    procedure Insert(Index: Integer; const Item: T); {$ifdef CLASSESINLINE} inline; {$endif}
 | 
				
			||||||
    function Last: T; {$ifdef CLASSESINLINE} inline; {$endif}
 | 
					    function Last: T; {$ifdef CLASSESINLINE} inline; {$endif}
 | 
				
			||||||
@ -608,6 +621,28 @@ end;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
{$ifndef VER2_0}
 | 
					{$ifndef VER2_0}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{****************************************************************************}
 | 
				
			||||||
 | 
					{*             TFPGListEnumerator                                           *}
 | 
				
			||||||
 | 
					{****************************************************************************}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function TFPGListEnumerator.GetCurrent: T;
 | 
				
			||||||
 | 
					begin
 | 
				
			||||||
 | 
					  Result := T(FList.Items[FPosition]^);
 | 
				
			||||||
 | 
					end;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					constructor TFPGListEnumerator.Create(AList: TFPSList);
 | 
				
			||||||
 | 
					begin
 | 
				
			||||||
 | 
					  inherited Create;
 | 
				
			||||||
 | 
					  FList := AList;
 | 
				
			||||||
 | 
					  FPosition := -1;
 | 
				
			||||||
 | 
					end;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function TFPGListEnumerator.MoveNext: Boolean;
 | 
				
			||||||
 | 
					begin
 | 
				
			||||||
 | 
					  inc(FPosition);
 | 
				
			||||||
 | 
					  Result := FPosition < FList.Count;
 | 
				
			||||||
 | 
					end;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{****************************************************************************}
 | 
					{****************************************************************************}
 | 
				
			||||||
{*                TFPGList                                                  *}
 | 
					{*                TFPGList                                                  *}
 | 
				
			||||||
{****************************************************************************}
 | 
					{****************************************************************************}
 | 
				
			||||||
@ -668,6 +703,11 @@ begin
 | 
				
			|||||||
  Result := T(inherited First^);
 | 
					  Result := T(inherited First^);
 | 
				
			||||||
end;
 | 
					end;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function TFPGList.GetEnumerator: TFPGListEnumeratorSpec;
 | 
				
			||||||
 | 
					begin
 | 
				
			||||||
 | 
					  Result := TFPGListEnumeratorSpec.Create(Self);
 | 
				
			||||||
 | 
					end;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function TFPGList.IndexOf(const Item: T): Integer;
 | 
					function TFPGList.IndexOf(const Item: T): Integer;
 | 
				
			||||||
begin
 | 
					begin
 | 
				
			||||||
  Result := 0;
 | 
					  Result := 0;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user