0024742: Remove rarely used collection classes: Queue
[occt.git] / src / QANCollection / QANCollection1.cxx
1 // Created on: 2004-03-05
2 // Created by: Mikhail KUZMITCHEV
3 // Copyright (c) 2004-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <QANCollection.hxx>
17 #include <Draw_Interpretor.hxx>
18
19 #include <OSD_PerfMeter.hxx>
20
21 #include <TColgp_Array1OfPnt.hxx>
22 #include <TColgp_SequenceOfPnt.hxx>
23
24 #define USE_MACROS
25 #ifdef USE_MACROS
26 #include <NCollection_DefineArray1.hxx>
27 #include <NCollection_DefineSequence.hxx>
28 DEFINE_BASECOLLECTION (MyBaseCollPnt, gp_Pnt)
29 DEFINE_ARRAY1   (MyArray1,   MyBaseCollPnt, gp_Pnt)
30 DEFINE_SEQUENCE (MySequence, MyBaseCollPnt, gp_Pnt)
31 #else
32 #include <NCollection_Sequence.hxx>
33 #include <NCollection_Array1.hxx>
34 typedef NCollection_Array1<gp_Pnt> MyArray1;
35 typedef NCollection_Sequence<gp_Pnt> MySequence;
36 typedef NCollection_BaseCollection<gp_Pnt> MyBaseCollPnt;
37 #endif
38 void checkArray         (const Standard_Boolean);
39 void checkSequence      (const Standard_Boolean, const Standard_Boolean);
40 void createArray        (TColgp_Array1OfPnt&);
41 void assignArray        (TColgp_Array1OfPnt&, const TColgp_Array1OfPnt&);
42 void createSequence     (TColgp_SequenceOfPnt&);
43 void assignSequence     (TColgp_SequenceOfPnt&, const TColgp_SequenceOfPnt&);
44
45 void createArray        (MyArray1&);
46 void assignArray        (MyArray1&, const MyArray1&);
47 void createSequence     (MySequence&);
48 void assignSequence     (MySequence&, const MySequence&);
49 void assignCollection   (MyBaseCollPnt&, const MyBaseCollPnt&, const char *);
50 void printAllMeters     ();
51
52 void checkArray (const Standard_Boolean isNewColl)
53 {
54   if (isNewColl) {
55     MyArray1 anArrPnt (1, 100000), anArrPnt1 (1, 100000);
56     createArray (anArrPnt);
57     assignArray (anArrPnt1, anArrPnt);
58     assignCollection (anArrPnt1, anArrPnt, "Assign collect to array");
59   } else {
60     TColgp_Array1OfPnt anArrPnt (1,100000), anArrPnt1 (1, 100000);
61     createArray (anArrPnt);
62     assignArray (anArrPnt1, anArrPnt);
63   }
64   printAllMeters ();
65 }
66
67 static  Handle(NCollection_BaseAllocator) anAlloc[2];
68
69 Handle(NCollection_BaseAllocator) getAlloc (const int i)
70 {
71   return i == 0 ? anAlloc[0]: anAlloc[1];
72 }
73
74 void checkSequence (const Standard_Boolean isNewColl,
75                     const Standard_Boolean isIncr)
76 {
77   if (isNewColl) {
78     if (isIncr) {
79       anAlloc[0] = new NCollection_IncAllocator;
80       anAlloc[1] = new NCollection_IncAllocator;
81     }
82     MySequence aSeqPnt (anAlloc[0]), aSeqPnt1(anAlloc[1]);
83     createSequence (aSeqPnt);
84     assignSequence (aSeqPnt1, aSeqPnt);
85     assignCollection (aSeqPnt1, aSeqPnt, "Assign collect to sequence");
86   } else {
87     TColgp_SequenceOfPnt aSeqPnt, aSeqPnt1;
88     createSequence (aSeqPnt);
89     assignSequence (aSeqPnt1, aSeqPnt);
90   }
91   printAllMeters ();
92 }
93
94 //=======================================================================
95 //function : QANColCheckArray1
96 //purpose  : 
97 //=======================================================================
98 static Standard_Integer QANColCheckArray1(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
99 {
100   if ( argc > 2) {
101     di << "Usage : " << argv[0] << " [-n]" << "\n";
102     return 1;
103   }
104
105   Standard_Boolean isNewColl = Standard_False;
106   if (argc > 1) {
107     if (strcmp (argv[1], "-n") == 0) isNewColl = Standard_True;
108   }
109   checkArray (isNewColl);
110   return 0;
111 }
112
113 //=======================================================================
114 //function : QANColCheckSequence
115 //purpose  : 
116 //=======================================================================
117 static Standard_Integer QANColCheckSequence(Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
118 {
119   if ( argc > 2) {
120     di << "Usage : " << argv[0] << " [-n]/[-ni]/[-in]" << "\n";
121     return 1;
122   }
123
124   Standard_Boolean isNewColl = Standard_False, isIncr = Standard_False;
125   if (argc > 1) {
126     if (strcmp (argv[1], "-n") == 0) isNewColl = Standard_True;
127     if (strcmp (argv[1], "-ni") == 0 || strcmp (argv[1], "-in") == 0)
128     {
129       isNewColl = Standard_True;
130       isIncr = Standard_True;
131     }
132   }
133   checkSequence (isNewColl, isIncr);
134   return 0;
135 }
136
137 void QANCollection::Commands1(Draw_Interpretor& theCommands) {
138   const char *group = "QANCollection";
139
140   // from agvCollTest/src/AgvColEXE/TestEXE.cxx
141   theCommands.Add("QANColCheckArray1",   "QANColCheckArray1 [-n]",               __FILE__, QANColCheckArray1,   group);  
142   theCommands.Add("QANColCheckSequence", "QANColCheckSequence [-n]/[-ni]/[-in]", __FILE__, QANColCheckSequence, group);  
143
144   return;
145 }