Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:29

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