Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:16

0001 // Copyright (c) 2020 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _Message_ProgressRange_HeaderFile
0015 #define _Message_ProgressRange_HeaderFile
0016 
0017 #include <Standard_TypeDef.hxx>
0018 
0019 class Message_ProgressScope;
0020 
0021 //! Auxiliary class representing a part of the global progress scale allocated by
0022 //! a step of the progress scope, see Message_ProgressScope::Next().
0023 //!
0024 //! A range object takes responsibility of advancing the progress by the size of
0025 //! allocated step, which is then performed depending on how it is used:
0026 //!
0027 //! - If Message_ProgressScope object is created using this range as argument, then
0028 //!   this respondibility is taken over by that scope.
0029 //!
0030 //! - Otherwise, a range advances progress directly upon destruction.
0031 //!
0032 //! A range object can be copied, the responsibility for progress advancement is 
0033 //! then taken by the copy.
0034 //! The same range object may be used (either copied or used to create scope) only once.
0035 //! Any consequent attempts to use range will give no result on the progress;
0036 //! in debug mode, an assert message will be generated.
0037 //!
0038 //! @sa Message_ProgressScope for more details
0039 class Message_ProgressRange
0040 {
0041 public:
0042   //! Constructor of the empty range
0043   Message_ProgressRange()
0044     : myParentScope (0), myStart(0.), myDelta (0.), myWasUsed (false)
0045   {}
0046 
0047   //! Copy constructor disarms the source
0048   Message_ProgressRange (const Message_ProgressRange& theOther)
0049     : myParentScope (theOther.myParentScope),
0050       myStart (theOther.myStart),
0051       myDelta (theOther.myDelta),
0052       myWasUsed (theOther.myWasUsed)
0053   {
0054     // discharge theOther
0055     theOther.myWasUsed = true;
0056   }
0057 
0058   //! Copy assignment disarms the source
0059   Message_ProgressRange& operator=(const Message_ProgressRange& theOther)
0060   {
0061     myParentScope = theOther.myParentScope;
0062     myStart = theOther.myStart;
0063     myDelta = theOther.myDelta;
0064     myWasUsed = theOther.myWasUsed;
0065     theOther.myWasUsed = true;
0066     return *this;
0067   }
0068 
0069   //! Returns true if ProgressIndicator signals UserBreak
0070   Standard_Boolean UserBreak() const;
0071 
0072   //! Returns false if ProgressIndicator signals UserBreak
0073   Standard_Boolean More() const
0074   {
0075     return !UserBreak();
0076   }
0077 
0078   //! Returns true if this progress range is attached to some indicator.
0079   Standard_Boolean IsActive() const;
0080 
0081   //! Closes the current range and advances indicator
0082   void Close();
0083 
0084   //! Destructor
0085   ~Message_ProgressRange()
0086   {
0087     Close();
0088   }
0089 
0090 private:
0091   //! Constructor is private
0092   Message_ProgressRange (const Message_ProgressScope& theParent, 
0093                          Standard_Real theStart, Standard_Real theDelta)
0094     : myParentScope (&theParent),
0095       myStart (theStart),
0096       myDelta (theDelta),
0097       myWasUsed (false)
0098   {}
0099 
0100 private:
0101   const Message_ProgressScope* myParentScope;  //!< Pointer to parent scope
0102   Standard_Real                myStart;        //!< Start point on the global scale
0103   Standard_Real                myDelta;        //!< Step of incrementation on the global scale
0104 
0105   mutable Standard_Boolean     myWasUsed;      //!< Flag indicating that this range
0106                                                //!  was used to create a new scope
0107 
0108   friend class Message_ProgressScope;
0109 };
0110 
0111 #include <Message_ProgressIndicator.hxx>
0112 
0113 //=======================================================================
0114 //function : IsActive
0115 //purpose  :
0116 //=======================================================================
0117 inline Standard_Boolean Message_ProgressRange::IsActive() const
0118 {
0119   return !myWasUsed && myParentScope && myParentScope->myProgress;
0120 }
0121 
0122 //=======================================================================
0123 //function : UserBreak
0124 //purpose  :
0125 //=======================================================================
0126 inline Standard_Boolean Message_ProgressRange::UserBreak() const
0127 {
0128   return myParentScope && myParentScope->myProgress && myParentScope->myProgress->UserBreak();
0129 }
0130 
0131 //=======================================================================
0132 //function : Close
0133 //purpose  :
0134 //=======================================================================
0135 inline void Message_ProgressRange::Close()
0136 {
0137   if (!IsActive())
0138     return;
0139 
0140   myParentScope->myProgress->Increment(myDelta, *myParentScope);
0141   myParentScope = 0;
0142   myWasUsed = true;
0143 }
0144 
0145 #endif // _Message_ProgressRange_HeaderFile