Changeset 322 for Generics/NativeGenerics
- Timestamp:
- Feb 8, 2012, 9:47:54 AM (13 years ago)
- Location:
- Generics/NativeGenerics
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
Generics/NativeGenerics/Demo/Demo.lpi
r321 r322 43 43 <IsPartOfProject Value="True"/> 44 44 <UnitName Value="Demo"/> 45 <EditorIndex Value=" 7"/>45 <EditorIndex Value="9"/> 46 46 <WindowIndex Value="0"/> 47 47 <TopLine Value="1"/> … … 57 57 <ResourceBaseClass Value="Form"/> 58 58 <UnitName Value="UMainForm"/> 59 <IsVisibleTab Value="True"/> 59 60 <EditorIndex Value="0"/> 60 61 <WindowIndex Value="0"/> 61 <TopLine Value=" 85"/>62 <CursorPos X="1 1" Y="98"/>62 <TopLine Value="191"/> 63 <CursorPos X="1" Y="205"/> 63 64 <UsageCount Value="233"/> 64 65 <Bookmarks Count="1"> 65 <Item0 X="65" Y="27 7" ID="2"/>66 <Item0 X="65" Y="276" ID="2"/> 66 67 </Bookmarks> 67 68 <Loaded Value="True"/> … … 83 84 <TopLine Value="1"/> 84 85 <CursorPos X="25" Y="13"/> 85 <UsageCount Value=" 0"/>86 <UsageCount Value="10"/> 86 87 <DefaultSyntaxHighlighter Value="None"/> 87 88 </Unit3> … … 439 440 <Filename Value="../Units/GenericList.pas"/> 440 441 <UnitName Value="GenericList"/> 441 <IsVisibleTab Value="True"/> 442 <EditorIndex Value="1"/> 443 <WindowIndex Value="0"/> 444 <TopLine Value="449"/> 445 <CursorPos X="92" Y="462"/> 446 <UsageCount Value="35"/> 442 <EditorIndex Value="3"/> 443 <WindowIndex Value="0"/> 444 <TopLine Value="516"/> 445 <CursorPos X="1" Y="528"/> 446 <UsageCount Value="37"/> 447 447 <Loaded Value="True"/> 448 448 </Unit46> … … 450 450 <Filename Value="../Units/GenericMatrix.pas"/> 451 451 <UnitName Value="GenericMatrix"/> 452 <EditorIndex Value=" 6"/>452 <EditorIndex Value="8"/> 453 453 <WindowIndex Value="0"/> 454 454 <TopLine Value="77"/> 455 455 <CursorPos X="1" Y="85"/> 456 <UsageCount Value="1 3"/>456 <UsageCount Value="15"/> 457 457 <Loaded Value="True"/> 458 458 </Unit47> … … 460 460 <Filename Value="../Units/GenericStream.pas"/> 461 461 <UnitName Value="GenericStream"/> 462 <WindowIndex Value="0"/> 463 <TopLine Value="59"/> 464 <CursorPos X="26" Y="65"/> 462 <EditorIndex Value="1"/> 463 <WindowIndex Value="0"/> 464 <TopLine Value="148"/> 465 <CursorPos X="3" Y="150"/> 465 466 <UsageCount Value="15"/> 467 <Loaded Value="True"/> 466 468 </Unit48> 467 469 <Unit49> … … 476 478 <Filename Value="../Units/GenericDictionary.pas"/> 477 479 <UnitName Value="GenericDictionary"/> 478 <EditorIndex Value=" 5"/>480 <EditorIndex Value="7"/> 479 481 <WindowIndex Value="0"/> 480 482 <TopLine Value="1"/> 481 483 <CursorPos X="1" Y="1"/> 482 <UsageCount Value="1 4"/>484 <UsageCount Value="16"/> 483 485 <Loaded Value="True"/> 484 486 </Unit50> 485 487 <Unit51> 486 488 <Filename Value="../../../../../Lazarus/0.9.31_2.6.0/fpc/2.6.0/source/rtl/objpas/sysutils/sysunih.inc"/> 487 <EditorIndex Value=" 4"/>489 <EditorIndex Value="6"/> 488 490 <WindowIndex Value="0"/> 489 491 <TopLine Value="9"/> 490 492 <CursorPos X="10" Y="22"/> 491 <UsageCount Value="1 4"/>493 <UsageCount Value="16"/> 492 494 <Loaded Value="True"/> 493 495 <DefaultSyntaxHighlighter Value="Delphi"/> … … 496 498 <Filename Value="../Units/SpecializedList.pas"/> 497 499 <UnitName Value="SpecializedList"/> 498 <EditorIndex Value=" 8"/>500 <EditorIndex Value="10"/> 499 501 <WindowIndex Value="0"/> 500 502 <TopLine Value="1"/> 501 503 <CursorPos X="23" Y="11"/> 502 <UsageCount Value="1 4"/>504 <UsageCount Value="16"/> 503 505 <Loaded Value="True"/> 504 506 </Unit52> 505 507 <Unit53> 506 508 <Filename Value="../../../../../Lazarus/0.9.31_2.7.1/fpc/2.7.1/source/rtl/objpas/classes/classesh.inc"/> 507 <WindowIndex Value="0"/> 508 <TopLine Value="127"/> 509 <CursorPos X="3" Y="140"/> 509 <EditorIndex Value="2"/> 510 <WindowIndex Value="0"/> 511 <TopLine Value="257"/> 512 <CursorPos X="3" Y="270"/> 510 513 <UsageCount Value="13"/> 514 <Loaded Value="True"/> 511 515 </Unit53> 512 516 <Unit54> … … 529 533 <Filename Value="../Units/GenericRange.pas"/> 530 534 <UnitName Value="GenericRange"/> 531 <EditorIndex Value=" 2"/>535 <EditorIndex Value="4"/> 532 536 <WindowIndex Value="0"/> 533 537 <TopLine Value="4"/> 534 538 <CursorPos X="33" Y="8"/> 535 <UsageCount Value="1 4"/>539 <UsageCount Value="16"/> 536 540 <Loaded Value="True"/> 537 541 </Unit56> … … 546 550 <Filename Value="../Units/GenericTree.pas"/> 547 551 <UnitName Value="GenericTree"/> 548 <EditorIndex Value=" 3"/>552 <EditorIndex Value="5"/> 549 553 <WindowIndex Value="0"/> 550 554 <TopLine Value="1"/> 551 555 <CursorPos X="33" Y="8"/> 552 <UsageCount Value="1 3"/>556 <UsageCount Value="16"/> 553 557 <Loaded Value="True"/> 554 558 </Unit58> 555 559 </Units> 556 <JumpHistory Count="30" HistoryIndex="2 9">560 <JumpHistory Count="30" HistoryIndex="28"> 557 561 <Position1> 558 562 <Filename Value="UMainForm.pas"/> 559 <Caret Line=" 93" Column="29" TopLine="77"/>563 <Caret Line="23" Column="22" TopLine="10"/> 560 564 </Position1> 561 565 <Position2> 562 566 <Filename Value="UMainForm.pas"/> 563 <Caret Line=" 98" Column="11" TopLine="85"/>567 <Caret Line="669" Column="21" TopLine="656"/> 564 568 </Position2> 565 569 <Position3> 566 <Filename Value=" ../Units/GenericList.pas"/>567 <Caret Line=" 67" Column="35" TopLine="51"/>570 <Filename Value="UMainForm.pas"/> 571 <Caret Line="185" Column="19" TopLine="179"/> 568 572 </Position3> 569 573 <Position4> 570 <Filename Value=" ../Units/GenericList.pas"/>571 <Caret Line=" 14" Column="36" TopLine="1"/>574 <Filename Value="UMainForm.pas"/> 575 <Caret Line="49" Column="14" TopLine="36"/> 572 576 </Position4> 573 577 <Position5> 574 <Filename Value="../Units/Generic List.pas"/>575 <Caret Line="4 34" Column="1" TopLine="419"/>578 <Filename Value="../Units/GenericStream.pas"/> 579 <Caret Line="45" Column="48" TopLine="27"/> 576 580 </Position5> 577 581 <Position6> 578 <Filename Value=" ../Units/GenericList.pas"/>579 <Caret Line="1 6" Column="3" TopLine="15"/>582 <Filename Value="UMainForm.pas"/> 583 <Caret Line="198" Column="25" TopLine="185"/> 580 584 </Position6> 581 585 <Position7> 582 <Filename Value=" ../Units/GenericList.pas"/>583 <Caret Line=" 32" Column="1" TopLine="15"/>586 <Filename Value="UMainForm.pas"/> 587 <Caret Line="669" Column="21" TopLine="656"/> 584 588 </Position7> 585 589 <Position8> 586 <Filename Value=" ../Units/GenericList.pas"/>587 <Caret Line="1 47" Column="3" TopLine="145"/>590 <Filename Value="UMainForm.pas"/> 591 <Caret Line="164" Column="1" TopLine="151"/> 588 592 </Position8> 589 593 <Position9> 590 <Filename Value=" ../Units/GenericList.pas"/>591 <Caret Line=" 27" Column="1" TopLine="24"/>594 <Filename Value="UMainForm.pas"/> 595 <Caret Line="442" Column="1" TopLine="429"/> 592 596 </Position9> 593 597 <Position10> 594 <Filename Value=" ../Units/GenericList.pas"/>595 <Caret Line=" 30" Column="1" TopLine="21"/>598 <Filename Value="UMainForm.pas"/> 599 <Caret Line="443" Column="1" TopLine="429"/> 596 600 </Position10> 597 601 <Position11> 598 <Filename Value=" ../Units/GenericList.pas"/>599 <Caret Line=" 35" Column="1" TopLine="22"/>602 <Filename Value="UMainForm.pas"/> 603 <Caret Line="442" Column="3" TopLine="429"/> 600 604 </Position11> 601 605 <Position12> 602 <Filename Value=" ../Units/GenericList.pas"/>603 <Caret Line=" 77" Column="31" TopLine="53"/>606 <Filename Value="UMainForm.pas"/> 607 <Caret Line="656" Column="20" TopLine="643"/> 604 608 </Position12> 605 609 <Position13> 606 <Filename Value=" ../Units/GenericList.pas"/>607 <Caret Line="1 5" Column="1" TopLine="14"/>610 <Filename Value="UMainForm.pas"/> 611 <Caret Line="189" Column="3" TopLine="182"/> 608 612 </Position13> 609 613 <Position14> 610 <Filename Value="../Units/Generic List.pas"/>611 <Caret Line=" 26" Column="1" TopLine="22"/>614 <Filename Value="../Units/GenericStream.pas"/> 615 <Caret Line="43" Column="15" TopLine="30"/> 612 616 </Position14> 613 617 <Position15> 614 <Filename Value=" ../Units/GenericList.pas"/>615 <Caret Line=" 77" Column="33" TopLine="53"/>618 <Filename Value="UMainForm.pas"/> 619 <Caret Line="191" Column="1" TopLine="182"/> 616 620 </Position15> 617 621 <Position16> 618 <Filename Value=" ../Units/GenericList.pas"/>619 <Caret Line=" 45" Column="1" TopLine="32"/>622 <Filename Value="UMainForm.pas"/> 623 <Caret Line="192" Column="1" TopLine="182"/> 620 624 </Position16> 621 625 <Position17> 622 <Filename Value=" ../Units/GenericList.pas"/>623 <Caret Line=" 25" Column="1" TopLine="13"/>626 <Filename Value="UMainForm.pas"/> 627 <Caret Line="193" Column="1" TopLine="182"/> 624 628 </Position17> 625 629 <Position18> 626 <Filename Value=" ../Units/GenericList.pas"/>627 <Caret Line=" 26" Column="1" TopLine="13"/>630 <Filename Value="UMainForm.pas"/> 631 <Caret Line="194" Column="1" TopLine="182"/> 628 632 </Position18> 629 633 <Position19> 630 <Filename Value=" ../Units/GenericList.pas"/>631 <Caret Line=" 27" Column="1" TopLine="14"/>634 <Filename Value="UMainForm.pas"/> 635 <Caret Line="195" Column="1" TopLine="182"/> 632 636 </Position19> 633 637 <Position20> 634 <Filename Value=" ../Units/GenericList.pas"/>635 <Caret Line=" 28" Column="1" TopLine="15"/>638 <Filename Value="UMainForm.pas"/> 639 <Caret Line="196" Column="1" TopLine="182"/> 636 640 </Position20> 637 641 <Position21> 638 <Filename Value=" ../Units/GenericList.pas"/>639 <Caret Line=" 31" Column="1" TopLine="18"/>642 <Filename Value="UMainForm.pas"/> 643 <Caret Line="197" Column="1" TopLine="182"/> 640 644 </Position21> 641 645 <Position22> 642 <Filename Value=" ../Units/GenericList.pas"/>643 <Caret Line=" 35" Column="1" TopLine="22"/>646 <Filename Value="UMainForm.pas"/> 647 <Caret Line="198" Column="1" TopLine="182"/> 644 648 </Position22> 645 649 <Position23> 646 <Filename Value=" ../Units/GenericList.pas"/>647 <Caret Line=" 29" Column="1" TopLine="22"/>650 <Filename Value="UMainForm.pas"/> 651 <Caret Line="199" Column="1" TopLine="182"/> 648 652 </Position23> 649 653 <Position24> 650 <Filename Value=" ../Units/GenericList.pas"/>651 <Caret Line=" 35" Column="1" TopLine="22"/>654 <Filename Value="UMainForm.pas"/> 655 <Caret Line="200" Column="1" TopLine="182"/> 652 656 </Position24> 653 657 <Position25> 654 <Filename Value=" ../Units/GenericList.pas"/>655 <Caret Line=" 31" Column="30" TopLine="22"/>658 <Filename Value="UMainForm.pas"/> 659 <Caret Line="201" Column="1" TopLine="182"/> 656 660 </Position25> 657 661 <Position26> 658 <Filename Value=" ../Units/GenericList.pas"/>659 <Caret Line=" 64" Column="1" TopLine="48"/>662 <Filename Value="UMainForm.pas"/> 663 <Caret Line="202" Column="1" TopLine="191"/> 660 664 </Position26> 661 665 <Position27> 662 <Filename Value=" ../Units/GenericList.pas"/>663 <Caret Line=" 407" Column="77" TopLine="389"/>666 <Filename Value="UMainForm.pas"/> 667 <Caret Line="203" Column="1" TopLine="191"/> 664 668 </Position27> 665 669 <Position28> 666 <Filename Value=" ../Units/GenericList.pas"/>667 <Caret Line=" 62" Column="20" TopLine="55"/>670 <Filename Value="UMainForm.pas"/> 671 <Caret Line="204" Column="1" TopLine="191"/> 668 672 </Position28> 669 673 <Position29> 670 <Filename Value=" ../Units/GenericList.pas"/>671 <Caret Line=" 385" Column="21" TopLine="380"/>674 <Filename Value="UMainForm.pas"/> 675 <Caret Line="205" Column="1" TopLine="191"/> 672 676 </Position29> 673 677 <Position30> 674 <Filename Value="../Units/Generic List.pas"/>675 <Caret Line=" 64" Column="39" TopLine="51"/>678 <Filename Value="../Units/GenericStream.pas"/> 679 <Caret Line="150" Column="3" TopLine="148"/> 676 680 </Position30> 677 681 </JumpHistory> … … 722 726 </CompilerOptions> 723 727 <Debugging> 728 <BreakPoints Count="1"> 729 <Item1> 730 <Kind Value="bpkSource"/> 731 <WatchScope Value="wpsLocal"/> 732 <WatchKind Value="wpkWrite"/> 733 <Source Value="UMainForm.pas"/> 734 <Line Value="205"/> 735 </Item1> 736 </BreakPoints> 724 737 <Exceptions Count="3"> 725 738 <Item1> -
Generics/NativeGenerics/Demo/UMainForm.pas
r321 r322 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 ComCtrls, GenericList, GenericDictionary, GenericQueue, 9 ComCtrls, GenericList, GenericDictionary, GenericQueue, GenericStream, 10 10 DateUtils, SpecializedList; 11 11 … … 162 162 var 163 163 Queue: TGQueue<Integer>; 164 I: Integer;165 164 begin 166 165 ListViewOutput.Clear; … … 183 182 procedure TMainForm.ButtonStreamByteClick(Sender: TObject); 184 183 var 185 Stream: T MemoryStreamByte;184 Stream: TGMemoryStream<Byte>; 186 185 I: Integer; 187 186 ByteArray: array of Byte; … … 190 189 ListViewOutput.Clear; 191 190 LabelTestName.Caption := 'TStreamByte test'; 192 Stream := T MemoryStreamByte.Create;191 Stream := TGMemoryStream<Byte>.Create; 193 192 with Stream do try 194 193 WriteOutput('Size := ', IntToStr(Stream.Size)); -
Generics/NativeGenerics/Units/GenericList.pas
r321 r322 38 38 procedure AddArray(Values: array of TItem); 39 39 procedure AddList(List: TGList<TItem>); 40 procedure AddListPart(List: TGList<TItem>; ItemIndex, ItemCount: TIndex); 40 41 procedure Assign(Source: TGList<TItem>); virtual; 41 42 procedure Clear; virtual; … … 48 49 property First: TItem read GetFirst write SetFirst; 49 50 procedure Fill(Start, Count: TIndex; Value: TItem); 50 function GetArray: TItemArray; 51 function GetArray(Index, ACount: TIndex): TItemArray; 52 procedure GetList(List: TGList<TItem>; Index, ACount: TIndex); 51 53 function Implode(Separator: string; Converter: TToStringConverter): string; 52 54 function IndexOf(Item: TItem; Start: TIndex = 0): TIndex; … … 161 163 end; 162 164 163 function TGList<TItem>.GetArray : TItemArray;165 function TGList<TItem>.GetArray(Index, ACount: TIndex): TItemArray; 164 166 var 165 167 I: Integer; 166 168 begin 167 SetLength(Result, Count);169 SetLength(Result, ACount); 168 170 I := 0; 169 171 while I < Count do begin 170 Result[I] := FItems[I]; 171 I := I + 1; 172 end; 172 Result[I] := FItems[Index + I]; 173 I := I + 1; 174 end; 175 end; 176 177 procedure TGList<TItem>.GetList(List: TGList; Index, ACount: TIndex); 178 begin 179 List.Clear; 180 List.AddListPart(Self, Index, ACount); 173 181 end; 174 182 … … 506 514 end; 507 515 516 procedure TGList<TItem>.AddListPart(List: TGList; ItemIndex, ItemCount: TIndex); 517 var 518 I: TIndex; 519 J: TIndex; 520 begin 521 I := Count; 522 J := ItemIndex; 523 Count := Count + ItemCount; 524 while I < Count do begin 525 Items[I] := List[J]; 526 I := I + 1; 527 J := J + 1; 528 end; 529 end; 530 508 531 procedure TGList<TItem>.Clear; 509 532 begin -
Generics/NativeGenerics/Units/GenericStream.pas
r320 r322 24 24 procedure Write(Item: TItem); virtual; abstract; 25 25 procedure WriteArray(Item: array of TItem); virtual; abstract; 26 procedure WriteList(List: TGList<TItem>); virtual; abstract; 26 27 function Read: TItem; virtual; abstract; 27 28 function ReadArray(Count: TIndex): TItemArray; virtual; abstract; … … 35 36 end; 36 37 38 TGMemoryStream<TItem> = class(TGStream<TItem>) 39 private 40 FList: TGList<TItem>; 41 FPosition: TIndex; 42 public 43 procedure Assign(Source: TGStream<TItem>); override; 44 procedure Write(Item: TItem); override; 45 procedure WriteArray(Values: array of TItem); override; 46 procedure WriteList(List: TGList<TItem>); override; 47 function Read: TItem; override; 48 function ReadArray(Count: TIndex): TItemArray; override; 49 function ReadList(List: TGList<TItem>; Count: TIndex): TIndex; 50 function Insert(Count: TIndex): Integer; override; 51 function Remove(Count: TIndex): Integer; override; 52 function Seek(Offset: TIndex; Origin: TSeekOrigin = soCurrent): TIndex; override; 53 constructor Create; override; 54 destructor Destroy; override; 55 property List: TGList<TItem> read FList; 56 end; 57 37 58 38 59 implementation 39 60 61 62 { TGStream } 40 63 41 64 procedure TGStream<TItem>.Assign(Source: TGStream<TItem>); … … 85 108 end; 86 109 110 { TMemoryStreamByte } 111 112 procedure TGMemoryStream<TItem>.Assign(Source: TGStream<TItem>); 113 begin 114 inherited; 115 if Source is TGMemoryStream<TItem> then begin 116 FList.Assign(TGMemoryStream<TItem>(Source).FList); 117 FPosition := TGMemoryStream<TItem>(Source).FPosition; 118 end; 119 end; 120 121 procedure TGMemoryStream<TItem>.Write(Item: TItem); 122 begin 123 if FList.Count < (FPosition + 1) then 124 FList.Count := FPosition + 1; 125 FList[FPosition] := Item; 126 Inc(FPosition); 127 end; 128 129 procedure TGMemoryStream<TItem>.WriteArray(Values: array of TItem); 130 begin 131 if FList.Count < (FPosition + Length(Values)) then 132 FList.Count := FPosition + Length(Values); 133 FList.ReplaceArray(FPosition, Values); 134 Inc(FPosition, Length(Values)); 135 end; 136 137 procedure TGMemoryStream<TItem>.WriteList(List: TGList<TItem>); 138 begin 139 FList.ReplaceList(FPosition, List); 140 end; 141 142 function TGMemoryStream<TItem>.Read: TItem; 143 begin 144 Result := FList[FPosition]; 145 Inc(FPosition); 146 end; 147 148 function TGMemoryStream<TItem>.ReadArray(Count: TIndex): TItemArray; 149 begin 150 Result := FList.GetArray(FPosition, Count); 151 end; 152 153 function TGMemoryStream<TItem>.ReadList(List: TGList<TItem>; Count: TIndex): TIndex; 154 begin 155 if (FPosition + Count) > FList.Count then 156 Count := FList.Count - FPosition; 157 FList.GetList(List, FPosition, Count); 158 Result := Count; 159 end; 160 161 function TGMemoryStream<TItem>.Insert(Count: TIndex): TIndex; 162 begin 163 FList.InsertCount(FPosition, Count); 164 Result := Count; 165 end; 166 167 function TGMemoryStream<TItem>.Remove(Count: TIndex): TIndex; 168 begin 169 Result := FList.Count - FPosition; 170 if Count < Result then Result := Count; 171 FList.DeleteItems(FPosition, Count); 172 end; 173 174 function TGMemoryStream<TItem>.Seek(Offset: TIndex; Origin: TSeekOrigin): TIndex; 175 begin 176 case Origin of 177 soBeginning: FPosition := Offset; 178 soCurrent: FPosition := FPosition + Offset; 179 soEnd: FPosition := FList.Count + Offset; 180 end; 181 if FPosition > FList.Count then FPosition := FList.Count; 182 if FPosition < 0 then FPosition := 0; 183 Result := FPosition; 184 end; 185 186 constructor TGMemoryStream<TItem>.Create; 187 begin 188 inherited; 189 FList := TGList<TItem>.Create; 190 end; 191 192 destructor TGMemoryStream<TItem>.Destroy; 193 begin 194 FList.Free; 195 inherited Destroy; 196 end; 197 198 87 199 end.
Note:
See TracChangeset
for help on using the changeset viewer.