Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-08 09:17:57

0001 // Created on: 1992-02-03
0002 // Created by: Christian CAILLET
0003 // Copyright (c) 1992-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _Transfer_ProcessForFinder_HeaderFile
0018 #define _Transfer_ProcessForFinder_HeaderFile
0019 
0020 #include <TColStd_IndexedMapOfInteger.hxx>
0021 #include <Transfer_HSequenceOfFinder.hxx>
0022 #include <Transfer_TransferMapOfProcessForFinder.hxx>
0023 #include <Message_ProgressRange.hxx>
0024 
0025 class Message_Messenger;
0026 class Transfer_Finder;
0027 class Transfer_Binder;
0028 class Transfer_ActorOfProcessForFinder;
0029 class Interface_InterfaceError;
0030 class Transfer_TransferFailure;
0031 class Transfer_FindHasher;
0032 class Transfer_IteratorOfProcessForFinder;
0033 class Message_Msg;
0034 class Interface_Check;
0035 class Standard_Transient;
0036 class Interface_CheckIterator;
0037 
0038 class Transfer_ProcessForFinder;
0039 DEFINE_STANDARD_HANDLE(Transfer_ProcessForFinder, Standard_Transient)
0040 
0041 class Transfer_ProcessForFinder : public Standard_Transient
0042 {
0043 
0044 public:
0045   //! Sets TransferProcess at initial state. Gives an Initial size
0046   //! (indicative) for the Map when known (default is 10000).
0047   //! Sets default trace file as a printer and default trace level
0048   //! (see Message_TraceFile).
0049   Standard_EXPORT Transfer_ProcessForFinder(const Standard_Integer nb = 10000);
0050 
0051   //! Sets TransferProcess at initial state. Gives an Initial size
0052   //! (indicative) for the Map when known (default is 10000).
0053   //! Sets a specified printer.
0054   Standard_EXPORT Transfer_ProcessForFinder(const Handle(Message_Messenger)& printer,
0055                                             const Standard_Integer           nb = 10000);
0056 
0057   //! Resets a TransferProcess as ready for a completely new work.
0058   //! Clears general data (roots) and the Map
0059   Standard_EXPORT void Clear();
0060 
0061   //! Rebuilds the Map and the roots to really remove Unbound items
0062   //! Because Unbind keeps the entity in place, even if not bound
0063   //! Hence, working by checking new items is meaningless if a
0064   //! formerly unbound item is rebound
0065   Standard_EXPORT void Clean();
0066 
0067   //! Resizes the Map as required (if a new reliable value has been
0068   //! determined). Acts only if <nb> is greater than actual NbMapped
0069   Standard_EXPORT void Resize(const Standard_Integer nb);
0070 
0071   //! Defines an Actor, which is used for automatic Transfer
0072   //! If already defined, the new Actor is cumulated
0073   //! (see SetNext from Actor)
0074   Standard_EXPORT void SetActor(const Handle(Transfer_ActorOfProcessForFinder)& actor);
0075 
0076   //! Returns the defined Actor. Returns a Null Handle if
0077   //! not set.
0078   Standard_EXPORT Handle(Transfer_ActorOfProcessForFinder) Actor() const;
0079 
0080   //! Returns the Binder which is linked with a starting Object
0081   //! It can either bring a Result (Transfer done) or none (for a
0082   //! pre-binding).
0083   //! If no Binder is linked with <start>, returns a Null Handle
0084   //! Considers a category number, by default 0
0085   Standard_EXPORT Handle(Transfer_Binder) Find(const Handle(Transfer_Finder)& start) const;
0086 
0087   //! Returns True if a Result (whatever its form) is Bound with
0088   //! a starting Object. I.e., if a Binder with a Result set,
0089   //! is linked with it
0090   //! Considers a category number, by default 0
0091   Standard_EXPORT Standard_Boolean IsBound(const Handle(Transfer_Finder)& start) const;
0092 
0093   //! Returns True if the result of the transfer of an object is
0094   //! already used in other ones. If it is, Rebind cannot change it.
0095   //! Considers a category number, by default 0
0096   Standard_EXPORT Standard_Boolean IsAlreadyUsed(const Handle(Transfer_Finder)& start) const;
0097 
0098   //! Creates a Link a starting Object with a Binder. This Binder
0099   //! can either bring a Result (effective Binding) or none (it can
0100   //! be set later : pre-binding).
0101   //! Considers a category number, by default 0
0102   Standard_EXPORT void Bind(const Handle(Transfer_Finder)& start,
0103                             const Handle(Transfer_Binder)& binder);
0104 
0105   //! Changes the Binder linked with a starting Object for its
0106   //! unitary transfer. This it can be useful when the exact form
0107   //! of the result is known once the transfer is widely engaged.
0108   //! This can be done only on first transfer.
0109   //! Considers a category number, by default 0
0110   Standard_EXPORT void Rebind(const Handle(Transfer_Finder)& start,
0111                               const Handle(Transfer_Binder)& binder);
0112 
0113   //! Removes the Binder linked with a starting object
0114   //! If this Binder brings a non-empty Check, it is replaced by
0115   //! a VoidBinder. Also removes from the list of Roots as required.
0116   //! Returns True if done, False if <start> was not bound
0117   //! Considers a category number, by default 0
0118   Standard_EXPORT Standard_Boolean Unbind(const Handle(Transfer_Finder)& start);
0119 
0120   //! Returns a Binder for a starting entity, as follows :
0121   //! Tries to Find the already bound one
0122   //! If none found, creates a VoidBinder and Binds it
0123   Standard_EXPORT Handle(Transfer_Binder) FindElseBind(const Handle(Transfer_Finder)& start);
0124 
0125   //! Sets Messenger used for outputting messages.
0126   Standard_EXPORT void SetMessenger(const Handle(Message_Messenger)& messenger);
0127 
0128   //! Returns Messenger used for outputting messages.
0129   //! The returned object is guaranteed to be non-null;
0130   //! default is Message::Messenger().
0131   Standard_EXPORT Handle(Message_Messenger) Messenger() const;
0132 
0133   //! Sets trace level used for outputting messages:
0134   //! <trace> = 0 : no trace at all
0135   //! <trace> = 1 : handled exceptions and calls to AddError
0136   //! <trace> = 2 : also calls to AddWarning
0137   //! <trace> = 3 : also traces new Roots
0138   //! (uses method ErrorTrace).
0139   //! Default is 1 : Errors traced
0140   Standard_EXPORT void SetTraceLevel(const Standard_Integer tracelev);
0141 
0142   //! Returns trace level used for outputting messages.
0143   Standard_EXPORT Standard_Integer TraceLevel() const;
0144 
0145   //! New name for AddFail (Msg)
0146   Standard_EXPORT void SendFail(const Handle(Transfer_Finder)& start, const Message_Msg& amsg);
0147 
0148   //! New name for AddWarning (Msg)
0149   Standard_EXPORT void SendWarning(const Handle(Transfer_Finder)& start, const Message_Msg& amsg);
0150 
0151   //! Adds an information message
0152   //! Trace is filled if trace level is at least 3
0153   Standard_EXPORT void SendMsg(const Handle(Transfer_Finder)& start, const Message_Msg& amsg);
0154 
0155   //! Adds an Error message to a starting entity (to the check of
0156   //! its Binder of category 0, as a Fail)
0157   Standard_EXPORT void AddFail(const Handle(Transfer_Finder)& start,
0158                                const Standard_CString         mess,
0159                                const Standard_CString         orig = "");
0160 
0161   //! (other name of AddFail, maintained for compatibility)
0162   Standard_EXPORT void AddError(const Handle(Transfer_Finder)& start,
0163                                 const Standard_CString         mess,
0164                                 const Standard_CString         orig = "");
0165 
0166   //! Adds an Error Message to a starting entity from the definition
0167   //! of a Msg (Original+Value)
0168   Standard_EXPORT void AddFail(const Handle(Transfer_Finder)& start, const Message_Msg& amsg);
0169 
0170   //! Adds a Warning message to a starting entity (to the check of
0171   //! its Binder of category 0)
0172   Standard_EXPORT void AddWarning(const Handle(Transfer_Finder)& start,
0173                                   const Standard_CString         mess,
0174                                   const Standard_CString         orig = "");
0175 
0176   //! Adds a Warning Message to a starting entity from the definition
0177   //! of a Msg (Original+Value)
0178   Standard_EXPORT void AddWarning(const Handle(Transfer_Finder)& start, const Message_Msg& amsg);
0179 
0180   Standard_EXPORT void Mend(const Handle(Transfer_Finder)& start, const Standard_CString pref = "");
0181 
0182   //! Returns the Check attached to a starting entity. If <start>
0183   //! is unknown, returns an empty Check
0184   //! Adds a case name to a starting entity
0185   //! Adds a case value to a starting entity
0186   //! Returns the complete case list for an entity. Null Handle if empty
0187   //! In the list of mapped items (between 1 and NbMapped),
0188   //! searches for the first item which follows <num0>(not included)
0189   //! and which has an attribute named <name>
0190   //! Attributes are brought by Binders
0191   //! Hence, allows such an iteration
0192   //!
0193   //! for (num = TP->NextItemWithAttribute(name,0);
0194   //! num > 0;
0195   //! num = TP->NextItemWithAttribute(name,num) {
0196   //! .. process mapped item <num>
0197   //! }
0198   //! Returns the type of an Attribute attached to binders
0199   //! If this name gives no Attribute, returns ParamVoid
0200   //! If this name gives several different types, returns ParamMisc
0201   //! Else, returns the effective type (ParamInteger, ParamReal,
0202   //! ParamIdent, or ParamText)
0203   //! Returns the list of recorded Attribute Names, as a Dictionary
0204   //! of Integer : each value gives the count of items which bring
0205   //! this attribute name
0206   //! By default, considers all the attribute names
0207   //! If <rootname> is given, considers only the attribute names
0208   //! which begin by <rootname>
0209   Standard_EXPORT Handle(Interface_Check) Check(const Handle(Transfer_Finder)& start) const;
0210 
0211   //! Binds a starting object with a Transient Result.
0212   //! Uses a SimpleBinderOfTransient to work. If there is already
0213   //! one but with no Result set, sets its Result.
0214   //! Considers a category number, by default 0
0215   Standard_EXPORT void BindTransient(const Handle(Transfer_Finder)&    start,
0216                                      const Handle(Standard_Transient)& res);
0217 
0218   //! Returns the Result of the Transfer of an object <start> as a
0219   //! Transient Result.
0220   //! Returns a Null Handle if there is no Transient Result
0221   //! Considers a category number, by default 0
0222   //! Warning : Supposes that Binding is done with a SimpleBinderOfTransient
0223   Standard_EXPORT const Handle(Standard_Transient)& FindTransient(
0224     const Handle(Transfer_Finder)& start) const;
0225 
0226   //! Prepares an object <start> to be bound with several results.
0227   //! If no Binder is yet attached to <obj>, a MultipleBinder
0228   //! is created, empty. If a Binder is already set, it must
0229   //! accept Multiple Binding.
0230   //! Considers a category number, by default 0
0231   Standard_EXPORT void BindMultiple(const Handle(Transfer_Finder)& start);
0232 
0233   //! Adds an item to a list of results bound to a starting object.
0234   //! Considers a category number, by default 0, for all results
0235   Standard_EXPORT void AddMultiple(const Handle(Transfer_Finder)&    start,
0236                                    const Handle(Standard_Transient)& res);
0237 
0238   //! Searches for a transient result attached to a starting object,
0239   //! according to its type, by criterium IsKind(atype)
0240   //!
0241   //! In case of multiple result, explores the list and gives in
0242   //! <val> the first transient result IsKind(atype)
0243   //! Returns True and fills <val> if found
0244   //! Else, returns False (<val> is not touched, not even nullified)
0245   //!
0246   //! This syntactic form avoids to do DownCast : if a result is
0247   //! found with the good type, it is loaded in <val> and can be
0248   //! immediately used, well initialised
0249   Standard_EXPORT Standard_Boolean FindTypedTransient(const Handle(Transfer_Finder)& start,
0250                                                       const Handle(Standard_Type)&   atype,
0251                                                       Handle(Standard_Transient)&    val) const;
0252 
0253   //! Safe variant for arbitrary type of argument
0254   template <class T>
0255   Standard_Boolean FindTypedTransient(const Handle(Transfer_Finder)& start,
0256                                       const Handle(Standard_Type)&   atype,
0257                                       Handle(T)&                     val) const
0258   {
0259     Handle(Standard_Transient) aVal = val;
0260     return FindTypedTransient(start, atype, aVal) && !(val = Handle(T)::DownCast(aVal)).IsNull();
0261   }
0262 
0263   //! Searches for a transient result recorded in a Binder, whatever
0264   //! this Binder is recorded or not in <me>
0265   //!
0266   //! This is strictly equivalent to the class method GetTypedResult
0267   //! from class SimpleBinderOfTransient, but is just lighter to call
0268   //!
0269   //! Apart from this, works as FindTypedTransient
0270   Standard_EXPORT Standard_Boolean GetTypedTransient(const Handle(Transfer_Binder)& binder,
0271                                                      const Handle(Standard_Type)&   atype,
0272                                                      Handle(Standard_Transient)&    val) const;
0273 
0274   //! Safe variant for arbitrary type of argument
0275   template <class T>
0276   Standard_Boolean GetTypedTransient(const Handle(Transfer_Binder)& start,
0277                                      const Handle(Standard_Type)&   atype,
0278                                      Handle(T)&                     val) const
0279   {
0280     Handle(Standard_Transient) aVal = val;
0281     return GetTypedTransient(start, atype, aVal) && !(val = Handle(T)::DownCast(aVal)).IsNull();
0282   }
0283 
0284   //! Returns the maximum possible value for Map Index
0285   //! (no result can be bound with a value greater than it)
0286   Standard_EXPORT Standard_Integer NbMapped() const;
0287 
0288   //! Returns the Starting Object bound to an Index,
0289   Standard_EXPORT const Handle(Transfer_Finder)& Mapped(const Standard_Integer num) const;
0290 
0291   //! Returns the Index value bound to a Starting Object, 0 if none
0292   Standard_EXPORT Standard_Integer MapIndex(const Handle(Transfer_Finder)& start) const;
0293 
0294   //! Returns the Binder bound to an Index
0295   //! Considers a category number, by default 0
0296   Standard_EXPORT Handle(Transfer_Binder) MapItem(const Standard_Integer num) const;
0297 
0298   //! Declares <obj> (and its Result) as Root. This status will be
0299   //! later exploited by RootResult, see below (Result can be
0300   //! produced at any time)
0301   Standard_EXPORT void SetRoot(const Handle(Transfer_Finder)& start);
0302 
0303   //! Enable (if <stat> True) or Disables (if <stat> False) Root
0304   //! Management. If it is set, Transfers are considered as stacked
0305   //! (a first Transfer commands other Transfers, and so on) and
0306   //! the Transfers commanded by an external caller are "Root".
0307   //! Remark : SetRoot can be called whatever this status, on every
0308   //! object.
0309   //! Default is set to True.
0310   Standard_EXPORT void SetRootManagement(const Standard_Boolean stat);
0311 
0312   //! Returns the count of recorded Roots
0313   Standard_EXPORT Standard_Integer NbRoots() const;
0314 
0315   //! Returns a Root Entity given its number in the list (1-NbRoots)
0316   Standard_EXPORT const Handle(Transfer_Finder)& Root(const Standard_Integer num) const;
0317 
0318   //! Returns the Binder bound with a Root Entity given its number
0319   //! Considers a category number, by default 0
0320   Standard_EXPORT Handle(Transfer_Binder) RootItem(const Standard_Integer num) const;
0321 
0322   //! Returns the index in the list of roots for a starting item,
0323   //! or 0 if it is not recorded as a root
0324   Standard_EXPORT Standard_Integer RootIndex(const Handle(Transfer_Finder)& start) const;
0325 
0326   //! Returns Nesting Level of Transfers (managed by methods
0327   //! TranscriptWith & Co). Starts to zero. If no automatic Transfer
0328   //! is used, it remains to zero. Zero means Root Level.
0329   Standard_EXPORT Standard_Integer NestingLevel() const;
0330 
0331   //! Resets Nesting Level of Transfers to Zero (Root Level),
0332   //! whatever its current value.
0333   Standard_EXPORT void ResetNestingLevel();
0334 
0335   //! Tells if <start> has been recognized as good candidate for
0336   //! Transfer. i.e. queries the Actor and its Nexts
0337   Standard_EXPORT Standard_Boolean Recognize(const Handle(Transfer_Finder)& start) const;
0338 
0339   //! Performs the Transfer of a Starting Object, by calling
0340   //! the method TransferProduct (see below).
0341   //! Mapping and Roots are managed : nothing is done if a Result is
0342   //! already Bound, an exception is raised in case of error.
0343   Standard_EXPORT Handle(Transfer_Binder) Transferring(
0344     const Handle(Transfer_Finder)& start,
0345     const Message_ProgressRange&   theProgress = Message_ProgressRange());
0346 
0347   //! Same as Transferring but does not return the Binder.
0348   //! Simply returns True in case of success (for user call)
0349   Standard_EXPORT Standard_Boolean
0350     Transfer(const Handle(Transfer_Finder)& start,
0351              const Message_ProgressRange&   theProgress = Message_ProgressRange());
0352 
0353   //! Allows controls if exceptions will be handled
0354   //! Transfer Operations
0355   //! <err> False : they are not handled with try {} catch {}
0356   //! <err> True  : they are
0357   //! Default is False: no handling performed
0358   Standard_EXPORT void SetErrorHandle(const Standard_Boolean err);
0359 
0360   //! Returns error handling flag
0361   Standard_EXPORT Standard_Boolean ErrorHandle() const;
0362 
0363   //! Method called when trace is asked
0364   //! Calls PrintTrace to display information relevant for starting
0365   //! objects (which can be redefined)
0366   //! <level> is Nesting Level of Transfer (0 = root)
0367   //! <mode> controls the way the trace is done :
0368   //! 0 neutral, 1 for Error, 2 for Warning message, 3 for new Root
0369   Standard_EXPORT void StartTrace(const Handle(Transfer_Binder)& binder,
0370                                   const Handle(Transfer_Finder)& start,
0371                                   const Standard_Integer         level,
0372                                   const Standard_Integer         mode) const;
0373 
0374   //! Prints a short information on a starting object. By default
0375   //! prints its Dynamic Type. Can be redefined
0376   Standard_EXPORT virtual void PrintTrace(const Handle(Transfer_Finder)& start,
0377                                           Standard_OStream&              S) const;
0378 
0379   //! Returns True if we are surely in a DeadLoop. Evaluation is not
0380   //! exact, it is a "majorant" which must be computed fast.
0381   //! This "majorant" is : <alevel> greater than NbMapped.
0382   Standard_EXPORT Standard_Boolean IsLooping(const Standard_Integer alevel) const;
0383 
0384   //! Returns, as an iterator, the log of root transfer, i.e. the
0385   //! created objects and Binders bound to starting roots
0386   //! If withstart is given True, Starting Objects are also returned
0387   Standard_EXPORT Transfer_IteratorOfProcessForFinder
0388     RootResult(const Standard_Boolean withstart = Standard_False) const;
0389 
0390   //! Returns, as an Iterator, the entire log of transfer (list of
0391   //! created objects and Binders which can bring errors)
0392   //! If withstart is given True, Starting Objects are also returned
0393   Standard_EXPORT Transfer_IteratorOfProcessForFinder
0394     CompleteResult(const Standard_Boolean withstart = Standard_False) const;
0395 
0396   //! Returns Binders which are neither "Done" nor "Initial",
0397   //! that is Error,Loop or Run (abnormal states at end of Transfer)
0398   //! Starting Objects are given in correspondence in the iterator
0399   Standard_EXPORT Transfer_IteratorOfProcessForFinder AbnormalResult() const;
0400 
0401   //! Returns a CheckList as a list of Check : each one is for a
0402   //! starting entity which have either check (warning or fail)
0403   //! messages are attached, or are in abnormal state : that case
0404   //! gives a specific message
0405   //! If <erronly> is True, checks with Warnings only are ignored
0406   Standard_EXPORT Interface_CheckIterator CheckList(const Standard_Boolean erronly) const;
0407 
0408   //! Returns, as an Iterator, the log of transfer for one object
0409   //! <level> = 0 : this object only
0410   //! and if <start> is a scope owner (else, <level> is ignored) :
0411   //! <level> = 1 : object plus its immediate scoped ones
0412   //! <level> = 2 : object plus all its scoped ones
0413   Standard_EXPORT Transfer_IteratorOfProcessForFinder
0414     ResultOne(const Handle(Transfer_Finder)& start,
0415               const Standard_Integer         level,
0416               const Standard_Boolean         withstart = Standard_False) const;
0417 
0418   //! Returns a CheckList for one starting object
0419   //! <level> interpreted as by ResultOne
0420   //! If <erronly> is True, checks with Warnings only are ignored
0421   Standard_EXPORT Interface_CheckIterator CheckListOne(const Handle(Transfer_Finder)& start,
0422                                                        const Standard_Integer         level,
0423                                                        const Standard_Boolean erronly) const;
0424 
0425   //! Returns True if no check message is attached to a starting
0426   //! object. <level> interpreted as by ResultOne
0427   //! If <erronly> is True, checks with Warnings only are ignored
0428   Standard_EXPORT Standard_Boolean IsCheckListEmpty(const Handle(Transfer_Finder)& start,
0429                                                     const Standard_Integer         level,
0430                                                     const Standard_Boolean         erronly) const;
0431 
0432   //! Removes Results attached to (== Unbinds) a given object and,
0433   //! according <level> :
0434   //! <level> = 0 : only it
0435   //! <level> = 1 : it plus its immediately owned sub-results(scope)
0436   //! <level> = 2 : it plus all its owned sub-results(scope)
0437   Standard_EXPORT void RemoveResult(const Handle(Transfer_Finder)& start,
0438                                     const Standard_Integer         level,
0439                                     const Standard_Boolean         compute = Standard_True);
0440 
0441   //! Computes a number to be associated to a starting object in
0442   //! a check or a check-list
0443   //! By default, returns 0; can be redefined
0444   Standard_EXPORT virtual Standard_Integer CheckNum(const Handle(Transfer_Finder)& start) const;
0445 
0446   DEFINE_STANDARD_RTTI_INLINE(Transfer_ProcessForFinder, Standard_Transient)
0447 
0448 protected:
0449 private:
0450   //! Same as Find but stores the last access to the map, for a
0451   //! faster access on next calls (as Bind does too)
0452   //! Considers a category number, by default 0
0453   //! C++ : return const &
0454   Standard_EXPORT Handle(Transfer_Binder) FindAndMask(const Handle(Transfer_Finder)& start);
0455 
0456   //! Internal action of Transfer, called by Transferring, with or
0457   //! without ErrorHandle. It invokes the Actor to work (set by
0458   //! SetActor), and tries its Nexts if no result is produced,
0459   //! until a Non Null Binder is produced.
0460   //! But keep in mind that a Null Binder can always be returned
0461   //! if a Starting Entity has not been recognized at all.
0462   Standard_EXPORT Handle(Transfer_Binder) TransferProduct(
0463     const Handle(Transfer_Finder)& start,
0464     const Message_ProgressRange&   theProgress = Message_ProgressRange());
0465 
0466   Standard_Boolean                         theerrh;
0467   Standard_Integer                         thetrace;
0468   Handle(Message_Messenger)                themessenger;
0469   Standard_Integer                         thelevel;
0470   Standard_Integer                         therootl;
0471   Standard_Boolean                         therootm;
0472   TColStd_IndexedMapOfInteger              theroots;
0473   Handle(Transfer_Finder)                  thelastobj;
0474   Handle(Transfer_Binder)                  thelastbnd;
0475   Standard_Integer                         theindex;
0476   Handle(Transfer_ActorOfProcessForFinder) theactor;
0477   Transfer_TransferMapOfProcessForFinder   themap;
0478 };
0479 
0480 #endif // _Transfer_ProcessForFinder_HeaderFile