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