home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1997 May
/
Pcwk0597.iso
/
delphi
/
tstrclas.lzh
/
CONTAINR.INT
< prev
next >
Wrap
Text File
|
1995-11-11
|
10KB
|
241 lines
UNIT Containr;
{ :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: }
{ Version 1.4 }
{ :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: }
INTERFACE
{ :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: }
USES
Classes,
SysUtils,
WinTypes,
WinProcs;
{ :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: }
CONST
ce_OK = 0; { status OK }
ce_IdxLtZero = 1; { Index parameter value less than zero }
ce_IdxGtCount = 2; { Index parameter value greater than count }
ce_Empty = 3; { trying to put or del an item in
an empty container }
ce_NewCapacLTCount = 4; { new capacity less than count }
ce_GlobalAllocFailed = 5; { global alloc failed }
ce_GlobalReAllocFailed = 6; { globalrealloc failed }
ce_GlobalLockFailed = 7; { globallock failed }
ce_IdxExceedsCapac = 8; { idx exceeds pre-defined capacity }
ce_AddFailedOnSort = 9;
ce_PutOnSort = 10;
ce_DuplicateItem = 11;
ce_InvalidItemRange = 12;
ce_InvalidNewCount = 13;
ce_SortInPlace = 14;
ce_SearchError = 15;
ce_Last = ce_SearchError;
TYPE
TCompareFunc = FUNCTION(VAR Ptr1,Ptr2) : INTEGER;
PBigByteArray = ^TBigByteArray;
TBigByteArray = array[0..65519] of BYTE;
TContainerSortType = (sortNone,sortAscending,sortDescending);
TBaseContainer = CLASS(TObject)
PRIVATE
FLocal : PBigByteArray; { for mem < 64K }
FMemH : THandle; { for mem > 64K }
FAddress : Pointer; { for mem > 64K }
FCount : LONGINT; { number of items in container }
FCapacity : LONGINT; { current capacity }
FDelta : LONGINT; { capacity increase }
FGrowAsRequired : BOOLEAN; { allow capacity to grow }
FSort : TContainerSortType; { sorting? }
FDuplicates : TDuplicates;
FItemSize : WORD; { size of item in list mem block }
FCompareFunc : TCompareFunc;
{ private methods }
FUNCTION AddItem(VAR Item) : LONGINT;
PROCEDURE FillItem(Idx : LONGINT; B : BYTE);
FUNCTION FindItem(Idx : LONGINT; VAR Item) : BOOLEAN;
FUNCTION GetItemAddress(Idx : LONGINT) : POINTER;
FUNCTION ItemIsNull(Idx : LONGINT) : BOOLEAN;
PROCEDURE MoveItem(StartIdx,TargetIdx,TotalIdx : LONGINT);
FUNCTION MemPtr(Idx: LONGINT) : POINTER;
PROCEDURE PutItem(Idx : LONGINT; VAR Item);
PROCEDURE QuickSort(L, R: LONGINT);
PROCEDURE ReportError(ErrorId : INTEGER; Idx : LONGINT);
PROCEDURE SetCapacity(NewCapacity: LONGINT);
PROCEDURE SetCount(NewCount : LONGINT);
PROCEDURE SetSort(NewSortType : TContainerSortType);
FUNCTION ValidIdx(Idx: LONGINT) : BOOLEAN;
PROTECTED
FUNCTION Compare(VAR Ptr1,Ptr2) : INTEGER; VIRTUAL;
PROCEDURE FreeItem(Item : POINTER); VIRTUAL;
PROCEDURE Grow;
PROCEDURE GrowBy(ExtraCapacity : LONGINT);
PROCEDURE GrowTo(NewCapacity : LONGINT);
FUNCTION InsertItem(Idx : LONGINT; VAR Item) : LONGINT;
FUNCTION Search(VAR AnItem; VAR Idx : LONGINT) : BOOLEAN; VIRTUAL;
PROCEDURE SortInPlace; VIRTUAL;
PUBLIC
{ constructors }
CONSTRUCTOR Create; VIRTUAL;
{ destructors }
DESTRUCTOR Destroy; OVERRIDE;
{ methods }
PROCEDURE Clear; VIRTUAL;
PROCEDURE Delete(Idx : LONGINT); VIRTUAL;
PROCEDURE DeleteAll; VIRTUAL;
PROCEDURE DeleteBlock(SIdx,EIdx : LONGINT);
PROCEDURE Exchange(Idx1,Idx2: LONGINT); VIRTUAL;
FUNCTION InsertBlock(Idx,Number : LONGINT) : LONGINT; VIRTUAL;
PROCEDURE Move(CurIdx, NewIdx: LONGINT); VIRTUAL;
PROCEDURE Pack; VIRTUAL;
PROCEDURE RemoveAll;
{ properties }
PROPERTY Capacity: LONGINT READ FCapacity WRITE SetCapacity;
PROPERTY Count: LONGINT READ FCount;
PROPERTY Delta : LONGINT READ FDelta WRITE FDelta;
PROPERTY Duplicates : TDuplicates READ FDuplicates WRITE FDuplicates;
PROPERTY GrowAsRequired : BOOLEAN READ FGrowAsRequired WRITE FGrowAsRequired;
PROPERTY Sort : TContainerSortType READ FSort WRITE SetSort;
PROPERTY CompareFunc : TCompareFunc READ FCompareFunc WRITE FCompareFunc;
END;
TObjectContainer = CLASS(TBaseContainer)
PRIVATE
FOwn : BOOLEAN; { own pointer/objects }
FUNCTION GetPtr(Idx : LONGINT) : POINTER;
PROCEDURE PutPtr(Idx : LONGINT; Item : POINTER);
PROTECTED
PROCEDURE FreeItem(Item : POINTER); OVERRIDE;
PUBLIC
{ constructors }
CONSTRUCTOR Create; OVERRIDE;
{ methods }
FUNCTION Add(Item: POINTER): LONGINT; VIRTUAL;
FUNCTION Append(Item : POINTER) : LONGINT; VIRTUAL;
FUNCTION First: POINTER; VIRTUAL;
FUNCTION FirstThat(Test: Pointer): Pointer;
FUNCTION FirstThatIdx(Test: Pointer): Pointer;
PROCEDURE ForEach(Action: Pointer);
PROCEDURE ForEachIdx(Action: Pointer);
FUNCTION Includes(Item : POINTER; VAR Idx : LONGINT) : BOOLEAN;
FUNCTION IndexOf(Item: POINTER): LONGINT; VIRTUAL;
FUNCTION Insert(Idx: LONGINT; Item: POINTER) : LONGINT; VIRTUAL;
FUNCTION Last: POINTER;
FUNCTION LastThat(Test: Pointer): Pointer;
FUNCTION LastThatIdx(Test: Pointer): Pointer;
FUNCTION Prepend(Item : POINTER) : LONGINT; VIRTUAL;
FUNCTION Remove(Item: POINTER): LONGINT; VIRTUAL;
{ properties }
PROPERTY Items[Idx : LONGINT]: POINTER READ GetPtr WRITE PutPtr;
PROPERTY Own : BOOLEAN READ Fown WRITE FOwn;
END;
TRecordContainer = CLASS(TObjectContainer)
PRIVATE
FRecordSize : WORD; { item record size }
PROTECTED
PROCEDURE FreeItem(Item : POINTER); OVERRIDE;
PUBLIC
{ constructors }
CONSTRUCTOR Create(ARecSize : WORD);
END;
TPCharContainer = CLASS(TObjectContainer)
PROTECTED
PROCEDURE FreeItem(Item : POINTER); OVERRIDE;
END;
TIntegerContainer = CLASS(TBaseContainer)
PRIVATE
FUNCTION GetInteger(Idx : LONGINT) : INTEGER;
PROCEDURE PutInteger(Idx : LONGINT; N : INTEGER);
PROTECTED
FUNCTION Compare(VAR Ptr1,Ptr2) : INTEGER; OVERRIDE;
PUBLIC
{ constructors }
CONSTRUCTOR Create;
{ methods }
FUNCTION Add(Item: INTEGER): LONGINT; VIRTUAL;
FUNCTION Append(Item : INTEGER) : LONGINT; VIRTUAL;
FUNCTION First: INTEGER; VIRTUAL;
FUNCTION Includes(Item : INTEGER; VAR Idx : LONGINT) : BOOLEAN;
FUNCTION Insert(Idx: LONGINT; Item: INTEGER) : LONGINT; VIRTUAL;
FUNCTION Last: INTEGER;
FUNCTION Prepend(Item : INTEGER) : LONGINT; VIRTUAL;
FUNCTION Remove(Item: INTEGER): LONGINT; VIRTUAL;
{ properties }
PROPERTY Items[Idx : LONGINT]: INTEGER READ GetInteger WRITE PutInteger;
END;
TWordContainer = CLASS(TBaseContainer)
PRIVATE
FUNCTION GetWord(Idx : LONGINT) : WORD;
PROCEDURE PutWord(Idx : LONGINT; N : WORD);
PROTECTED
FUNCTION Compare(VAR Ptr1,Ptr2) : INTEGER; OVERRIDE;
PUBLIC
{ constructors }
CONSTRUCTOR Create;
{ methods }
FUNCTION Add(Item: WORD): LONGINT; VIRTUAL;
FUNCTION Append(Item : WORD) : LONGINT; VIRTUAL;
FUNCTION First: WORD; VIRTUAL;
FUNCTION Includes(Item : WORD; VAR Idx : LONGINT) : BOOLEAN;
FUNCTION Insert(Idx: LONGINT; Item: WORD) : LONGINT; VIRTUAL;
FUNCTION Last: WORD;
FUNCTION Prepend(Item : WORD) : LONGINT; VIRTUAL;
FUNCTION Remove(Item: WORD): LONGINT; VIRTUAL;
{ properties }
PROPERTY Items[Idx : LONGINT]: WORD READ GetWord WRITE PutWord;
END;
TLongIntContainer = CLASS(TBaseContainer)
PRIVATE
FUNCTION GetLongInt(Idx : LONGINT) : LONGINT;
PROCEDURE PutLongInt(Idx : LONGINT; N : LONGINT);
PROTECTED
FUNCTION Compare(VAR Ptr1,Ptr2) : INTEGER; OVERRIDE;
PUBLIC
{ constructors }
CONSTRUCTOR Create;
{ methods }
FUNCTION Add(Item: LONGINT): LONGINT; VIRTUAL;
FUNCTION Append(Item : LONGINT) : LONGINT; VIRTUAL;
FUNCTION First: LONGINT; VIRTUAL;
FUNCTION Includes(Item : LONGINT; VAR Idx : LONGINT) : BOOLEAN;
FUNCTION Insert(Idx: LONGINT; Item: LONGINT) : LONGINT; VIRTUAL;
FUNCTION Last: LONGINT;
FUNCTION Prepend(Item : LONGINT) : LONGINT; VIRTUAL;
FUNCTION Remove(Item: LONGINT): LONGINT; VIRTUAL;
{ properties }
PROPERTY Items[Idx : LONGINT]: LONGINT READ GetLongInt WRITE PutLongInt;
END;
TCustomTypeContainer = CLASS(TBaseContainer)
PUBLIC
{ constructors }
CONSTRUCTOR Create(CustomTypeLen : WORD);
{ methods }
FUNCTION Add(VAR Item): LONGINT; VIRTUAL;
FUNCTION Append(VAR Item) : LONGINT; VIRTUAL;
FUNCTION Insert(Idx: LONGINT; VAR Item) : LONGINT; VIRTUAL;
FUNCTION Prepend(VAR Item) : LONGINT; VIRTUAL;
FUNCTION Retrieve(Idx : LONGINT; VAR Item) : BOOLEAN;
END;
{ :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: }