-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmsTotalShapesList.pas
91 lines (75 loc) · 2.09 KB
/
msTotalShapesList.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
unit msTotalShapesList;
interface
uses
Generics.Collections,
msInterfaces
;
type
TmsWeakShapeRefList = TList<TmsWeakShapeRef>;
TmsShapeByUIDMap = TDictionary<TmsShapeUID, TmsWeakShapeRef>;
TmsTotalShapesList = class
strict private
class var f_ShapesPlainList : TmsWeakShapeRefList;
class var f_Map : TmsShapeByUIDMap;
class function ShapesPlainList: TmsWeakShapeRefList;
class function Map: TmsShapeByUIDMap;
public
class destructor Fini;
public
class procedure ShapeAdded(const aShape: ImsShape);
class procedure ShapeDestroyed(const aShape: ImsShape);
class function GenerateUID(const aShape: ImsShape): TmsShapeUID;
// - ñîçäà¸ò UID äëÿ ïðèìèòèâà aShape
class function ShapeByUID(const aUID: TmsShapeUID): ImsShape;
end;//TmsTotalShapesList
implementation
uses
System.SysUtils
;
// TmsTotalShapesList
class destructor TmsTotalShapesList.Fini;
begin
FreeAndNil(f_ShapesPlainList);
FreeAndNil(f_Map);
end;
class function TmsTotalShapesList.ShapesPlainList: TmsWeakShapeRefList;
begin
if (f_ShapesPlainList = nil) then
f_ShapesPlainList := TmsWeakShapeRefList.Create;
Result := f_ShapesPlainList;
end;
class function TmsTotalShapesList.Map: TmsShapeByUIDMap;
begin
if (f_Map = nil) then
f_Map := TmsShapeByUIDMap.Create;
Result := f_Map;
end;
class procedure TmsTotalShapesList.ShapeAdded(const aShape: ImsShape);
begin
with ShapesPlainList do
if (IndexOf(aShape) < 0) then
Add(aShape);
Map.Remove(aShape.UID);
// - ïîòîìó, ÷òî ïðè ÄÅÑÅÐÈÀËÈÇÀÖÈÈ åñòü ÄÂÅ êîïèè ïðèìèòèâà
// îäíà - äåñåðèàëèçóåìàÿ
// âòîðàÿ - äîáàâëÿåìàÿ
Map.Add(aShape.UID, aShape);
end;
class procedure TmsTotalShapesList.ShapeDestroyed(const aShape: ImsShape);
begin
if (f_ShapesPlainList <> nil) then
f_ShapesPlainList.Remove(aShape);
if (f_Map <> nil) then
f_Map.Remove(aShape.UID);
end;
class function TmsTotalShapesList.GenerateUID(const aShape: ImsShape): TmsShapeUID;
begin
Result := TmsShapeUID.CreateNew;
end;
class function TmsTotalShapesList.ShapeByUID(const aUID: TmsShapeUID): ImsShape;
begin
Assert(f_Map <> nil);
Assert(not aUID.IsNull);
Result := f_Map[aUID];
end;
end.