Browse Source

* unmerged r23341 on Sven's request

git-svn-id: branches/fixes_2_6@26582 -
marco 11 years ago
parent
commit
daf9cebde1
1 changed files with 26 additions and 77 deletions
  1. 26 77
      packages/fcl-stl/src/gvector.pp

+ 26 - 77
packages/fcl-stl/src/gvector.pp

@@ -17,57 +17,33 @@ unit gvector;
 interface
 interface
 
 
 type
 type
-
-  { TVector }
-
-  generic TVector<T> = class
+  generic TVector<T>=class
   private
   private
   type
   type
-    PT = ^ T;
-    TArr = array of T;
+    PT=^ T;
+    TArr=array of T;
   var
   var
     FCapacity:SizeUInt;
     FCapacity:SizeUInt;
     FDataSize:SizeUInt;
     FDataSize:SizeUInt;
     FData:TArr;
     FData:TArr;
 
 
-    procedure SetValue(Position: SizeUInt; const Value: T); inline;
-    function GetValue(Position: SizeUInt):T; inline;
-    function GetMutable(Position: SizeUInt):PT; inline;
-    procedure IncreaseCapacity; inline;
-
-  const
-    // todo: move these constants to implementation when
-    // mantis #0021310 will be fixed.
-    SVectorPositionOutOfRange      = 'Vector position out of range';
-    SAccessingElementOfEmptyVector = 'Accessing element of empty vector';
-
-  type
-    TVectorEnumerator = class
-    private
-      FVector: TVector;
-      FPosition: Integer;
-    public
-      constructor Create(AVector: TVector);
-      function GetCurrent: T; inline;
-      function MoveNext: Boolean; inline;
-      property Current: T read GetCurrent;
-    end;
-
+    procedure SetValue(Position:SizeUInt; Value:T);inline;
+    function GetValue(Position:SizeUInt):T;inline;
+    function GetMutable(Position:SizeUInt):PT;inline;
+    procedure IncreaseCapacity;inline;
   public
   public
     constructor Create;
     constructor Create;
-    function Size: SizeUInt; inline;
-    procedure PushBack(const Value: T); inline;
-    procedure PopBack; inline;
-    function IsEmpty: boolean; inline;
-    procedure Insert(Position: SizeUInt; const Value: T); inline;
-    procedure Erase(Position: SizeUInt); inline;
-    procedure Clear; inline;
-    function Front: T; inline;
-    function Back: T; inline;
-    procedure Reserve(Num: SizeUInt); inline;
-    procedure Resize(Num: SizeUInt); inline;
-
-    function GetEnumerator: TVectorEnumerator;
+    function Size:SizeUInt;inline;
+    procedure PushBack(Value:T);inline;
+    procedure PopBack;inline;
+    function IsEmpty:boolean;inline;
+    procedure Insert(Position:SizeUInt; Value:T);inline;
+    procedure Erase(Position:SizeUInt);inline;
+    procedure Clear;inline;
+    function Front:T;inline;
+    function Back:T;inline;
+    procedure Reserve(Num:SizeUInt);inline;
+    procedure Resize(Num:SizeUInt);inline;
 
 
     property Items[i : SizeUInt]: T read getValue write setValue; default;
     property Items[i : SizeUInt]: T read getValue write setValue; default;
     property Mutable[i : SizeUInt]: PT read getMutable;
     property Mutable[i : SizeUInt]: PT read getMutable;
@@ -75,61 +51,39 @@ end;
 
 
 implementation
 implementation
 
 
-{ TVector.TVectorEnumerator }
-
-constructor TVector.TVectorEnumerator.Create(AVector: TVector);
-begin
-  FVector := AVector;
-  FPosition := -1;
-end;
-
-function TVector.TVectorEnumerator.GetCurrent: T;
-begin
-  Result := FVector[FPosition];
-end;
-
-function TVector.TVectorEnumerator.MoveNext: Boolean;
-begin
-  Result := FPosition < FVector.Size - 1;
-  if Result then
-    inc(FPosition);
-end;
-
-{ TVector }
-
 constructor TVector.Create();
 constructor TVector.Create();
 begin
 begin
   FCapacity:=0;
   FCapacity:=0;
   FDataSize:=0;
   FDataSize:=0;
 end;
 end;
 
 
-procedure TVector.SetValue(Position: SizeUInt; const Value: T);
+procedure TVector.SetValue(Position:SizeUInt; Value:T);inline;
 begin
 begin
-  Assert(position < size, SVectorPositionOutOfRange);
+  Assert(position < size, 'Vector position out of range');
   FData[Position]:=Value;
   FData[Position]:=Value;
 end;
 end;
 
 
 function TVector.GetValue(Position:SizeUInt):T;inline;
 function TVector.GetValue(Position:SizeUInt):T;inline;
 begin
 begin
-  Assert(position < size, SVectorPositionOutOfRange);
+  Assert(position < size, 'Vector position out of range');
   GetValue:=FData[Position];
   GetValue:=FData[Position];
 end;
 end;
 
 
 function TVector.GetMutable(Position:SizeUInt):PT;inline;
 function TVector.GetMutable(Position:SizeUInt):PT;inline;
 begin
 begin
-  Assert(position < size, SVectorPositionOutOfRange);
+  Assert(position < size, 'Vector position out of range');
   GetMutable:=@FData[Position];
   GetMutable:=@FData[Position];
 end;
 end;
 
 
 function TVector.Front():T;inline;
 function TVector.Front():T;inline;
 begin
 begin
-  Assert(size > 0, SAccessingElementOfEmptyVector);
+  Assert(size > 0, 'Accessing element of empty vector');
   Front:=FData[0];
   Front:=FData[0];
 end;
 end;
 
 
 function TVector.Back():T;inline;
 function TVector.Back():T;inline;
 begin
 begin
-  Assert(size > 0, SAccessingElementOfEmptyVector);
+  Assert(size > 0, 'Accessing element of empty vector');
   Back:=FData[FDataSize-1];
   Back:=FData[FDataSize-1];
 end;
 end;
 
 
@@ -146,7 +100,7 @@ begin
     IsEmpty:=false;
     IsEmpty:=false;
 end;
 end;
 
 
-procedure TVector.PushBack(const Value: T);
+procedure TVector.PushBack(Value:T);inline;
 begin
 begin
   if FDataSize=FCapacity then
   if FDataSize=FCapacity then
     IncreaseCapacity;
     IncreaseCapacity;
@@ -163,18 +117,13 @@ begin
   SetLength(FData, FCapacity);
   SetLength(FData, FCapacity);
 end;
 end;
 
 
-function TVector.GetEnumerator: TVectorEnumerator;
-begin
-  Result := TVectorEnumerator.Create(self);
-end;
-
 procedure TVector.PopBack();inline;
 procedure TVector.PopBack();inline;
 begin
 begin
   if FDataSize>0 then
   if FDataSize>0 then
     FDataSize:=FDataSize-1;
     FDataSize:=FDataSize-1;
 end;
 end;
 
 
-procedure TVector.Insert(Position: SizeUInt; const Value: T);
+procedure TVector.Insert(Position:SizeUInt; Value: T);inline;
 var i:SizeUInt;
 var i:SizeUInt;
 begin
 begin
   pushBack(Value);
   pushBack(Value);