Original in Russian: http://18delphi.blogspot.ru/2013/07/2_18.html
About containers. Table of contents
The previous series was here - http://18delphi.blogspot.com/2015/02/containers-8-deriving-of-specific.html
And here - http://18delphi.blogspot.com/2015/02/containers-7-abstract-containers-part-2.html
Now let’s look how special containers have changed.
The model:
The code:
StandardAtomicList.imp.pas:
IUnknownRefListTest.pas:
About containers. Table of contents
The previous series was here - http://18delphi.blogspot.com/2015/02/containers-8-deriving-of-specific.html
And here - http://18delphi.blogspot.com/2015/02/containers-7-abstract-containers-part-2.html
Now let’s look how special containers have changed.
The model:
The code:
StandardAtomicList.imp.pas:
StandardAtomicList.imp.pas: {$IfNDef StandardAtomicList_imp} //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // The library "SandBox" // The unit: "StandardAtomicList.imp.pas" // Native Delphi interfaces (.pas) // Generated from UML model, root element: Impurity::Class Shared Delphi Sand Box::SandBox::FinalContainers::StandardAtomicList // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// {$Define StandardAtomicList_imp} _AtomicList_Parent_ = TRefcounted; {$Include ..\SandBox\AtomicList.imp.pas} _StandardAtomicList_ = {mixin} class(_AtomicList_) end;//_StandardAtomicList_ {$Else StandardAtomicList_imp} {$Include ..\SandBox\AtomicList.imp.pas} {$EndIf StandardAtomicList_imp} 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 // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// {$Include ..\SandBox\sbDefine.inc} interface uses Refcounted, Classes, l3PtrLoc ; type _ItemType_ = Integer; {$Include ..\SandBox\StandardAtomicList.imp.pas} TIntegerList = class(_StandardAtomicList_) {* The list of Integer's } end;//TIntegerList implementation uses RTLConsts, l3MemorySizeUtils ; {$Include ..\SandBox\StandardAtomicList.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 // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// {$Include ..\SandBox\sbDefine.inc} interface uses Refcounted, Classes, l3PtrLoc ; type _ItemType_ = Int64; {$Include ..\SandBox\StandardAtomicList.imp.pas} TInt64List = class(_StandardAtomicList_) end;//TInt64List implementation uses RTLConsts, l3MemorySizeUtils ; {$Include ..\SandBox\StandardAtomicList.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 // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// {$Include ..\SandBox\sbDefine.inc} interface uses Refcounted, Classes, l3PtrLoc ; type _ItemType_ = Byte; {$Include ..\SandBox\StandardAtomicList.imp.pas} TByteList = class(_StandardAtomicList_) end;//TByteList implementation uses RTLConsts, l3MemorySizeUtils ; {$Include ..\SandBox\StandardAtomicList.imp.pas} end. IUnknownRefList.pas: unit IUnknownRefList; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // The library "SandBox" // The unit: "IUnknownRefList.pas" // Native Delphi interfaces (.pas) // Generated from UML model, root element: SimpleClass::Class Shared Delphi Sand Box::SandBox::FinalContainers::TIUnknownRefList // // The list of the REFERENCES to IUnknown // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// {$Include ..\SandBox\sbDefine.inc} interface uses Refcounted, Classes, l3PtrLoc ; type _ItemType_ = IUnknown; _InterfaceRefList_Parent_ = TRefcounted; {$Include ..\SandBox\InterfaceRefList.imp.pas} TIUnknownRefList = class(_InterfaceRefList_) {* The list of the REFERENCES to IUnknown } end;//TIUnknownRefList implementation uses RTLConsts, l3MemorySizeUtils ; {$Include ..\SandBox\InterfaceRefList.imp.pas} end. IUnknownPtrList.pas: unit IUnknownPtrList; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // The library "SandBox" // The unit: "IUnknownPtrList.pas" // Native Delphi interfaces (.pas) // Generated from UML model, root element: SimpleClass::Class Shared Delphi Sand Box::SandBox::FinalContainers::TIUnknownPtrList // // The list of the POINTERS to IUnknown // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// {$Include ..\SandBox\sbDefine.inc} interface uses Refcounted, Classes, l3PtrLoc ; type _ItemType_ = IUnknown; _InterfacePtrList_Parent_ = TRefcounted; {$Include ..\SandBox\InterfacePtrList.imp.pas} TIUnknownPtrList = class(_InterfacePtrList_) {* The list of the POINTERS to IUnknown } end;//TIUnknownPtrList implementation uses RTLConsts, l3MemorySizeUtils ; {$Include ..\SandBox\InterfacePtrList.imp.pas} end. And the tests. The model: pic2 pic3 The code: ListTest.imp.pas: {$IfNDef ListTest_imp} //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // The library "SandBoxTest" // The unit: "ListTest.imp.pas" // Native Delphi interfaces (.pas) // Generated from UML model, root element: TestCaseMixIn::Class Shared Delphi Sand Box::SandBoxTest::FinalContainersTests::ListTest // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// {$Define ListTest_imp} {$If defined(nsTest)} _ListTest_ = class(TTestCase) protected // protected methods function CreateList: _ListType_; {* Creates the list for testing } end;//_ListTest_ {$IfEnd} //nsTest {$Else ListTest_imp} {$If defined(nsTest)} // start class _ListTest_ function _ListTest_.CreateList: _ListType_; //#UC START# *51E80E0D030D_51E80DD30125_var* //#UC END# *51E80E0D030D_51E80DD30125_var* begin //#UC START# *51E80E0D030D_51E80DD30125_impl* Result := _ListType_.Create; //#UC END# *51E80E0D030D_51E80DD30125_impl* end;//_ListTest_.CreateList {$IfEnd} //nsTest {$EndIf ListTest_imp} AtomicListTest.imp.pas: {$IfNDef AtomicListTest_imp} //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // The library "SandBoxTest" // The unit: "AtomicListTest.imp.pas" // Native Delphi interfaces (.pas) // Generated from UML model, root element: TestCaseMixIn::Class Shared Delphi Sand Box::SandBoxTest::FinalContainersTests::AtomicListTest // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// {$Define AtomicListTest_imp} {$If defined(nsTest)} {$Include ..\SandBox\ListTest.imp.pas} _AtomicListTest_ = class(_ListTest_) private // private methods function RandomItem: _ItemType_; published // published methods procedure DoIt; procedure TestTwoLists; procedure TestInsert; procedure TestInsertAt0; procedure DeleteTest; {* The test of item deleting } procedure AddTest; {* The test of item adding } procedure RemoveTest; {* The test of item deleting by the value } end;//_AtomicListTest_ {$IfEnd} //nsTest {$Else AtomicListTest_imp} {$If defined(nsTest)} {$Include ..\SandBox\ListTest.imp.pas} // start class _AtomicListTest_ function _AtomicListTest_.RandomItem: _ItemType_; //#UC START# *51E6ADE0016E_51E03FC80111_var* var l_V : Cardinal; //#UC END# *51E6ADE0016E_51E03FC80111_var* begin //#UC START# *51E6ADE0016E_51E03FC80111_impl* l_V := Random(1000); if (l_V > High(_ItemType_)) then Result := High(_ItemType_) else Result := l_V; //#UC END# *51E6ADE0016E_51E03FC80111_impl* end;//_AtomicListTest_.RandomItem procedure _AtomicListTest_.DoIt; //#UC START# *51DEB319037C_51E03FC80111_var* const cCount = 1000; var l_List : _ListType_; l_Count : IndexType; l_Index : IndexType; //#UC END# *51DEB319037C_51E03FC80111_var* begin //#UC START# *51DEB319037C_51E03FC80111_impl* l_List := CreateList; 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_51E03FC80111_impl* end;//_AtomicListTest_.DoIt procedure _AtomicListTest_.TestTwoLists; //#UC START# *51DED6FC03C1_51E03FC80111_var* const cCount = 1000; var l_A : _ListType_; l_B : _ListType_; l_Index : IndexType; l_Value : _ItemType_; //#UC END# *51DED6FC03C1_51E03FC80111_var* begin //#UC START# *51DED6FC03C1_51E03FC80111_impl* l_A := CreateList; try l_B := CreateList; try l_A.Count := cCount; for l_Index := 0 to l_A.Count - 1 do begin l_Value := RandomItem; 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_51E03FC80111_impl* end;//_AtomicListTest_.TestTwoLists procedure _AtomicListTest_.TestInsert; //#UC START# *51E6AC74038B_51E03FC80111_var* const cCount = 1000; var l_List : _ListType_; l_Value : _ItemType_; l_Index : IndexType; //#UC END# *51E6AC74038B_51E03FC80111_var* begin //#UC START# *51E6AC74038B_51E03FC80111_impl* l_List := CreateList; try for l_Index := 0 to cCount do begin l_Value := RandomItem; l_List.Insert(l_Index, l_Value); Check(l_List.Count = l_Index + 1); Check(l_List[l_Index] = l_Value); end;//for l_Index finally FreeAndNil(l_List); end;//try..finally //#UC END# *51E6AC74038B_51E03FC80111_impl* end;//_AtomicListTest_.TestInsert procedure _AtomicListTest_.TestInsertAt0; //#UC START# *51E6B4260008_51E03FC80111_var* const cCount = 1000; var l_List : _ListType_; l_Value : _ItemType_; l_Index : IndexType; //#UC END# *51E6B4260008_51E03FC80111_var* begin //#UC START# *51E6B4260008_51E03FC80111_impl* l_List := CreateList; try for l_Index := 0 to cCount do begin l_Value := RandomItem; l_List.Insert(0, l_Value); Check(l_List.Count = l_Index + 1); Check(l_List[0] = l_Value); end;//for l_Index finally FreeAndNil(l_List); end;//try..finally //#UC END# *51E6B4260008_51E03FC80111_impl* end;//_AtomicListTest_.TestInsertAt0 procedure _AtomicListTest_.DeleteTest; //#UC START# *51E7F6EF0285_51E03FC80111_var* const cCount = 1000; var l_List : _ListType_; l_Value : _ItemType_; l_Index : IndexType; l_Prev : _ItemType_; //#UC END# *51E7F6EF0285_51E03FC80111_var* begin //#UC START# *51E7F6EF0285_51E03FC80111_impl* l_List := CreateList; try for l_Index := 0 to cCount do begin l_Value := RandomItem; l_List.Insert(l_Index, l_Value); Check(l_List.Count = l_Index + 1); Check(l_List[l_Index] = l_Value); end;//for l_Index while not l_List.Empty do begin l_Index := Random(l_List.Count - 1); if (l_Index < l_List.Count - 1) then begin l_Prev := l_List[l_Index + 1]; l_List.Delete(l_Index); if l_List.Empty then break; Check(l_List[l_Index] = l_Prev); end//l_Index < l_List.Count - 1 else begin if (l_Index = 0) then l_List.Delete(l_Index) else begin l_Prev := l_List[l_Index - 1]; l_List.Delete(l_Index); if l_List.Empty then break; Check(l_List[l_Index - 1] = l_Prev); end;//l_Index = 0 end;//l_Index < l_List.Count - 1 end;//while l_List.Count finally FreeAndNil(l_List); end;//try..finally //#UC END# *51E7F6EF0285_51E03FC80111_impl* end;//_AtomicListTest_.DeleteTest procedure _AtomicListTest_.AddTest; //#UC START# *51E80DC50154_51E03FC80111_var* const cCount = 1000; var l_List : _ListType_; l_Value : _ItemType_; l_Index : IndexType; //#UC END# *51E80DC50154_51E03FC80111_var* begin //#UC START# *51E80DC50154_51E03FC80111_impl* l_List := CreateList; try for l_Index := 0 to cCount do begin l_Value := RandomItem; l_List.Add(l_Value); Check(l_List.Last = l_Value); end;//for l_Index finally FreeAndNil(l_List); end;//try..finally //#UC END# *51E80DC50154_51E03FC80111_impl* end;//_AtomicListTest_.AddTest procedure _AtomicListTest_.RemoveTest; //#UC START# *51E8127802AF_51E03FC80111_var* const cCount = 1000; var l_List : _ListType_; l_Value : _ItemType_; l_Index : IndexType; //#UC END# *51E8127802AF_51E03FC80111_var* begin //#UC START# *51E8127802AF_51E03FC80111_impl* l_List := CreateList; try for l_Index := 0 to cCount do begin l_Value := RandomItem; l_List.Add(l_Value); Check(l_List.Last = l_Value); end;//for l_Index while not l_List.Empty do begin l_Value := RandomItem; l_List.Remove(l_Value); end;//while not finally FreeAndNil(l_List); end;//try..finally //#UC END# *51E8127802AF_51E03FC80111_impl* end;//_AtomicListTest_.RemoveTest {$IfEnd} //nsTest {$EndIf AtomicListTest_imp}
IUnknownRefListTest.pas:
unit IUnknownRefListTest; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // The library "SandBoxTest" // The unit: "IUnknownRefListTest.pas" // Native Delphi interfaces (.pas) // Generated from UML model, root element: TestCase::Class Shared Delphi Sand Box::SandBoxTest::FinalContainersTests::IUnknownRefListTest // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// {$Include ..\SandBox\sbtDefine.inc} interface {$If defined(nsTest)} uses TestFrameWork, IUnknownRefList ; {$IfEnd} //nsTest {$If defined(nsTest)} type _ListType_ = TIUnknownRefList; {$Include ..\SandBox\ListTest.imp.pas} TIUnknownRefListTest = class(_ListTest_) published // published methods procedure DoIt; end;//TIUnknownRefListTest {$IfEnd} //nsTest implementation {$If defined(nsTest)} uses SysUtils ; {$IfEnd} //nsTest {$If defined(nsTest)} {$Include ..\SandBox\ListTest.imp.pas} // start class TIUnknownRefListTest procedure TIUnknownRefListTest.DoIt; //#UC START# *51E80B2F02CF_51E80B08039E_var* var l_List : _ListType_; //#UC END# *51E80B2F02CF_51E80B08039E_var* begin //#UC START# *51E80B2F02CF_51E80B08039E_impl* l_List := CreateList; try // - For now we do nothing finally FreeAndNil(l_List); end;//try..finally //#UC END# *51E80B2F02CF_51E80B08039E_impl* end;//TIUnknownRefListTest.DoIt {$IfEnd} //nsTest initialization TestFramework.RegisterTest(TIUnknownRefListTest.Suite); end.
Комментариев нет:
Отправить комментарий