0026850: Replace nested instantiations of TCollection generic classes by NCollection...
[occt.git] / src / Transfer / Transfer_ProcessForFinder.hxx
CommitLineData
42cf5bc1 1// Created on: 1992-02-03
2// Created by: Christian CAILLET
3// Copyright (c) 1992-1999 Matra Datavision
4// Copyright (c) 1999-2014 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#ifndef _Transfer_ProcessForFinder_HeaderFile
18#define _Transfer_ProcessForFinder_HeaderFile
19
42cf5bc1 20#include <TColStd_IndexedMapOfInteger.hxx>
42cf5bc1 21#include <Transfer_HSequenceOfFinder.hxx>
5d88fd54 22#include <Transfer_TransferMapOfProcessForFinder.hxx>
23
42cf5bc1 24class Message_Messenger;
25class Transfer_Finder;
26class Transfer_Binder;
27class Transfer_ActorOfProcessForFinder;
28class Message_ProgressIndicator;
29class Interface_InterfaceError;
30class Transfer_TransferFailure;
31class Transfer_FindHasher;
42cf5bc1 32class Transfer_IteratorOfProcessForFinder;
33class Message_Msg;
34class Interface_Check;
35class Standard_Transient;
36class Interface_CheckIterator;
37
38
39class Transfer_ProcessForFinder;
40DEFINE_STANDARD_HANDLE(Transfer_ProcessForFinder, MMgt_TShared)
41
42
43class Transfer_ProcessForFinder : public MMgt_TShared
44{
45
46public:
47
48
36b9ff75 49 //! Sets TransferProcess at initial state. Gives an Initial size
50 //! (indicative) for the Map when known (default is 10000).
51 //! Sets default trace file as a printer and default trace level
52 //! (see Message_TraceFile).
42cf5bc1 53 Standard_EXPORT Transfer_ProcessForFinder(const Standard_Integer nb = 10000);
54
36b9ff75 55 //! Sets TransferProcess at initial state. Gives an Initial size
56 //! (indicative) for the Map when known (default is 10000).
57 //! Sets a specified printer.
42cf5bc1 58 Standard_EXPORT Transfer_ProcessForFinder(const Handle(Message_Messenger)& printer, const Standard_Integer nb = 10000);
59
36b9ff75 60 //! Resets a TransferProcess as ready for a completely new work.
61 //! Clears general data (roots) and the Map
42cf5bc1 62 Standard_EXPORT void Clear();
63
36b9ff75 64 //! Rebuilds the Map and the roots to really remove Unbound items
65 //! Because Unbind keeps the entity in place, even if not bound
66 //! Hence, working by checking new items is meaningless if a
67 //! formerly unbound item is rebound
42cf5bc1 68 Standard_EXPORT void Clean();
69
36b9ff75 70 //! Resizes the Map as required (if a new reliable value has been
71 //! determined). Acts only if <nb> is greater than actual NbMapped
42cf5bc1 72 Standard_EXPORT void Resize (const Standard_Integer nb);
73
36b9ff75 74 //! Defines an Actor, which is used for automatic Transfer
75 //! If already defined, the new Actor is cumulated
76 //! (see SetNext from Actor)
42cf5bc1 77 Standard_EXPORT void SetActor (const Handle(Transfer_ActorOfProcessForFinder)& actor);
78
36b9ff75 79 //! Returns the defined Actor. Returns a Null Handle if
80 //! not set.
42cf5bc1 81 Standard_EXPORT Handle(Transfer_ActorOfProcessForFinder) Actor() const;
82
36b9ff75 83 //! Returns the Binder which is linked with a starting Object
84 //! It can either bring a Result (Transfer done) or none (for a
85 //! pre-binding).
86 //! If no Binder is linked with <start>, returns a Null Handle
87 //! Considers a category number, by default 0
42cf5bc1 88 Standard_EXPORT Handle(Transfer_Binder) Find (const Handle(Transfer_Finder)& start) const;
89
36b9ff75 90 //! Returns True if a Result (whatever its form) is Bound with
91 //! a starting Object. I.e., if a Binder with a Result set,
92 //! is linked with it
93 //! Considers a category number, by default 0
42cf5bc1 94 Standard_EXPORT Standard_Boolean IsBound (const Handle(Transfer_Finder)& start) const;
95
36b9ff75 96 //! Returns True if the result of the transfer of an object is
97 //! already used in other ones. If it is, Rebind cannot change it.
98 //! Considers a category number, by default 0
42cf5bc1 99 Standard_EXPORT Standard_Boolean IsAlreadyUsed (const Handle(Transfer_Finder)& start) const;
100
36b9ff75 101 //! Creates a Link a starting Object with a Binder. This Binder
102 //! can either bring a Result (effective Binding) or none (it can
103 //! be set later : pre-binding).
104 //! Considers a category number, by default 0
42cf5bc1 105 Standard_EXPORT void Bind (const Handle(Transfer_Finder)& start, const Handle(Transfer_Binder)& binder);
106
36b9ff75 107 //! Changes the Binder linked with a starting Object for its
108 //! unitary transfer. This it can be useful when the exact form
109 //! of the result is known once the transfer is widely engaged.
110 //! This can be done only on first transfer.
111 //! Considers a category number, by default 0
42cf5bc1 112 Standard_EXPORT void Rebind (const Handle(Transfer_Finder)& start, const Handle(Transfer_Binder)& binder);
113
36b9ff75 114 //! Removes the Binder linked with a starting object
115 //! If this Binder brings a non-empty Check, it is replaced by
116 //! a VoidBinder. Also removes from the list of Roots as required.
117 //! Returns True if done, False if <start> was not bound
118 //! Considers a category number, by default 0
42cf5bc1 119 Standard_EXPORT Standard_Boolean Unbind (const Handle(Transfer_Finder)& start);
120
36b9ff75 121 //! Returns a Binder for a starting entity, as follows :
122 //! Tries to Find the already bound one
123 //! If none found, creates a VoidBinder and Binds it
42cf5bc1 124 Standard_EXPORT Handle(Transfer_Binder) FindElseBind (const Handle(Transfer_Finder)& start);
125
36b9ff75 126 //! Sets Messenger used for outputting messages.
42cf5bc1 127 Standard_EXPORT void SetMessenger (const Handle(Message_Messenger)& messenger);
128
36b9ff75 129 //! Returns Messenger used for outputting messages.
130 //! The returned object is guaranteed to be non-null;
131 //! default is Message::Messenger().
42cf5bc1 132 Standard_EXPORT Handle(Message_Messenger) Messenger() const;
133
36b9ff75 134 //! Sets trace level used for outputting messages:
135 //! <trace> = 0 : no trace at all
136 //! <trace> = 1 : handled exceptions and calls to AddError
137 //! <trace> = 2 : also calls to AddWarning
138 //! <trace> = 3 : also traces new Roots
139 //! (uses method ErrorTrace).
140 //! Default is 1 : Errors traced
42cf5bc1 141 Standard_EXPORT void SetTraceLevel (const Standard_Integer tracelev);
142
36b9ff75 143 //! Returns trace level used for outputting messages.
42cf5bc1 144 Standard_EXPORT Standard_Integer TraceLevel() const;
145
36b9ff75 146 //! New name for AddFail (Msg)
42cf5bc1 147 Standard_EXPORT void SendFail (const Handle(Transfer_Finder)& start, const Message_Msg& amsg);
148
36b9ff75 149 //! New name for AddWarning (Msg)
42cf5bc1 150 Standard_EXPORT void SendWarning (const Handle(Transfer_Finder)& start, const Message_Msg& amsg);
151
36b9ff75 152 //! Adds an information message
153 //! Trace is filled if trace level is at least 3
42cf5bc1 154 Standard_EXPORT void SendMsg (const Handle(Transfer_Finder)& start, const Message_Msg& amsg);
155
36b9ff75 156 //! Adds an Error message to a starting entity (to the check of
157 //! its Binder of category 0, as a Fail)
42cf5bc1 158 Standard_EXPORT void AddFail (const Handle(Transfer_Finder)& start, const Standard_CString mess, const Standard_CString orig = "");
159
36b9ff75 160 //! (other name of AddFail, maintained for compatibility)
42cf5bc1 161 Standard_EXPORT void AddError (const Handle(Transfer_Finder)& start, const Standard_CString mess, const Standard_CString orig = "");
162
36b9ff75 163 //! Adds an Error Message to a starting entity from the definition
164 //! of a Msg (Original+Value)
42cf5bc1 165 Standard_EXPORT void AddFail (const Handle(Transfer_Finder)& start, const Message_Msg& amsg);
166
36b9ff75 167 //! Adds a Warning message to a starting entity (to the check of
168 //! its Binder of category 0)
42cf5bc1 169 Standard_EXPORT void AddWarning (const Handle(Transfer_Finder)& start, const Standard_CString mess, const Standard_CString orig = "");
170
36b9ff75 171 //! Adds a Warning Message to a starting entity from the definition
172 //! of a Msg (Original+Value)
42cf5bc1 173 Standard_EXPORT void AddWarning (const Handle(Transfer_Finder)& start, const Message_Msg& amsg);
174
175 Standard_EXPORT void Mend (const Handle(Transfer_Finder)& start, const Standard_CString pref = "");
176
36b9ff75 177 //! Returns the Check attached to a starting entity. If <start>
178 //! is unknown, returns an empty Check
179 //! Adds a case name to a starting entity
180 //! Adds a case value to a starting entity
181 //! Returns the complete case list for an entity. Null Handle if empty
182 //! In the list of mapped items (between 1 and NbMapped),
183 //! searches for the first item which follows <num0>(not included)
184 //! and which has an attribute named <name>
185 //! Attributes are brought by Binders
186 //! Hence, allows such an iteration
187 //!
188 //! for (num = TP->NextItemWithAttribute(name,0);
189 //! num > 0;
190 //! num = TP->NextItemWithAttribute(name,num) {
191 //! .. process mapped item <num>
192 //! }
193 //! Returns the type of an Attribute attached to binders
194 //! If this name gives no Attribute, returns ParamVoid
195 //! If this name gives several different types, returns ParamMisc
196 //! Else, returns the effective type (ParamInteger, ParamReal,
197 //! ParamIdent, or ParamText)
198 //! Returns the list of recorded Attribute Names, as a Dictionary
199 //! of Integer : each value gives the count of items which bring
200 //! this attribute name
201 //! By default, considers all the attribute names
202 //! If <rootname> is given, considers only the attribute names
203 //! which begin by <rootname>
42cf5bc1 204 Standard_EXPORT Handle(Interface_Check) Check (const Handle(Transfer_Finder)& start) const;
205
36b9ff75 206 //! Binds a starting object with a Transient Result.
207 //! Uses a SimpleBinderOfTransient to work. If there is already
208 //! one but with no Result set, sets its Result.
209 //! Considers a category number, by default 0
42cf5bc1 210 Standard_EXPORT void BindTransient (const Handle(Transfer_Finder)& start, const Handle(Standard_Transient)& res);
211
36b9ff75 212 //! Returns the Result of the Transfer of an object <start> as a
213 //! Transient Result.
214 //! Returns a Null Handle if there is no Transient Result
215 //! Considers a category number, by default 0
216 //! Warning : Supposes that Binding is done with a SimpleBinderOfTransient
42cf5bc1 217 Standard_EXPORT const Handle(Standard_Transient)& FindTransient (const Handle(Transfer_Finder)& start) const;
218
36b9ff75 219 //! Prepares an object <start> to be bound with several results.
220 //! If no Binder is yet attached to <obj>, a MultipleBinder
221 //! is created, empty. If a Binder is already set, it must
222 //! accept Multiple Binding.
223 //! Considers a category number, by default 0
42cf5bc1 224 Standard_EXPORT void BindMultiple (const Handle(Transfer_Finder)& start);
225
36b9ff75 226 //! Adds an item to a list of results bound to a starting object.
227 //! Considers a category number, by default 0, for all results
42cf5bc1 228 Standard_EXPORT void AddMultiple (const Handle(Transfer_Finder)& start, const Handle(Standard_Transient)& res);
229
36b9ff75 230 //! Searches for a transient result attached to a starting object,
231 //! according to its type, by criterium IsKind(atype)
232 //!
233 //! In case of multiple result, explores the list and gives in
234 //! <val> the first transient result IsKind(atype)
235 //! Returns True and fills <val> if found
236 //! Else, returns False (<val> is not touched, not even nullified)
237 //!
238 //! This syntactic form avoids to do DownCast : if a result is
239 //! found with the good type, it is loaded in <val> and can be
240 //! immediately used, well initialised
42cf5bc1 241 Standard_EXPORT Standard_Boolean FindTypedTransient (const Handle(Transfer_Finder)& start, const Handle(Standard_Type)& atype, Handle(Standard_Transient)& val) const;
242
36b9ff75 243 //! Searches for a transient result recorded in a Binder, whatever
244 //! this Binder is recorded or not in <me>
245 //!
246 //! This is strictly equivalent to the class method GetTypedResult
247 //! from class SimpleBinderOfTransient, but is just lighter to call
248 //!
249 //! Apart from this, works as FindTypedTransient
42cf5bc1 250 Standard_EXPORT Standard_Boolean GetTypedTransient (const Handle(Transfer_Binder)& binder, const Handle(Standard_Type)& atype, Handle(Standard_Transient)& val) const;
251
36b9ff75 252 //! Returns the maximum possible value for Map Index
253 //! (no result can be bound with a value greater than it)
42cf5bc1 254 Standard_EXPORT Standard_Integer NbMapped() const;
255
36b9ff75 256 //! Returns the Starting Object bound to an Index,
42cf5bc1 257 Standard_EXPORT const Handle(Transfer_Finder)& Mapped (const Standard_Integer num) const;
258
36b9ff75 259 //! Returns the Index value bound to a Starting Object, 0 if none
42cf5bc1 260 Standard_EXPORT Standard_Integer MapIndex (const Handle(Transfer_Finder)& start) const;
261
36b9ff75 262 //! Returns the Binder bound to an Index
263 //! Considers a category number, by default 0
42cf5bc1 264 Standard_EXPORT Handle(Transfer_Binder) MapItem (const Standard_Integer num) const;
265
36b9ff75 266 //! Declares <obj> (and its Result) as Root. This status will be
267 //! later exploited by RootResult, see below (Result can be
268 //! produced at any time)
42cf5bc1 269 Standard_EXPORT void SetRoot (const Handle(Transfer_Finder)& start);
270
36b9ff75 271 //! Enable (if <stat> True) or Disables (if <stat> False) Root
272 //! Management. If it is set, Transfers are considered as stacked
273 //! (a first Transfer commands other Transfers, and so on) and
274 //! the Transfers commanded by an external caller are "Root".
275 //! Remark : SetRoot can be called whatever this status, on every
276 //! object.
277 //! Default is set to True.
42cf5bc1 278 Standard_EXPORT void SetRootManagement (const Standard_Boolean stat);
279
36b9ff75 280 //! Returns the count of recorded Roots
42cf5bc1 281 Standard_EXPORT Standard_Integer NbRoots() const;
282
36b9ff75 283 //! Returns a Root Entity given its number in the list (1-NbRoots)
42cf5bc1 284 Standard_EXPORT const Handle(Transfer_Finder)& Root (const Standard_Integer num) const;
285
36b9ff75 286 //! Returns the Binder bound with a Root Entity given its number
287 //! Considers a category number, by default 0
42cf5bc1 288 Standard_EXPORT Handle(Transfer_Binder) RootItem (const Standard_Integer num) const;
289
36b9ff75 290 //! Returns the index in the list of roots for a starting item,
291 //! or 0 if it is not recorded as a root
42cf5bc1 292 Standard_EXPORT Standard_Integer RootIndex (const Handle(Transfer_Finder)& start) const;
293
36b9ff75 294 //! Returns Nesting Level of Transfers (managed by methods
295 //! TranscriptWith & Co). Starts to zero. If no automatic Transfer
296 //! is used, it remains to zero. Zero means Root Level.
42cf5bc1 297 Standard_EXPORT Standard_Integer NestingLevel() const;
298
36b9ff75 299 //! Resets Nesting Level of Transfers to Zero (Root Level),
300 //! whatever its current value.
42cf5bc1 301 Standard_EXPORT void ResetNestingLevel();
302
36b9ff75 303 //! Tells if <start> has been recognized as good candidate for
304 //! Transfer. i.e. queries the Actor and its Nexts
42cf5bc1 305 Standard_EXPORT Standard_Boolean Recognize (const Handle(Transfer_Finder)& start) const;
306
36b9ff75 307 //! Performs the Transfer of a Starting Object, by calling
308 //! the method TransferProduct (see below).
309 //! Mapping and Roots are managed : nothing is done if a Result is
310 //! already Bound, an exception is raised in case of error.
42cf5bc1 311 Standard_EXPORT Handle(Transfer_Binder) Transferring (const Handle(Transfer_Finder)& start);
312
36b9ff75 313 //! Same as Transferring but does not return the Binder.
314 //! Simply returns True in case of success (for user call)
42cf5bc1 315 Standard_EXPORT Standard_Boolean Transfer (const Handle(Transfer_Finder)& start);
316
36b9ff75 317 //! Allows controls if exceptions will be handled
318 //! Transfer Operations
319 //! <err> False : they are not handled with try {} catch {}
320 //! <err> True : they are
321 //! Default is False: no handling performed
42cf5bc1 322 Standard_EXPORT void SetErrorHandle (const Standard_Boolean err);
323
36b9ff75 324 //! Returns error handling flag
42cf5bc1 325 Standard_EXPORT Standard_Boolean ErrorHandle() const;
326
36b9ff75 327 //! Method called when trace is asked
328 //! Calls PrintTrace to display information relevant for starting
329 //! objects (which can be redefined)
330 //! <level> is Nesting Level of Transfer (0 = root)
331 //! <mode> controls the way the trace is done :
332 //! 0 neutral, 1 for Error, 2 for Warning message, 3 for new Root
42cf5bc1 333 Standard_EXPORT void StartTrace (const Handle(Transfer_Binder)& binder, const Handle(Transfer_Finder)& start, const Standard_Integer level, const Standard_Integer mode) const;
334
36b9ff75 335 //! Prints a short information on a starting object. By default
336 //! prints its Dynamic Type. Can be redefined
42cf5bc1 337 Standard_EXPORT virtual void PrintTrace (const Handle(Transfer_Finder)& start, const Handle(Message_Messenger)& S) const;
338
36b9ff75 339 //! Returns True if we are surely in a DeadLoop. Evaluation is not
340 //! exact, it is a "majorant" which must be computed fast.
341 //! This "majorant" is : <alevel> greater than NbMapped.
42cf5bc1 342 Standard_EXPORT Standard_Boolean IsLooping (const Standard_Integer alevel) const;
343
36b9ff75 344 //! Returns, as an iterator, the log of root transfer, i.e. the
345 //! created objects and Binders bound to starting roots
346 //! If withstart is given True, Starting Objets are also returned
42cf5bc1 347 Standard_EXPORT Transfer_IteratorOfProcessForFinder RootResult (const Standard_Boolean withstart = Standard_False) const;
348
36b9ff75 349 //! Returns, as an Iterator, the entire log of transfer (list of
350 //! created objects and Binders which can bring errors)
351 //! If withstart is given True, Starting Objets are also returned
42cf5bc1 352 Standard_EXPORT Transfer_IteratorOfProcessForFinder CompleteResult (const Standard_Boolean withstart = Standard_False) const;
353
36b9ff75 354 //! Returns Binders which are neither "Done" nor "Initial",
355 //! that is Error,Loop or Run (abnormal states at end of Transfer)
356 //! Starting Objects are given in correspondance in the iterator
42cf5bc1 357 Standard_EXPORT Transfer_IteratorOfProcessForFinder AbnormalResult() const;
358
36b9ff75 359 //! Returns a CheckList as a list of Check : each one is for a
360 //! starting entity which have either check (warning or fail)
361 //! messages are attached, or are in abnormal state : that case
362 //! gives a specific message
363 //! If <erronly> is True, checks with Warnings only are ignored
42cf5bc1 364 Standard_EXPORT Interface_CheckIterator CheckList (const Standard_Boolean erronly) const;
365
36b9ff75 366 //! Returns, as an Iterator, the log of transfer for one object
367 //! <level> = 0 : this object only
368 //! and if <start> is a scope owner (else, <level> is ignored) :
369 //! <level> = 1 : object plus its immediate scoped ones
370 //! <level> = 2 : object plus all its scoped ones
42cf5bc1 371 Standard_EXPORT Transfer_IteratorOfProcessForFinder ResultOne (const Handle(Transfer_Finder)& start, const Standard_Integer level, const Standard_Boolean withstart = Standard_False) const;
372
36b9ff75 373 //! Returns a CheckList for one starting object
374 //! <level> interpreted as by ResultOne
375 //! If <erronly> is True, checks with Warnings only are ignored
42cf5bc1 376 Standard_EXPORT Interface_CheckIterator CheckListOne (const Handle(Transfer_Finder)& start, const Standard_Integer level, const Standard_Boolean erronly) const;
377
36b9ff75 378 //! Returns True if no check message is attached to a starting
379 //! object. <level> interpreted as by ResultOne
380 //! If <erronly> is True, checks with Warnings only are ignored
42cf5bc1 381 Standard_EXPORT Standard_Boolean IsCheckListEmpty (const Handle(Transfer_Finder)& start, const Standard_Integer level, const Standard_Boolean erronly) const;
382
36b9ff75 383 //! Removes Results attached to (== Unbinds) a given object and,
384 //! according <level> :
385 //! <level> = 0 : only it
386 //! <level> = 1 : it plus its immediately owned sub-results(scope)
387 //! <level> = 2 : it plus all its owned sub-results(scope)
42cf5bc1 388 Standard_EXPORT void RemoveResult (const Handle(Transfer_Finder)& start, const Standard_Integer level, const Standard_Boolean compute = Standard_True);
389
36b9ff75 390 //! Computes a number to be associated to a starting object in
391 //! a check or a check-list
392 //! By default, returns 0; can be redefined
42cf5bc1 393 Standard_EXPORT virtual Standard_Integer CheckNum (const Handle(Transfer_Finder)& start) const;
394
36b9ff75 395 //! Sets Progress indicator
42cf5bc1 396 Standard_EXPORT void SetProgress (const Handle(Message_ProgressIndicator)& theProgress);
397
36b9ff75 398 //! Gets Progress indicator
42cf5bc1 399 Standard_EXPORT Handle(Message_ProgressIndicator) GetProgress() const;
400
401
402
403
404 DEFINE_STANDARD_RTTI(Transfer_ProcessForFinder,MMgt_TShared)
405
406protected:
407
408
409
410
411private:
412
413
36b9ff75 414 //! Same as Find but stores the last access to the map, for a
415 //! faster access on next calls (as Bind does too)
416 //! Considers a category number, by default 0
417 //! C++ : return const &
42cf5bc1 418 Standard_EXPORT Handle(Transfer_Binder) FindAndMask (const Handle(Transfer_Finder)& start);
419
36b9ff75 420 //! Internal action of Transfer, called by Transferring, with or
421 //! without ErrorHandle. It invokes the Actor to work (set by
422 //! SetActor), and tries its Nexts if no result is produced,
423 //! until a Non Null Binder is produced.
424 //! But keep in mind that a Null Binder can allways be returned
425 //! if a Starting Entity has not been recognized at all.
42cf5bc1 426 Standard_EXPORT Handle(Transfer_Binder) TransferProduct (const Handle(Transfer_Finder)& start);
427
428 Standard_Boolean theerrh;
429 Standard_Integer thetrace;
430 Handle(Message_Messenger) themessenger;
431 Standard_Integer thelevel;
432 Standard_Integer therootl;
433 Standard_Boolean therootm;
434 TColStd_IndexedMapOfInteger theroots;
435 Handle(Transfer_Finder) thelastobj;
436 Handle(Transfer_Binder) thelastbnd;
437 Standard_Integer theindex;
438 Handle(Transfer_ActorOfProcessForFinder) theactor;
439 Transfer_TransferMapOfProcessForFinder themap;
440 Handle(Message_ProgressIndicator) myProgress;
441
442
443};
444
445
446
447
448
449
450
451#endif // _Transfer_ProcessForFinder_HeaderFile