b311480e |
1 | // Created on: 2003-03-04 |
2 | // Created by: Pavel TELKOV |
3 | // Copyright (c) 2003-2012 OPEN CASCADE SAS |
4 | // |
5 | // The content of this file is subject to the Open CASCADE Technology Public |
6 | // License Version 6.5 (the "License"). You may not use the content of this file |
7 | // except in compliance with the License. Please obtain a copy of the License |
8 | // at http://www.opencascade.org and read it completely before using this file. |
9 | // |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
12 | // |
13 | // The Original Code and all software distributed under the License is |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
15 | // Initial Developer hereby disclaims all such warranties, including without |
16 | // limitation, any warranties of merchantability, fitness for a particular |
17 | // purpose or non-infringement. Please see the License for the specific terms |
18 | // and conditions governing the rights and limitations under the License. |
19 | |
7fd59977 |
20 | // The original implementation copyright (c) RINA S.p.A. |
21 | |
22 | #ifndef Message_ExecStatus_HeaderFile |
23 | #define Message_ExecStatus_HeaderFile |
24 | |
25 | #include <Message_StatusType.hxx> |
26 | #include <Message_Status.hxx> |
27 | |
28 | /** |
29 | * Tiny class for extended handling of error / execution |
30 | * status of algorithm in universal way. |
31 | * |
32 | * It is in fact a set of integers represented as a collection of bit flags |
33 | * for each of four types of status; each status flag has its own symbolic |
34 | * name and can be set/tested individually. |
35 | * |
36 | * The flags are grouped in semantic groups: |
37 | * - No flags means nothing done |
38 | * - Done flags correspond to some operation succesffuly completed |
39 | * - Warning flags correspond to warning messages on some |
40 | * potentially wrong situation, not harming algorithm execution |
41 | * - Alarm flags correspond to more severe warnings about incorrect |
42 | * user data, while not breaking algorithm execution |
43 | * - Fail flags correspond to cases when algorithm failed to complete |
44 | */ |
45 | |
46 | class Standard_EXPORT Message_ExecStatus |
47 | { |
48 | |
49 | private: |
50 | |
51 | //! Mask to separate bits indicating status type and index within the type |
52 | enum StatusMask { |
53 | MType = 0x0000ff00, |
54 | MIndex = 0x000000ff |
55 | }; |
56 | static inline int getBitFlag (int status) |
57 | { |
58 | return 0x1 << (status & MIndex); |
59 | } |
60 | |
61 | public: |
62 | //!@name Creation and simple operations with statuses |
63 | //!@{ |
64 | |
65 | //! Create empty execution status |
66 | Message_ExecStatus () |
67 | : myDone( Message_None), myWarn( Message_None), |
68 | myAlarm( Message_None), myFail( Message_None) |
69 | {} |
70 | |
71 | //! Initialise the execution status |
72 | Message_ExecStatus ( Message_Status status ) |
73 | : myDone( Message_None), myWarn( Message_None), |
74 | myAlarm( Message_None), myFail( Message_None) |
75 | { |
76 | Set( status ); |
77 | } |
78 | |
79 | //! Sets a status flag |
80 | void Set (Message_Status status) |
81 | { |
82 | switch( status & MType ) |
83 | { |
84 | case Message_DONE: myDone |= (getBitFlag( status )); break; |
85 | case Message_WARN: myWarn |= (getBitFlag( status )); break; |
86 | case Message_ALARM:myAlarm |= (getBitFlag( status )); break; |
87 | case Message_FAIL: myFail |= (getBitFlag( status )); break; |
88 | default: break; |
89 | } |
90 | } |
91 | |
92 | //! Check status for being set |
93 | Standard_Boolean IsSet (Message_Status status) const |
94 | { |
95 | switch( status & MType ) |
96 | { |
97 | case Message_DONE: return ( myDone & getBitFlag( status ) ? Standard_True : Standard_False ); |
98 | case Message_WARN: return ( myWarn & getBitFlag( status ) ? Standard_True : Standard_False ); |
99 | case Message_ALARM:return ( myAlarm & getBitFlag( status ) ? Standard_True : Standard_False ); |
100 | case Message_FAIL: return ( myFail & getBitFlag( status ) ? Standard_True : Standard_False ); |
101 | default: return Standard_False; |
102 | } |
103 | } |
104 | |
105 | //! Clear one status |
106 | void Clear (Message_Status status) |
107 | { |
108 | switch( status & MType ) |
109 | { |
110 | case Message_DONE: myDone &= ~(getBitFlag( status )); return; |
111 | case Message_WARN: myWarn &= ~(getBitFlag( status )); return; |
112 | case Message_ALARM:myAlarm &= ~(getBitFlag( status )); return; |
113 | case Message_FAIL: myFail &= ~(getBitFlag( status )); return; |
114 | default: return; |
115 | } |
116 | } |
117 | |
118 | //!@} |
119 | |
120 | //!@name Advanced: Group operations (useful for analysis) |
121 | //!@{ |
122 | |
123 | //! Check if at least one status of each type is set |
124 | Standard_Boolean IsDone () const { return myDone != Message_None; } |
125 | Standard_Boolean IsFail () const { return myFail != Message_None; } |
126 | Standard_Boolean IsWarn () const { return myWarn != Message_None; } |
127 | Standard_Boolean IsAlarm () const { return myAlarm != Message_None; } |
128 | |
129 | //! Set all statuses of each type |
130 | void SetAllDone () { myDone = ~0; }; |
131 | void SetAllWarn () { myWarn = ~0; }; |
132 | void SetAllAlarm () { myAlarm = ~0; }; |
133 | void SetAllFail () { myFail = ~0; }; |
134 | |
135 | //! Clear all statuses of each type |
136 | void ClearAllDone () { myDone = Message_None; }; |
137 | void ClearAllWarn () { myWarn = Message_None; }; |
138 | void ClearAllAlarm() { myAlarm = Message_None; }; |
139 | void ClearAllFail () { myFail = Message_None; }; |
140 | |
141 | //! Clear all statuses |
142 | void Clear () |
143 | { |
144 | myDone = myWarn = myAlarm = myFail = Message_None; |
145 | } |
146 | |
147 | //! Add statuses to me from theOther execution status |
148 | void Add ( const Message_ExecStatus& theOther ) |
149 | { |
150 | myDone |= theOther.myDone; |
151 | myWarn |= theOther.myWarn; |
152 | myAlarm |= theOther.myAlarm; |
153 | myFail |= theOther.myFail; |
154 | } |
155 | const Message_ExecStatus& operator |= ( const Message_ExecStatus& theOther ) |
156 | { Add ( theOther ); return *this; } |
157 | |
158 | //! Leave only the statuses common with theOther |
159 | void And ( const Message_ExecStatus& theOther ) |
160 | { |
161 | myDone &= theOther.myDone; |
162 | myWarn &= theOther.myWarn; |
163 | myAlarm &= theOther.myAlarm; |
164 | myFail &= theOther.myFail; |
165 | } |
166 | const Message_ExecStatus& operator &= ( const Message_ExecStatus& theOther ) |
167 | { And ( theOther ); return *this; } |
168 | |
169 | //@} |
170 | |
171 | public: |
172 | |
173 | //!@name Advanced: Iteration and analysis of status flags |
174 | //!@{ |
175 | |
176 | //! Definitions of range of available statuses |
177 | enum StatusRange |
178 | { |
179 | FirstStatus = 1, |
180 | StatusesPerType = 32, |
181 | NbStatuses = 128, |
182 | LastStatus = 129 |
183 | }; |
184 | |
185 | //! Returns index of status in whole range [FirstStatus, LastStatus] |
186 | static Standard_Integer StatusIndex( Message_Status status ) |
187 | { |
188 | switch( status & MType ) |
189 | { |
190 | case Message_DONE: return 0 * StatusesPerType + LocalStatusIndex(status); |
191 | case Message_WARN: return 1 * StatusesPerType + LocalStatusIndex(status); |
192 | case Message_ALARM: return 2 * StatusesPerType + LocalStatusIndex(status); |
193 | case Message_FAIL: return 3 * StatusesPerType + LocalStatusIndex(status); |
194 | default: return 0; |
195 | } |
196 | } |
197 | |
198 | //! Returns index of status inside type of status (Done or Warn or, etc) |
199 | //! in range [1, StatusesPerType] |
200 | static Standard_Integer LocalStatusIndex( Message_Status status ) |
201 | { |
202 | return (status & MIndex) + 1; |
203 | } |
204 | |
205 | //! Returns status type (DONE, WARN, ALARM, or FAIL) |
206 | static Message_StatusType TypeOfStatus( Message_Status status ) |
207 | { |
208 | return (Message_StatusType)(status & MType); |
209 | } |
210 | |
211 | //! Returns status with index theIndex in whole range [FirstStatus, LastStatus] |
212 | static Message_Status StatusByIndex( const Standard_Integer theIndex ) |
213 | { |
214 | Standard_Integer indx = theIndex - 1; |
215 | if ( indx < 32 ) |
216 | return (Message_Status)(Message_DONE + indx); |
217 | else if ( indx < 64 ) |
218 | return (Message_Status)(Message_WARN + ( indx - 32 )); |
219 | else if ( indx < 96 ) |
220 | return (Message_Status)(Message_ALARM + ( indx - 64 )); |
221 | else if ( indx < 128 ) |
222 | return (Message_Status)(Message_FAIL + ( indx - 96 )); |
223 | return Message_None; |
224 | } |
225 | |
226 | //!@} |
227 | |
228 | private: |
229 | // ---------- PRIVATE FIELDS ---------- |
230 | Standard_Integer myDone; |
231 | Standard_Integer myWarn; |
232 | Standard_Integer myAlarm; |
233 | Standard_Integer myFail; |
234 | }; |
235 | |
236 | #endif |