|
Форуми -> Програмування -> delphi templates - stack
|
{$IFNDEF TYPED_OBJECT_STACK_TEMPLATE}
unit u_stack;
interface
uses
Sysutils,
Classes,
Contnrs;
type
_TYPED_OBJECT_STACK_ITEM_ = TObject;
{$ENDIF TYPED_OBJECT_STACK_TEMPLATE}
{$IFNDEF TYPED_OBJECT_STACK_TEMPLATE_SECOND_PASS}
type
_TYPED_OBJECT_STACK_ = class
protected
fStack: TObjectStack;
function GetCount : integer;
public
constructor Create;
destructor Destroy; override;
function Push(_Item: _TYPED_OBJECT_STACK_ITEM_): _TYPED_OBJECT_STACK_ITEM_;
function Pop : _TYPED_OBJECT_STACK_ITEM_;
function Peek : _TYPED_OBJECT_STACK_ITEM_;
property Count : integer read GetCount;
end;
{$ENDIF TYPED_OBJECT_STACK_TEMPLATE_SECOND_PASS}
{$IFNDEF TYPED_OBJECT_STACK_TEMPLATE}
implementation
{$DEFINE TYPED_OBJECT_STACK_TEMPLATE_SECOND_PASS}
{$ENDIF TYPED_OBJECT_STACK_TEMPLATE}
{$IFDEF TYPED_OBJECT_STACK_TEMPLATE_SECOND_PASS}
{ _TYPED_OBJECT_STACK_ }
constructor _TYPED_OBJECT_STACK_.Create;
begin
inherited Create;
fStack := TObjectStack.Create;
end;
destructor _TYPED_OBJECT_STACK_.Destroy;
begin
fStack.Free;
inherited;
end;
function _TYPED_OBJECT_STACK_.Push(
_Item: _TYPED_OBJECT_STACK_ITEM_): _TYPED_OBJECT_STACK_ITEM_;
begin
Result := fStack.Push(_Item) as _TYPED_OBJECT_STACK_ITEM_;
end;
function _TYPED_OBJECT_STACK_.Pop : _TYPED_OBJECT_STACK_ITEM_;
begin
Result := fStack.Pop as _TYPED_OBJECT_STACK_ITEM_;
end;
function _TYPED_OBJECT_STACK_.Peek : _TYPED_OBJECT_STACK_ITEM_;
begin
Result := fStack.Peek as _TYPED_OBJECT_STACK_ITEM_;
end;
function _TYPED_OBJECT_STACK_.GetCount : integer;
begin
Result := fStack.Count;
end;
{$WARNINGS off}
{$IFNDEF TYPED_OBJECT_STACK_TEMPLATE}
end.
{$ENDIF TYPED_OBJECT_STACK_TEMPLATE}
{$ENDIF TYPED_OBJECT_STACK_TEMPLATE_SECOND_PASS}
{$DEFINE TYPED_OBJECT_STACK_TEMPLATE_SECOND_PASS}
|
|
використання аналогічне u_list, тільки треба в дефайни помінять =)) замість _LIST_ _STACK_.
і вуаля =) пуш, поп, пеек, каунт =)) стек однако!
|
|
Книга Фріланс на західному ринку
|
|