0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / IFSelect / IFSelect_SignatureList.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
42cf5bc1 14
15#include <Dico_DictionaryOfInteger.hxx>
16#include <Dico_DictionaryOfTransient.hxx>
7fd59977 17#include <Dico_IteratorOfDictionaryOfInteger.hxx>
18#include <Dico_IteratorOfDictionaryOfTransient.hxx>
42cf5bc1 19#include <IFSelect_SignatureList.hxx>
20#include <Interface_InterfaceModel.hxx>
7fd59977 21#include <Interface_Macros.hxx>
42cf5bc1 22#include <Interface_MSG.hxx>
7fd59977 23#include <Message.hxx>
42cf5bc1 24#include <Message_Messenger.hxx>
25#include <Standard_Transient.hxx>
26#include <Standard_Type.hxx>
27#include <TCollection_HAsciiString.hxx>
28#include <TColStd_HSequenceOfTransient.hxx>
7fd59977 29
92efcf78 30IMPLEMENT_STANDARD_RTTIEXT(IFSelect_SignatureList,MMgt_TShared)
31
b311480e 32IFSelect_SignatureList::IFSelect_SignatureList
7fd59977 33 (const Standard_Boolean withlist)
34{
35 thesignonly = Standard_False;
36 thelistat = withlist;
37 thenbnuls = 0;
38 thedicount = new Dico_DictionaryOfInteger;
39 thediclist = new Dico_DictionaryOfTransient;
40 SetName("...");
41}
42
43 void IFSelect_SignatureList::SetList
44 (const Standard_Boolean withlist)
45 { thelistat = withlist; }
46
47 Standard_Boolean& IFSelect_SignatureList::ModeSignOnly ()
48 { return thesignonly; }
49
50 void IFSelect_SignatureList::Clear ()
51{
52 thelastval.Clear();
53 thenbnuls = 0;
54 thedicount = new Dico_DictionaryOfInteger;
55 thediclist = new Dico_DictionaryOfTransient;
56}
57
58 void IFSelect_SignatureList::Add
59 (const Handle(Standard_Transient)& ent, const Standard_CString sign)
60{
61 if (thesignonly) {
62 thelastval.Clear();
63 thelastval.AssignCat (sign);
64 return;
65 }
66
67 if (sign[0] == '\0') { thenbnuls ++; return; }
68
69 Standard_Boolean deja;
70 Standard_Integer& nb = thedicount->NewItem(sign,deja);
71 if (!deja) nb = 0;
72 nb ++;
73
74 if (thelistat) {
75 Handle(Standard_Transient)& anitem = thediclist->NewItem(sign,deja);
76 DeclareAndCast(TColStd_HSequenceOfTransient,alist,anitem);
77 if (!deja) { alist = new TColStd_HSequenceOfTransient(); anitem = alist; }
78 alist->Append(ent);
79 }
80}
81
82 Standard_CString IFSelect_SignatureList::LastValue () const
83 { return thelastval.ToCString(); }
84
85 void IFSelect_SignatureList::Init
86 (const Standard_CString name,
75259fc5 87 const Handle(Dico_DictionaryOfInteger)& theCount,
7fd59977 88 const Handle(Dico_DictionaryOfTransient)& list,
89 const Standard_Integer nbnuls)
90{
91 thelastval.Clear();
92 thename = new TCollection_HAsciiString (name);
75259fc5 93 thedicount = theCount;
7fd59977 94 thediclist = list;
95 thenbnuls = nbnuls;
96 if (thediclist.IsNull()) thelistat = Standard_False;
97}
98
99
100 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_SignatureList::List
101 (const Standard_CString root) const
102{
103 Handle(TColStd_HSequenceOfHAsciiString) list =
104 new TColStd_HSequenceOfHAsciiString();
105 Dico_IteratorOfDictionaryOfInteger iter(thedicount,root);
106 for (; iter.More(); iter.Next()) {
107 Handle(TCollection_HAsciiString) sign =
108 new TCollection_HAsciiString (iter.Name());
109 list->Append(sign);
110 }
111 return list;
112}
113
114
115 Standard_Boolean IFSelect_SignatureList::HasEntities () const
116 { return thelistat; }
117
118 Standard_Integer IFSelect_SignatureList::NbNulls () const
119 { return thenbnuls; }
120
121 Standard_Integer IFSelect_SignatureList::NbTimes
122 (const Standard_CString sign) const
123{
124 Standard_Integer nb;
125 if (thedicount->GetItem(sign,nb)) return nb;
126 else return 0;
127}
128
129 Handle(TColStd_HSequenceOfTransient) IFSelect_SignatureList::Entities
130 (const Standard_CString sign) const
131{
132 Handle(TColStd_HSequenceOfTransient) list;
133 if (!thelistat) return list;
134 if (thediclist->GetItem(sign,list)) return list;
135 list = new TColStd_HSequenceOfTransient();
136 return list;
137}
138
139
140 void IFSelect_SignatureList::SetName (const Standard_CString name)
141 { thename = new TCollection_HAsciiString (name); }
142
143 Standard_CString IFSelect_SignatureList::Name () const
144 { return thename->ToCString(); }
145
146
147 void IFSelect_SignatureList::PrintCount (const Handle(Message_Messenger)& S) const
148{
149 Standard_Integer nbtot = 0, nbsign = 0;
150 Dico_IteratorOfDictionaryOfInteger iter(thedicount,"");
151 S << " Count "<<thename->ToCString()<<"\n ----- -----------"<<endl;
152 for (; iter.More(); iter.Next()) {
153 Standard_Integer val = iter.Value();
154 S << Interface_MSG::Blanks(val,6) << val <<" "<<iter.Name()<<endl;
155 nbtot += val;
156 nbsign ++;
157 }
158 if (thenbnuls > 0) S << thename->ToCString()<< " Nul : " << thenbnuls<<endl;
159 S<<" Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl;
160}
161
162 void IFSelect_SignatureList::PrintList
163 (const Handle(Message_Messenger)& S, const Handle(Interface_InterfaceModel)& model,
164 const IFSelect_PrintCount mod) const
165{
166 if (mod == IFSelect_ItemsByEntity) return;
167 if (mod == IFSelect_CountByItem) { PrintCount (S); return; }
168 if (mod == IFSelect_CountSummary) { PrintSum (S); return; }
169 if (!HasEntities()) {
170 S <<" SignatureList "<<Name()<<" : PrintList, list not available"<<endl;
171 PrintCount(S);
172 return;
173 }
174 Standard_Integer nbtot = 0, nbsign = 0;
175 Dico_IteratorOfDictionaryOfTransient iter(thediclist,"");
176 for (; iter.More(); iter.Next()) {
177 DeclareAndCast(TColStd_HSequenceOfTransient,list,iter.Value());
178 S<<Name()<<" : "<<iter.Name()<<endl;
179 if (list.IsNull()) { S<<" - (empty list)"<<endl; continue; }
180 Standard_Integer nb = list->Length();
181 S<<" - Nb: "<<nb<<" : ";
182 Standard_Integer nc = nb; if (nb > 5 && mod == IFSelect_ShortByItem) nc = 5;
183 for (Standard_Integer i = 1; i <= nc; i ++) {
184 if (list->Value(i).IsNull()) {
185 S<<" 0"; if (mod == IFSelect_EntitiesByItem) S<<":(Global)";
186 continue;
187 }
188 Standard_Integer num = model->Number(list->Value(i));
189 if (num == IFSelect_ShortByItem) { S<<" ??"; continue; }
190 S<<" "<<num;
191 if (mod == IFSelect_EntitiesByItem)
192 { S<<":"; model->PrintLabel(list->Value(i),S); }
193 }
194 if (nc < nb) S<<" .. etc";
195 S<<endl;
196 nbtot += nb;
197 nbsign ++;
198 }
199 S<<" Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl;
200}
201
202
203 void IFSelect_SignatureList::PrintSum (const Handle(Message_Messenger)& S) const
204{
205 Dico_IteratorOfDictionaryOfInteger iter(thedicount,"");
206 S << " Summary "<<thename->ToCString()<<"\n ----- -----------"<<endl;
207 Standard_Integer nbtot = 0, nbsign = 0, maxent = 0, nbval = 0, nbve = 0, minval = 0, maxval = 0, totval = 0;
208 for (; iter.More(); iter.Next()) {
209 Standard_Integer nbent = iter.Value();
210 nbtot += nbent;
211 nbsign ++;
212 if (nbent > maxent) maxent = nbent;
213 TCollection_AsciiString name = iter.Name();
214// if (!name.IsIntegerValue()) continue; pas bien fiable
215 Standard_Integer ic, nc = name.Length();
216 Standard_Boolean iaint = Standard_True;
217 for (ic = 1; ic <= nc; ic ++) {
218 char unc = name.Value(ic);
219 if (ic == 1 && (unc == ' ' || unc == '+' || unc == '-')) continue;
220 if (unc >= '0' && unc <= '9') continue;
221 iaint = Standard_False; break;
222 }
223 if (!iaint) continue;
224 Standard_Integer val = name.IntegerValue();
225 if (nbval == 0) { minval = maxval = val; }
226 if (minval > val) minval = val;
227 if (maxval < val) maxval = val;
228 nbval ++;
229 nbve += nbent;
230 totval += (val*nbent);
231 }
232 S << " Nb Total:"<<nbtot<<" for "<<nbsign<<" items"<<endl;
233 S << " Highest count of entities : "<<maxent<<" on one item"<<endl;
234 if (nbval > 0) {
235 S<<" Summary on Integer Values"<<endl;
236 S<<" Nb Integer Items : "<<nbval<<endl;
237 S<<" For Nb Entities : "<<nbve<<endl;
238 S<<" Cumulated Values : "<<totval<<endl;
239 S<<" Maximum Value : "<<maxval<<endl;
240 Standard_Integer avg1, avg2;
241 avg1 = totval/nbve;
242 avg2 = ((totval - (avg1*nbve)) * 10) / nbve;
243 S<<" Average Value : "<<avg1<<" "<<avg2<<"/10"<<endl;
244 S<<" Minimum Value : "<<minval<<endl;
245 }
246}