PageRenderTime 20ms CodeModel.GetById 17ms app.highlight 1ms RepoModel.GetById 0ms app.codeStats 1ms

/jcl/source/prototypes/containers/JclArraySets.imp

https://github.com/the-Arioch/jcl
Unknown | 96 lines | 88 code | 8 blank | 0 comment | 0 complexity | a3a618ece522cc90cc59fd053cf0c8d0 MD5 | raw file
Possible License(s): BSD-3-Clause
 1(*$JPPDEFINEMACRO JCLARRAYSETIMP(SELFCLASSNAME, COLLECTIONINTERFACENAME, ITRINTERFACENAME, CONSTKEYWORD, PARAMETERNAME, TYPENAME, DEFAULTVALUE, GETTERFUNCTIONNAME)
 2//=== { SELFCLASSNAME } ====================================================
 3
 4function SELFCLASSNAME.Add(CONSTKEYWORDPARAMETERNAME: TYPENAME): Boolean;
 5var
 6  Idx: Integer;
 7begin
 8  {$JPPDEFINE WRITE}{$JPPEXPANDMACRO LOCK}
 9    Result := FAllowDefaultElements or not ItemsEqual(PARAMETERNAME, DEFAULTVALUE);
10    if Result then
11    begin
12      Idx := BinarySearch(PARAMETERNAME);
13      if Idx >= 0 then
14        Result := not ItemsEqual(GETTERFUNCTIONNAME(Idx), PARAMETERNAME) or CheckDuplicate
15      else
16        Result := True;
17      if Result then
18        Result := inherited Insert(Idx + 1, PARAMETERNAME);
19    end;
20  {$JPPEXPANDMACRO UNLOCK}
21end;
22
23function SELFCLASSNAME.AddAll(const ACollection: COLLECTIONINTERFACENAME): Boolean;
24var
25  It: ITRINTERFACENAME;
26begin
27  {$JPPDEFINE WRITE}{$JPPEXPANDMACRO LOCK}
28    Result := False;
29    if ACollection = nil then
30      Exit;
31    It := ACollection.First;
32    while It.HasNext do
33      Result := Add(It.Next) and Result;
34  {$JPPEXPANDMACRO UNLOCK}
35end;
36
37function SELFCLASSNAME.BinarySearch(CONSTKEYWORDPARAMETERNAME: TYPENAME): Integer;
38var
39  HiPos, LoPos, CompPos: Integer;
40  Comp: Integer;
41begin
42  {$JPPUNDEF WRITE}{$JPPEXPANDMACRO LOCK}
43    LoPos := 0;
44    HiPos := Size - 1;
45    CompPos := (HiPos + LoPos) div 2;
46    while HiPos >= LoPos do
47    begin
48      Comp := ItemsCompare(GETTERFUNCTIONNAME(CompPos), PARAMETERNAME);
49      if Comp < 0 then
50        LoPos := CompPos + 1
51      else
52      if Comp > 0 then
53        HiPos := CompPos - 1
54      else
55      begin
56        HiPos := CompPos;
57        LoPos := CompPos + 1;
58      end;
59      CompPos := (HiPos + LoPos) div 2;
60    end;
61    Result := HiPos;
62  {$JPPEXPANDMACRO UNLOCK}
63end;
64
65function SELFCLASSNAME.Contains(CONSTKEYWORDPARAMETERNAME: TYPENAME): Boolean;
66var
67  Idx: Integer;
68begin
69  {$JPPUNDEF WRITE}{$JPPEXPANDMACRO LOCK}
70    Idx := BinarySearch(PARAMETERNAME);
71    if Idx >= 0 then
72      Result := ItemsEqual(GETTERFUNCTIONNAME(Idx), PARAMETERNAME)
73    else
74      Result := False;
75  {$JPPEXPANDMACRO UNLOCK}
76end;
77
78function SELFCLASSNAME.Insert(Index: Integer; CONSTKEYWORDPARAMETERNAME: TYPENAME): Boolean;
79begin
80  raise EJclOperationNotSupportedError.Create;
81end;
82
83procedure SELFCLASSNAME.Intersect(const ACollection: COLLECTIONINTERFACENAME);
84begin
85  RetainAll(ACollection);
86end;
87
88procedure SELFCLASSNAME.Subtract(const ACollection: COLLECTIONINTERFACENAME);
89begin
90  RemoveAll(ACollection);
91end;
92
93procedure SELFCLASSNAME.Union(const ACollection: COLLECTIONINTERFACENAME);
94begin
95  AddAll(ACollection);
96end;*)