четверг, 26 февраля 2015 г.

Containers 8. Deriving of specific atomic containers from abstract ones

Original in Russian: http://18delphi.blogspot.ru/2013/07/blog-post_8789.html

About containers. Table of contents

The previous series was here - http://18delphi.blogspot.com/2015/02/containers-7-abstract-containers-part-2.html

Now let us derive from abstract containers of the previous series – the specific ones. As yet – atomic ones.

So. As usual.

The model:

The code:

IntegerList.pas:

unit IntegerList;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// The library "SandBox"
// The unit: "IntegerList.pas"
// Native Delphi interfaces (.pas)
// Generated from UML model, root element: SimpleClass::Class Shared Delphi Sand Box::SandBox::FinalContainers::TIntegerList
//
// The list of Integer's
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
// ! Fully generated from the model. It is not allowed to edit manually. !
 
interface
 
uses
  Refcounted,
  Classes,
  l3PtrLoc
  ;
 
type
 _ItemType_ = Integer;
 _AtomicList_Parent_ = TRefcounted;
 {$Include AtomicList.imp.pas}
 TIntegerList = class(_AtomicList_)
  {* The list of Integer's }
 end;//TIntegerList
 
implementation
 
uses
  RTLConsts,
  l3MemorySizeUtils
  ;
 
type _Instance_R_ = TIntegerList;
type _AtomicList_R_ = TIntegerList;
 
{$Include AtomicList.imp.pas}
 
end.

ByteList.pas: 
unit ByteList;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// The library "SandBox"
// The unit: "ByteList.pas"
// Native Delphi interfaces (.pas)
// Generated from UML model, root element: SimpleClass::Class Shared Delphi Sand Box::SandBox::FinalContainers::TByteList
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
// ! Fully generated from the model. It is not allowed to edit manually. !
 
interface
 
uses
  Refcounted,
  Classes,
  l3PtrLoc
  ;
 
type
 _ItemType_ = Byte;
 _AtomicList_Parent_ = TRefcounted;
 {$Include AtomicList.imp.pas}
 TByteList = class(_AtomicList_)
 end;//TByteList
 
implementation
 
uses
  RTLConsts,
  l3MemorySizeUtils
  ;
 
type _Instance_R_ = TByteList;
type _AtomicList_R_ = TByteList;
 
{$Include AtomicList.imp.pas}
 
end.


Int64List.pas: 
unit Int64List;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// The library "SandBox"
// The unit: "Int64List.pas"
// Native Delphi interfaces (.pas)
// Generated from UML model, root element: SimpleClass::Class Shared Delphi Sand Box::SandBox::FinalContainers::TInt64List
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
// ! Fully generated from the model. It is not allowed to edit manually. !
 
interface
 
uses
  Refcounted,
  Classes,
  l3PtrLoc
  ;
 
type
 _ItemType_ = Int64;
 _AtomicList_Parent_ = TRefcounted;
 {$Include AtomicList.imp.pas}
 TInt64List = class(_AtomicList_)
 end;//TInt64List
 
implementation
 
uses
  RTLConsts,
  l3MemorySizeUtils
  ;
 
type _Instance_R_ = TInt64List;
type _AtomicList_R_ = TInt64List;
 
{$Include AtomicList.imp.pas}
 
end.

The tests (picked out of the thin air, nevertheless they have the right to live).

The model of the tests:

The code of the tests:

IntegerListTest.pas:

unit IntegerListTest;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// The library "SandBoxTest"
// The unit: "IntegerListTest.pas"
// Native Delphi interfaces (.pas)
// Generated from UML model, root element: TestCase::Class Shared Delphi Sand Box::SandBoxTest::FinalContainersTests::IntegerListTest
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
// ! Fully generated from the model. It is not allowed to edit manually. !
 
interface
 
uses
  TestFrameWork
  ;
 
type
 TIntegerListTest = class(TTestCase)
 published
 // published methods
   procedure DoIt;
   procedure TestTwoLists;
 end;//TIntegerListTest
 
implementation
 
uses
  IntegerList,
  SysUtils
  ;
 
// start class TIntegerListTest
 
procedure TIntegerListTest.DoIt;
//#UC START# *51DEB319037C_51DEB2FA00B0_var*
const
 cCount = 1000;
var
 l_List : TIntegerList;
 l_Count : IndexType;
 l_Index : IndexType;
//#UC END# *51DEB319037C_51DEB2FA00B0_var*
begin
//#UC START# *51DEB319037C_51DEB2FA00B0_impl*
 l_List := TIntegerList.Create;
 try
  l_List.Count := cCount;
  Check(l_List.Count = cCount);
  Check(l_List.Capacity >= cCount);
 
  for l_Index := 0 to l_List.Count - 1 do
   Check(l_List[l_Index] = 0);
 
  l_Count := Random(cCount);
  l_List.Count := l_Count;
  Check(l_List.Count = l_Count, Format('We’ve allocated %d items. Count = %d', [l_Count, l_List.Count]));
  Check(l_List.Capacity >= l_Count, Format('We’ve allocated %d items. Capacity = %d', [l_Count, l_List.Capacity]));
 
  for l_Index := 0 to l_List.Count - 1 do
   Check(l_List[l_Index] = 0);
    
 finally
  FreeAndNil(l_List);
 end;//try..finally
//#UC END# *51DEB319037C_51DEB2FA00B0_impl*
end;//TIntegerListTest.DoIt
 
procedure TIntegerListTest.TestTwoLists;
//#UC START# *51DED6FC03C1_51DEB2FA00B0_var*
const
 cCount = 1000;
var
 l_A : TIntegerList;
 l_B : TIntegerList;
 l_Index : IndexType;
 l_Value : Integer;
//#UC END# *51DED6FC03C1_51DEB2FA00B0_var*
begin
//#UC START# *51DED6FC03C1_51DEB2FA00B0_impl*
 l_A := TIntegerList.Create;
 try
  l_B := TIntegerList.Create;
  try
   l_A.Count := cCount;
   for l_Index := 0 to l_A.Count - 1 do
   begin
    l_Value := Random(1000);
    l_A[l_Index] := l_Value;
    Check(l_A[l_Index] = l_Value);
   end;//for l_Index
 
   l_B.Count := l_A.Count;
   for l_Index := 0 to l_A.Count - 1 do
   begin
    l_B[l_Index] := l_A[l_Index];
   end;//for l_Index
 
   for l_Index := 0 to l_A.Count - 1 do
   begin
    Check(l_B[l_Index] = l_A[l_Index]);
   end;//for l_Index
  finally
   FreeAndNil(l_B);
  end;//try..finally
 finally
  FreeAndNil(l_A);
 end;//try..finally
//#UC END# *51DED6FC03C1_51DEB2FA00B0_impl*
end;//TIntegerListTest.TestTwoLists
 
initialization
 TestFramework.RegisterTest(TIntegerListTest.Suite);
 
end.


ByteListTest.pas: 
unit ByteListTest;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// The library "SandBoxTest"
// The unit: "ByteListTest.pas"
// Native Delphi interfaces (.pas)
// Generated from UML model, root element: TestCase::Class Shared Delphi Sand Box::SandBoxTest::FinalContainersTests::ByteListTest
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
// ! Fully generated from the model. It is not allowed to edit manually. !
 
interface
 
uses
  TestFrameWork
  ;
 
type
 TByteListTest = class(TTestCase)
 published
 // published methods
   procedure DoIt;
 end;//TByteListTest
 
implementation
 
uses
  ByteList,
  SysUtils
  ;
 
// start class TByteListTest
 
procedure TByteListTest.DoIt;
//#UC START# *51DEE6960378_51DEE67C003A_var*
const
 cCount = 1000;
var
 l_List : TByteList;
 l_Count : IndexType;
 l_Index : IndexType;
//#UC END# *51DEE6960378_51DEE67C003A_var*
begin
//#UC START# *51DEE6960378_51DEE67C003A_impl*
 l_List := TByteList.Create;
 try
  l_List.Count := cCount;
  Check(l_List.Count = cCount);
  Check(l_List.Capacity >= cCount);
 
  for l_Index := 0 to l_List.Count - 1 do
   Check(l_List[l_Index] = 0);
 
  l_Count := Random(cCount);
  l_List.Count := l_Count;
  Check(l_List.Count = l_Count, Format('We’ve allocated %d items. Count = %d', [l_Count, l_List.Count]));
  Check(l_List.Capacity >= l_Count, Format('We’ve allocated %d items. Capacity = %d', [l_Count, l_List.Capacity]));
 
  for l_Index := 0 to l_List.Count - 1 do
   Check(l_List[l_Index] = 0);
    
 finally
  FreeAndNil(l_List);
 end;//try..finally
//#UC END# *51DEE6960378_51DEE67C003A_impl*
end;//TByteListTest.DoIt
 
initialization
 TestFramework.RegisterTest(TByteListTest.Suite);
 
end.


Int64ListTest.pas: 
unit Int64ListTest;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// The library "SandBoxTest"
// The unit: "Int64ListTest.pas"
// Native Delphi interfaces (.pas)
// Generated from UML model, root element: TestCase::Class Shared Delphi Sand Box::SandBoxTest::FinalContainersTests::Int64ListTest
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
// ! Fully generated from the model. It is not allowed to edit manually. !
 
interface
 
uses
  TestFrameWork
  ;
 
type
 TInt64ListTest = class(TTestCase)
 published
 // published methods
   procedure DoIt;
 end;//TInt64ListTest
 
implementation
 
uses
  Int64List,
  SysUtils
  ;
 
// start class TInt64ListTest
 
procedure TInt64ListTest.DoIt;
//#UC START# *51DEE90202A8_51DEE8E9025A_var*
const
 cCount = 1000;
var
 l_List : TInt64List;
 l_Count : IndexType;
 l_Index : IndexType;
//#UC END# *51DEE90202A8_51DEE8E9025A_var*
begin
//#UC START# *51DEE90202A8_51DEE8E9025A_impl*
 l_List := TInt64List.Create;
 try
  l_List.Count := cCount;
  Check(l_List.Count = cCount);
  Check(l_List.Capacity >= cCount);
 
  for l_Index := 0 to l_List.Count - 1 do
   Check(l_List[l_Index] = 0);
 
  l_Count := Random(cCount);
  l_List.Count := l_Count;
  Check(l_List.Count = l_Count, Format('We’ve allocated %d items. Count = %d', [l_Count, l_List.Count]));
  Check(l_List.Capacity >= l_Count, Format('We’ve allocated %d items. Capacity = %d', [l_Count, l_List.Capacity]));
 
  for l_Index := 0 to l_List.Count - 1 do
   Check(l_List[l_Index] = 0);
    
 finally
  FreeAndNil(l_List);
 end;//try..finally
//#UC END# *51DEE90202A8_51DEE8E9025A_impl*
end;//TInt64ListTest.DoIt
 
initialization
 TestFramework.RegisterTest(TInt64ListTest.Suite);
 
end.


The code is here - http://sourceforge.net/p/rumtmarc/code-0/19/tree/trunk/Blogger/SandBox and http://sourceforge.net/p/rumtmarc/code-0/19/tree/trunk/Blogger/SandBoxTest

Комментариев нет:

Отправить комментарий