Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2003-03-04 |
2 | // Created by: Pavel TELKOV | |
973c2be1 | 3 | // Copyright (c) 2003-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
b311480e | 15 | |
7fd59977 | 16 | // The original implementation copyright (c) RINA S.p.A. |
17 | ||
18 | #ifndef Message_ExecStatus_HeaderFile | |
19 | #define Message_ExecStatus_HeaderFile | |
20 | ||
21 | #include <Message_StatusType.hxx> | |
22 | #include <Message_Status.hxx> | |
23 | ||
24 | /** | |
25 | * Tiny class for extended handling of error / execution | |
26 | * status of algorithm in universal way. | |
27 | * | |
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. | |
31 | * | |
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 | |
40 | */ | |
41 | ||
be5c3602 | 42 | class Message_ExecStatus |
7fd59977 | 43 | { |
44 | ||
45 | private: | |
46 | ||
47 | //! Mask to separate bits indicating status type and index within the type | |
48 | enum StatusMask { | |
49 | MType = 0x0000ff00, | |
50 | MIndex = 0x000000ff | |
51 | }; | |
52 | static inline int getBitFlag (int status) | |
53 | { | |
54 | return 0x1 << (status & MIndex); | |
55 | } | |
56 | ||
57 | public: | |
58 | //!@name Creation and simple operations with statuses | |
59 | //!@{ | |
60 | ||
61 | //! Create empty execution status | |
62 | Message_ExecStatus () | |
63 | : myDone( Message_None), myWarn( Message_None), | |
64 | myAlarm( Message_None), myFail( Message_None) | |
65 | {} | |
66 | ||
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) | |
71 | { | |
72 | Set( status ); | |
73 | } | |
74 | ||
75 | //! Sets a status flag | |
76 | void Set (Message_Status status) | |
77 | { | |
78 | switch( status & MType ) | |
79 | { | |
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; | |
84 | default: break; | |
85 | } | |
86 | } | |
87 | ||
88 | //! Check status for being set | |
89 | Standard_Boolean IsSet (Message_Status status) const | |
90 | { | |
91 | switch( status & MType ) | |
92 | { | |
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; | |
98 | } | |
99 | } | |
100 | ||
101 | //! Clear one status | |
102 | void Clear (Message_Status status) | |
103 | { | |
104 | switch( status & MType ) | |
105 | { | |
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; | |
110 | default: return; | |
111 | } | |
112 | } | |
113 | ||
114 | //!@} | |
115 | ||
116 | //!@name Advanced: Group operations (useful for analysis) | |
117 | //!@{ | |
118 | ||
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; } | |
124 | ||
125 | //! Set all statuses of each type | |
5640d653 DB |
126 | void SetAllDone () { myDone = ~0; } |
127 | void SetAllWarn () { myWarn = ~0; } | |
128 | void SetAllAlarm () { myAlarm = ~0; } | |
129 | void SetAllFail () { myFail = ~0; } | |
7fd59977 | 130 | |
131 | //! Clear all statuses of each type | |
5640d653 DB |
132 | void ClearAllDone () { myDone = Message_None; } |
133 | void ClearAllWarn () { myWarn = Message_None; } | |
134 | void ClearAllAlarm() { myAlarm = Message_None; } | |
135 | void ClearAllFail () { myFail = Message_None; } | |
7fd59977 | 136 | |
137 | //! Clear all statuses | |
138 | void Clear () | |
139 | { | |
140 | myDone = myWarn = myAlarm = myFail = Message_None; | |
141 | } | |
142 | ||
143 | //! Add statuses to me from theOther execution status | |
144 | void Add ( const Message_ExecStatus& theOther ) | |
145 | { | |
146 | myDone |= theOther.myDone; | |
147 | myWarn |= theOther.myWarn; | |
148 | myAlarm |= theOther.myAlarm; | |
149 | myFail |= theOther.myFail; | |
150 | } | |
151 | const Message_ExecStatus& operator |= ( const Message_ExecStatus& theOther ) | |
152 | { Add ( theOther ); return *this; } | |
153 | ||
154 | //! Leave only the statuses common with theOther | |
155 | void And ( const Message_ExecStatus& theOther ) | |
156 | { | |
157 | myDone &= theOther.myDone; | |
158 | myWarn &= theOther.myWarn; | |
159 | myAlarm &= theOther.myAlarm; | |
160 | myFail &= theOther.myFail; | |
161 | } | |
162 | const Message_ExecStatus& operator &= ( const Message_ExecStatus& theOther ) | |
163 | { And ( theOther ); return *this; } | |
164 | ||
165 | //@} | |
166 | ||
167 | public: | |
168 | ||
169 | //!@name Advanced: Iteration and analysis of status flags | |
170 | //!@{ | |
171 | ||
172 | //! Definitions of range of available statuses | |
173 | enum StatusRange | |
174 | { | |
175 | FirstStatus = 1, | |
176 | StatusesPerType = 32, | |
177 | NbStatuses = 128, | |
178 | LastStatus = 129 | |
179 | }; | |
180 | ||
181 | //! Returns index of status in whole range [FirstStatus, LastStatus] | |
182 | static Standard_Integer StatusIndex( Message_Status status ) | |
183 | { | |
184 | switch( status & MType ) | |
185 | { | |
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); | |
190 | default: return 0; | |
191 | } | |
192 | } | |
193 | ||
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 ) | |
197 | { | |
198 | return (status & MIndex) + 1; | |
199 | } | |
200 | ||
201 | //! Returns status type (DONE, WARN, ALARM, or FAIL) | |
202 | static Message_StatusType TypeOfStatus( Message_Status status ) | |
203 | { | |
204 | return (Message_StatusType)(status & MType); | |
205 | } | |
206 | ||
207 | //! Returns status with index theIndex in whole range [FirstStatus, LastStatus] | |
208 | static Message_Status StatusByIndex( const Standard_Integer theIndex ) | |
209 | { | |
210 | Standard_Integer indx = theIndex - 1; | |
211 | if ( indx < 32 ) | |
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 )); | |
219 | return Message_None; | |
220 | } | |
221 | ||
222 | //!@} | |
223 | ||
224 | private: | |
225 | // ---------- PRIVATE FIELDS ---------- | |
226 | Standard_Integer myDone; | |
227 | Standard_Integer myWarn; | |
228 | Standard_Integer myAlarm; | |
229 | Standard_Integer myFail; | |
230 | }; | |
231 | ||
232 | #endif |