1 // Created on: 2003-03-04
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2003-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // The original implementation copyright (c) RINA S.p.A.
18 #ifndef Message_ExecStatus_HeaderFile
19 #define Message_ExecStatus_HeaderFile
21 #include <Message_StatusType.hxx>
22 #include <Message_Status.hxx>
25 * Tiny class for extended handling of error / execution
26 * status of algorithm in universal way.
28 * It is in fact a set of integers represented as a collection of bit flags
29 * for each of four types of status; each status flag has its own symbolic
30 * name and can be set/tested individually.
32 * The flags are grouped in semantic groups:
33 * - No flags means nothing done
34 * - Done flags correspond to some operation succesffuly completed
35 * - Warning flags correspond to warning messages on some
36 * potentially wrong situation, not harming algorithm execution
37 * - Alarm flags correspond to more severe warnings about incorrect
38 * user data, while not breaking algorithm execution
39 * - Fail flags correspond to cases when algorithm failed to complete
42 class Message_ExecStatus
47 //! Mask to separate bits indicating status type and index within the type
52 static inline int getBitFlag (int status)
54 return 0x1 << (status & MIndex);
58 //!@name Creation and simple operations with statuses
61 //! Create empty execution status
63 : myDone( Message_None), myWarn( Message_None),
64 myAlarm( Message_None), myFail( Message_None)
67 //! Initialise the execution status
68 Message_ExecStatus ( Message_Status status )
69 : myDone( Message_None), myWarn( Message_None),
70 myAlarm( Message_None), myFail( Message_None)
75 //! Sets a status flag
76 void Set (Message_Status status)
78 switch( status & MType )
80 case Message_DONE: myDone |= (getBitFlag( status )); break;
81 case Message_WARN: myWarn |= (getBitFlag( status )); break;
82 case Message_ALARM:myAlarm |= (getBitFlag( status )); break;
83 case Message_FAIL: myFail |= (getBitFlag( status )); break;
88 //! Check status for being set
89 Standard_Boolean IsSet (Message_Status status) const
91 switch( status & MType )
93 case Message_DONE: return ( myDone & getBitFlag( status ) ? Standard_True : Standard_False );
94 case Message_WARN: return ( myWarn & getBitFlag( status ) ? Standard_True : Standard_False );
95 case Message_ALARM:return ( myAlarm & getBitFlag( status ) ? Standard_True : Standard_False );
96 case Message_FAIL: return ( myFail & getBitFlag( status ) ? Standard_True : Standard_False );
97 default: return Standard_False;
102 void Clear (Message_Status status)
104 switch( status & MType )
106 case Message_DONE: myDone &= ~(getBitFlag( status )); return;
107 case Message_WARN: myWarn &= ~(getBitFlag( status )); return;
108 case Message_ALARM:myAlarm &= ~(getBitFlag( status )); return;
109 case Message_FAIL: myFail &= ~(getBitFlag( status )); return;
116 //!@name Advanced: Group operations (useful for analysis)
119 //! Check if at least one status of each type is set
120 Standard_Boolean IsDone () const { return myDone != Message_None; }
121 Standard_Boolean IsFail () const { return myFail != Message_None; }
122 Standard_Boolean IsWarn () const { return myWarn != Message_None; }
123 Standard_Boolean IsAlarm () const { return myAlarm != Message_None; }
125 //! Set all statuses of each type
126 void SetAllDone () { myDone = ~0; }
127 void SetAllWarn () { myWarn = ~0; }
128 void SetAllAlarm () { myAlarm = ~0; }
129 void SetAllFail () { myFail = ~0; }
131 //! Clear all statuses of each type
132 void ClearAllDone () { myDone = Message_None; }
133 void ClearAllWarn () { myWarn = Message_None; }
134 void ClearAllAlarm() { myAlarm = Message_None; }
135 void ClearAllFail () { myFail = Message_None; }
137 //! Clear all statuses
140 myDone = myWarn = myAlarm = myFail = Message_None;
143 //! Add statuses to me from theOther execution status
144 void Add ( const Message_ExecStatus& theOther )
146 myDone |= theOther.myDone;
147 myWarn |= theOther.myWarn;
148 myAlarm |= theOther.myAlarm;
149 myFail |= theOther.myFail;
151 const Message_ExecStatus& operator |= ( const Message_ExecStatus& theOther )
152 { Add ( theOther ); return *this; }
154 //! Leave only the statuses common with theOther
155 void And ( const Message_ExecStatus& theOther )
157 myDone &= theOther.myDone;
158 myWarn &= theOther.myWarn;
159 myAlarm &= theOther.myAlarm;
160 myFail &= theOther.myFail;
162 const Message_ExecStatus& operator &= ( const Message_ExecStatus& theOther )
163 { And ( theOther ); return *this; }
169 //!@name Advanced: Iteration and analysis of status flags
172 //! Definitions of range of available statuses
176 StatusesPerType = 32,
181 //! Returns index of status in whole range [FirstStatus, LastStatus]
182 static Standard_Integer StatusIndex( Message_Status status )
184 switch( status & MType )
186 case Message_DONE: return 0 * StatusesPerType + LocalStatusIndex(status);
187 case Message_WARN: return 1 * StatusesPerType + LocalStatusIndex(status);
188 case Message_ALARM: return 2 * StatusesPerType + LocalStatusIndex(status);
189 case Message_FAIL: return 3 * StatusesPerType + LocalStatusIndex(status);
194 //! Returns index of status inside type of status (Done or Warn or, etc)
195 //! in range [1, StatusesPerType]
196 static Standard_Integer LocalStatusIndex( Message_Status status )
198 return (status & MIndex) + 1;
201 //! Returns status type (DONE, WARN, ALARM, or FAIL)
202 static Message_StatusType TypeOfStatus( Message_Status status )
204 return (Message_StatusType)(status & MType);
207 //! Returns status with index theIndex in whole range [FirstStatus, LastStatus]
208 static Message_Status StatusByIndex( const Standard_Integer theIndex )
210 Standard_Integer indx = theIndex - 1;
212 return (Message_Status)(Message_DONE + indx);
213 else if ( indx < 64 )
214 return (Message_Status)(Message_WARN + ( indx - 32 ));
215 else if ( indx < 96 )
216 return (Message_Status)(Message_ALARM + ( indx - 64 ));
217 else if ( indx < 128 )
218 return (Message_Status)(Message_FAIL + ( indx - 96 ));
225 // ---------- PRIVATE FIELDS ----------
226 Standard_Integer myDone;
227 Standard_Integer myWarn;
228 Standard_Integer myAlarm;
229 Standard_Integer myFail;