-
Notifications
You must be signed in to change notification settings - Fork 10
/
msShapeClassList.pas
99 lines (84 loc) · 2.22 KB
/
msShapeClassList.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
unit msShapeClassList;
interface
uses
msInterfaces,
msShape,
Generics.Collections,
msObject
;
type
MCmsShape = msShape.MCmsShape;
TmsShapeClassListItems = TList<MCmsShape>;
TmsShapeClassLambda = reference to procedure (const aShapeClass : MCmsShape);
TmsShapeClassList = class(TmsObject)
strict protected
f_Registered : TmsShapeClassListItems;
constructor Create;
protected
function IndexOf(const aValue: TmsShapeClassName): Integer;
procedure Cleanup; override;
public
procedure RegisterMC(const aValue: MCmsShape); virtual;
function ByName(const aValue: String): MCmsShape;
procedure IterateShapes(aLambda: TmsShapeClassLambda); virtual;
// [Èòåðàòîð (øàáëîí ïðîåêòèðîâàíèÿ)|https://ru.wikipedia.org/wiki/%D0%98%D1%82%D0%B5%D1%80%D0%B0%D1%82%D0%BE%D1%80_(%D1%88%D0%B0%D0%B1%D0%BB%D0%BE%D0%BD_%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F)]
end;//TmsShapeClassList
implementation
uses
System.StrUtils,
SysUtils,
msShapeClass
;
// TmsShapeClassList
constructor TmsShapeClassList.Create;
begin
inherited;
f_Registered := TmsShapeClassListItems.Create;
end;
procedure TmsShapeClassList.Cleanup;
begin
FreeAndNil(f_Registered);
inherited;
end;
procedure TmsShapeClassList.RegisterMC(const aValue: MCmsShape);
begin
Assert(IndexOf(aValue.Name) < 0, 'Ñòåðåîòèï ' + aValue.Stereotype + ' óæå çàðåãèñòðèðîâàí');
f_Registered.Add(aValue);
end;
function TmsShapeClassList.IndexOf(const aValue: TmsShapeClassName): Integer;
var
l_Shape : MCmsShape;
I : Integer;
begin
Result := -1;
for I := 0 to Pred(f_Registered.Count) do
begin
l_Shape := f_Registered.Items[I];
if (l_Shape.Name = aValue) then
begin
Result := I;
Exit;
end;//l_Shape.Name = l_Value
end;//for I
end;
function TmsShapeClassList.ByName(const aValue: String): MCmsShape;
var
I : Integer;
begin
Result := nil;
I := IndexOf(aValue);
if (I >= 0) then
Result := f_Registered.Items[I];
end;
procedure TmsShapeClassList.IterateShapes(aLambda: TmsShapeClassLambda);
var
l_ShapeClass : MCmsShape;
begin
for l_ShapeClass in f_Registered do
if not l_ShapeClass.IsTool then
aLambda(l_ShapeClass);
for l_ShapeClass in f_Registered do
if l_ShapeClass.IsTool then
aLambda(l_ShapeClass);
end;
end.