1 // Copyright (c) 2020 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _Message_ProgressRange_HeaderFile
15 #define _Message_ProgressRange_HeaderFile
17 #include <Standard_TypeDef.hxx>
19 class Message_ProgressScope;
21 //! Auxiliary class representing a part of the global progress scale allocated by
22 //! a step of the progress scope, see Message_ProgressScope::Next().
24 //! A range object takes responsibility of advancing the progress by the size of
25 //! allocated step, which is then performed depending on how it is used:
27 //! - If Message_ProgressScope object is created using this range as argument, then
28 //! this respondibility is taken over by that scope.
30 //! - Otherwise, a range advances progress directly upon destruction.
32 //! A range object can be copied, the responsibility for progress advancement is
33 //! then taken by the copy.
34 //! The same range object may be used (either copied or used to create scope) only once.
35 //! Any consequenct attempts to use range will give no result on the progress;
36 //! in debug mode, an assert message will be generated.
38 //! @sa Message_ProgressScope for more details
39 class Message_ProgressRange
42 //! Constructor of the range
43 Message_ProgressRange()
44 : myParentScope (0), myDelta (0), myWasUsed (false)
47 //! Copy constructor disarms the source.
48 Message_ProgressRange (const Message_ProgressRange& theOther)
49 : myParentScope (theOther.myParentScope),
50 myDelta (theOther.myDelta),
51 myWasUsed (theOther.myWasUsed)
54 theOther.myWasUsed = true;
57 //! Copy assignment disarms the source.
58 Message_ProgressRange& operator=(const Message_ProgressRange& theOther)
60 myParentScope = theOther.myParentScope;
61 myDelta = theOther.myDelta;
62 myWasUsed = theOther.myWasUsed;
63 theOther.myWasUsed = true;
67 //! Returns true if ProgressIndicator signals UserBreak
68 Standard_Boolean UserBreak() const;
70 //! Returns false if ProgressIndicator signals UserBreak
71 Standard_Boolean More() const
76 //! Returns true if this progress range is attached to some indicator.
77 Standard_Boolean IsActive() const;
79 //! Closes the current range and advances indicator
83 ~Message_ProgressRange()
89 //! Constructor is private
90 Message_ProgressRange (const Message_ProgressScope& theParent, Standard_Real theDelta)
91 : myParentScope (&theParent),
97 const Message_ProgressScope* myParentScope; //!< Pointer to parent scope
98 Standard_Real myDelta; //!< Step of incrementation
99 mutable Standard_Boolean myWasUsed; //!< Flag indicating that this range
100 //! was used to create a new scope
102 friend class Message_ProgressScope;
105 #include <Message_ProgressIndicator.hxx>
107 //=======================================================================
108 //function : IsActive
110 //=======================================================================
111 inline Standard_Boolean Message_ProgressRange::IsActive() const
113 return !myWasUsed && myParentScope && myParentScope->myProgress;
116 //=======================================================================
117 //function : UserBreak
119 //=======================================================================
120 inline Standard_Boolean Message_ProgressRange::UserBreak() const
122 return myParentScope && myParentScope->myProgress && myParentScope->myProgress->UserBreak();
125 //=======================================================================
128 //=======================================================================
129 inline void Message_ProgressRange::Close()
134 myParentScope->myProgress->Increment(myDelta, *myParentScope);
139 #endif // _Message_ProgressRange_HeaderFile