Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-05 09:23:10

0001 // Created on: 2003-03-04
0002 // Created by: Pavel TELKOV
0003 // Copyright (c) 2003-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 // The original implementation copyright (c) RINA S.p.A.
0017 
0018 #ifndef Message_ExecStatus_HeaderFile
0019 #define Message_ExecStatus_HeaderFile
0020 
0021 #include <Message_Status.hxx>
0022 
0023 /**
0024  * Tiny class for extended handling of error / execution
0025  * status of algorithm in universal way.
0026  *
0027  * It is in fact a set of integers represented as a collection of bit flags
0028  * for each of four types of status; each status flag has its own symbolic
0029  * name and can be set/tested individually.
0030  *
0031  * The flags are grouped in semantic groups:
0032  * - No flags means nothing done
0033  * - Done flags correspond to some operation successfully completed
0034  * - Warning flags correspond to warning messages on some
0035  *   potentially wrong situation, not harming algorithm execution
0036  * - Alarm flags correspond to more severe warnings about incorrect
0037  *   user data, while not breaking algorithm execution
0038  * - Fail flags correspond to cases when algorithm failed to complete
0039  */
0040 class Message_ExecStatus
0041 {
0042 private:
0043   //! Mask to separate bits indicating status type and index within the type
0044   enum StatusMask
0045   {
0046     MType  = 0x0000ff00,
0047     MIndex = 0x000000ff
0048   };
0049 
0050   static inline int getBitFlag(int theStatus) { return 0x1 << (theStatus & MIndex); }
0051 
0052 public:
0053   //!@name Creation and simple operations with statuses
0054   //!@{
0055 
0056   //! Create empty execution status
0057   Message_ExecStatus()
0058       : myDone(Message_None),
0059         myWarn(Message_None),
0060         myAlarm(Message_None),
0061         myFail(Message_None)
0062   {
0063   }
0064 
0065   //! Initialise the execution status
0066   Message_ExecStatus(Message_Status theStatus)
0067       : myDone(Message_None),
0068         myWarn(Message_None),
0069         myAlarm(Message_None),
0070         myFail(Message_None)
0071   {
0072     Set(theStatus);
0073   }
0074 
0075   //! Sets a status flag
0076   void Set(Message_Status theStatus)
0077   {
0078     switch (TypeOfStatus(theStatus))
0079     {
0080       case Message_DONE:
0081         myDone |= (getBitFlag(theStatus));
0082         break;
0083       case Message_WARN:
0084         myWarn |= (getBitFlag(theStatus));
0085         break;
0086       case Message_ALARM:
0087         myAlarm |= (getBitFlag(theStatus));
0088         break;
0089       case Message_FAIL:
0090         myFail |= (getBitFlag(theStatus));
0091         break;
0092     }
0093   }
0094 
0095   //! Check status for being set
0096   bool IsSet(Message_Status theStatus) const
0097   {
0098     switch (TypeOfStatus(theStatus))
0099     {
0100       case Message_DONE:
0101         return (myDone & getBitFlag(theStatus)) != 0;
0102       case Message_WARN:
0103         return (myWarn & getBitFlag(theStatus)) != 0;
0104       case Message_ALARM:
0105         return (myAlarm & getBitFlag(theStatus)) != 0;
0106       case Message_FAIL:
0107         return (myFail & getBitFlag(theStatus)) != 0;
0108     }
0109     return false;
0110   }
0111 
0112   //! Clear one status
0113   void Clear(Message_Status theStatus)
0114   {
0115     switch (TypeOfStatus(theStatus))
0116     {
0117       case Message_DONE:
0118         myDone &= ~(getBitFlag(theStatus));
0119         return;
0120       case Message_WARN:
0121         myWarn &= ~(getBitFlag(theStatus));
0122         return;
0123       case Message_ALARM:
0124         myAlarm &= ~(getBitFlag(theStatus));
0125         return;
0126       case Message_FAIL:
0127         myFail &= ~(getBitFlag(theStatus));
0128         return;
0129     }
0130   }
0131 
0132   //!@}
0133 
0134   //!@name Advanced: Group operations (useful for analysis)
0135   //!@{
0136 
0137   //! Check if at least one status of each type is set
0138   bool IsDone() const { return myDone != Message_None; }
0139 
0140   bool IsFail() const { return myFail != Message_None; }
0141 
0142   bool IsWarn() const { return myWarn != Message_None; }
0143 
0144   bool IsAlarm() const { return myAlarm != Message_None; }
0145 
0146   //! Set all statuses of each type
0147   void SetAllDone() { myDone = ~0; }
0148 
0149   void SetAllWarn() { myWarn = ~0; }
0150 
0151   void SetAllAlarm() { myAlarm = ~0; }
0152 
0153   void SetAllFail() { myFail = ~0; }
0154 
0155   //! Clear all statuses of each type
0156   void ClearAllDone() { myDone = Message_None; }
0157 
0158   void ClearAllWarn() { myWarn = Message_None; }
0159 
0160   void ClearAllAlarm() { myAlarm = Message_None; }
0161 
0162   void ClearAllFail() { myFail = Message_None; }
0163 
0164   //! Clear all statuses
0165   void Clear() { myDone = myWarn = myAlarm = myFail = Message_None; }
0166 
0167   //! Add statuses to me from theOther execution status
0168   void Add(const Message_ExecStatus& theOther)
0169   {
0170     myDone |= theOther.myDone;
0171     myWarn |= theOther.myWarn;
0172     myAlarm |= theOther.myAlarm;
0173     myFail |= theOther.myFail;
0174   }
0175 
0176   const Message_ExecStatus& operator|=(const Message_ExecStatus& theOther)
0177   {
0178     Add(theOther);
0179     return *this;
0180   }
0181 
0182   //! Leave only the statuses common with theOther
0183   void And(const Message_ExecStatus& theOther)
0184   {
0185     myDone &= theOther.myDone;
0186     myWarn &= theOther.myWarn;
0187     myAlarm &= theOther.myAlarm;
0188     myFail &= theOther.myFail;
0189   }
0190 
0191   const Message_ExecStatus& operator&=(const Message_ExecStatus& theOther)
0192   {
0193     And(theOther);
0194     return *this;
0195   }
0196 
0197   //@}
0198 
0199 public:
0200   //!@name Advanced: Iteration and analysis of status flags
0201   //!@{
0202 
0203   //! Definitions of range of available statuses
0204   enum StatusRange
0205   {
0206     FirstStatus     = 1,
0207     StatusesPerType = 32,
0208     NbStatuses      = 128,
0209     LastStatus      = 129
0210   };
0211 
0212   //! Returns index of status in whole range [FirstStatus, LastStatus]
0213   static int StatusIndex(Message_Status theStatus)
0214   {
0215     switch (TypeOfStatus(theStatus))
0216     {
0217       case Message_DONE:
0218         return 0 * StatusesPerType + LocalStatusIndex(theStatus);
0219       case Message_WARN:
0220         return 1 * StatusesPerType + LocalStatusIndex(theStatus);
0221       case Message_ALARM:
0222         return 2 * StatusesPerType + LocalStatusIndex(theStatus);
0223       case Message_FAIL:
0224         return 3 * StatusesPerType + LocalStatusIndex(theStatus);
0225     }
0226     return 0;
0227   }
0228 
0229   //! Returns index of status inside type of status (Done or Warn or, etc)
0230   //! in range [1, StatusesPerType]
0231   static int LocalStatusIndex(Message_Status theStatus)
0232   {
0233     return ((unsigned int)theStatus & (unsigned int)MIndex) + 1;
0234   }
0235 
0236   //! Returns status type (DONE, WARN, ALARM, or FAIL)
0237   static Message_StatusType TypeOfStatus(Message_Status theStatus)
0238   {
0239     return (Message_StatusType)((unsigned int)theStatus & (unsigned int)MType);
0240   }
0241 
0242   //! Returns status with index theIndex in whole range [FirstStatus, LastStatus]
0243   static Message_Status StatusByIndex(const int theIndex)
0244   {
0245     int indx = theIndex - 1;
0246     if (indx < 32)
0247       return (Message_Status)(Message_DONE + indx);
0248     else if (indx < 64)
0249       return (Message_Status)(Message_WARN + (indx - 32));
0250     else if (indx < 96)
0251       return (Message_Status)(Message_ALARM + (indx - 64));
0252     else if (indx < 128)
0253       return (Message_Status)(Message_FAIL + (indx - 96));
0254     return Message_None;
0255   }
0256 
0257   //!@}
0258 
0259 private:
0260   int myDone;
0261   int myWarn;
0262   int myAlarm;
0263   int myFail;
0264 };
0265 
0266 #endif