Changeset 76 for Generics/TemplateGenerics/Generic
- Timestamp:
- Oct 29, 2010, 7:49:29 AM (14 years ago)
- Location:
- Generics/TemplateGenerics/Generic
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
Generics/TemplateGenerics/Generic/ListImplementation.tpl
r74 r76 1 1 uses 2 2 RtlConsts; 3 4 // Used instead of System.Move form because of error: Identifier "System" not found5 procedure SystemMove(const Source; var Dest; Count: SizeInt);6 begin7 Move(Source, Dest, Count);8 end;9 3 10 4 { TGList } … … 130 124 if FCount = Capacity then Expand; 131 125 if Index < FCount then 132 System Move(FItems[Index], FItems[Index + 1], (FCount - Index) * SizeOf(TListItem));126 System.Move(FItems[Index], FItems[Index + 1], (FCount - Index) * SizeOf(TListItem)); 133 127 FItems[Index] := Item; 134 128 FCount := FCount + 1; … … 163 157 raise EListError.CreateFmt(SlistIndexError, [NewIndex]); 164 158 Temp := FItems[CurIndex]; 165 Delete(CurIndex); 166 Insert(NewIndex, Temp); 159 if NewIndex > CurIndex then begin 160 System.Move(FItems[CurIndex + 1], FItems[CurIndex], (NewIndex - CurIndex) * SizeOf(TListItem)); 161 end else 162 if NewIndex < CurIndex then begin 163 System.Move(FItems[NewIndex], FItems[NewIndex + 1], (CurIndex - NewIndex) * SizeOf(TListItem)); 164 end; 165 FItems[NewIndex] := Temp; 166 //Delete(CurIndex); 167 //Insert(NewIndex, Temp); 167 168 end; 168 169 … … 289 290 raise EListError.CreateFmt(SListIndexError, [Index]); 290 291 FCount := FCount - 1; 291 System Move(FItems[Index + 1], FItems[Index], (FCount - Index) * SizeOf(TListItem));292 System.Move(FItems[Index + 1], FItems[Index], (FCount - Index) * SizeOf(TListItem)); 292 293 // Shrink the list if appropriate 293 294 if (Capacity > 256) and (FCount < Capacity shr 2) then -
Generics/TemplateGenerics/Generic/QueueImplementation.tpl
r73 r76 5 5 procedure TGQueue.Enqueue(Value: TQueueItem); 6 6 begin 7 Add(Value);7 FList.Add(Value); 8 8 end; 9 9 10 10 function TGQueue.Peek: TQueueItem; 11 11 begin 12 Result := First; 12 Result := FList.First; 13 end; 14 15 constructor TGQueue.Create; 16 begin 17 FList := TGList.Create; 18 end; 19 20 destructor TGQueue.Destroy; 21 begin 22 FList.Free; 23 inherited Destroy; 13 24 end; 14 25 15 26 function TGQueue.Dequeue: TQueueItem; 16 27 begin 17 Result := Extract(First);28 Result := FList.Extract(FList.First); 18 29 end; 19 30 -
Generics/TemplateGenerics/Generic/QueueInterface.tpl
r73 r76 4 4 {$INCLUDE 'ListInterface.tpl'} 5 5 6 // TGQueue<T ListIndex, TListItem> = class(TGList)7 TGQueue = class (TGList)6 // TGQueue<TSetIndex, TSetItem> = class(TGList) 7 TGQueue = class 8 8 private 9 FList: TGList; 9 10 public 10 11 procedure Enqueue(Value: TQueueItem); 11 12 function Dequeue: TQueueItem; 12 13 function Peek: TQueueItem; 14 constructor Create; 15 destructor Destroy; override; 16 property List: TGList read FList; 13 17 end; -
Generics/TemplateGenerics/Generic/StackImplementation.tpl
r73 r76 5 5 procedure TGStack.Push(Value: TStackItem); 6 6 begin 7 Add(Value);7 FList.Add(Value); 8 8 end; 9 9 10 10 function TGStack.Pop: TStackItem; 11 11 begin 12 Result := Extract(Last);12 Result := FList.Extract(FList.Last); 13 13 end; 14 14 15 constructor TGStack.Create; 16 begin 17 FList := TGList.Create; 18 end; 19 20 destructor TGStack.Destroy; 21 begin 22 FList.Free; 23 inherited Destroy; 24 end; 25 -
Generics/TemplateGenerics/Generic/StackInterface.tpl
r73 r76 4 4 {$INCLUDE 'ListInterface.tpl'} 5 5 6 // TGStack<T ListIndex, TListItem> = class(TGList)7 TGStack = class (TGList)6 // TGStack<TStackIndex, TStackItem> = class(TGList) 7 TGStack = class 8 8 private 9 FList: TGList; 9 10 public 10 11 procedure Push(Value: TStackItem); 11 12 function Pop: TStackItem; 13 constructor Create; 14 destructor Destroy; override; 15 property List: TGList read FList; 12 16 end;
Note:
See TracChangeset
for help on using the changeset viewer.