Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:16

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 
0044   //! Mask to separate bits indicating status type and index within the type  
0045   enum StatusMask
0046   {
0047     MType  = 0x0000ff00,
0048     MIndex = 0x000000ff
0049   };
0050 
0051   static inline int getBitFlag (int theStatus)
0052   {
0053     return 0x1 << (theStatus & MIndex);
0054   }
0055 
0056 public:
0057   //!@name Creation and simple operations with statuses
0058   //!@{
0059 
0060   //! Create empty execution status
0061   Message_ExecStatus()
0062   : myDone  (Message_None), myWarn (Message_None),
0063     myAlarm (Message_None), myFail (Message_None)
0064   {}
0065 
0066   //! Initialise the execution status
0067   Message_ExecStatus (Message_Status theStatus)
0068   : myDone  (Message_None), myWarn (Message_None),
0069     myAlarm (Message_None), myFail (Message_None)
0070   {
0071     Set (theStatus);
0072   }
0073 
0074   //! Sets a status flag
0075   void Set (Message_Status theStatus)
0076   {
0077     switch (TypeOfStatus (theStatus))
0078     {
0079       case Message_DONE:  myDone  |= (getBitFlag (theStatus)); break;
0080       case Message_WARN:  myWarn  |= (getBitFlag (theStatus)); break;
0081       case Message_ALARM: myAlarm |= (getBitFlag (theStatus)); break;
0082       case Message_FAIL:  myFail  |= (getBitFlag (theStatus)); break;
0083     }
0084   }
0085 
0086   //! Check status for being set
0087   Standard_Boolean IsSet (Message_Status theStatus) const
0088   { 
0089     switch (TypeOfStatus (theStatus))
0090     {
0091       case Message_DONE:  return (myDone  & getBitFlag (theStatus)) != 0;
0092       case Message_WARN:  return (myWarn  & getBitFlag (theStatus)) != 0;
0093       case Message_ALARM: return (myAlarm & getBitFlag (theStatus)) != 0;
0094       case Message_FAIL:  return (myFail  & getBitFlag (theStatus)) != 0;
0095     }
0096     return Standard_False;
0097   }
0098 
0099   //! Clear one status
0100   void Clear (Message_Status theStatus)
0101   {
0102     switch (TypeOfStatus (theStatus))
0103     {
0104       case Message_DONE: myDone  &= ~(getBitFlag (theStatus)); return;
0105       case Message_WARN: myWarn  &= ~(getBitFlag (theStatus)); return;
0106       case Message_ALARM:myAlarm &= ~(getBitFlag (theStatus)); return;
0107       case Message_FAIL: myFail  &= ~(getBitFlag (theStatus)); return;
0108     }
0109   }
0110 
0111   //!@}
0112 
0113   //!@name Advanced: Group operations (useful for analysis)
0114   //!@{
0115 
0116   //! Check if at least one status of each type is set
0117   Standard_Boolean IsDone  () const { return myDone  != Message_None;  }
0118   Standard_Boolean IsFail  () const { return myFail  != Message_None;  }
0119   Standard_Boolean IsWarn  () const { return myWarn  != Message_None;  }
0120   Standard_Boolean IsAlarm () const { return myAlarm != Message_None;  }
0121 
0122   //! Set all statuses of each type
0123   void SetAllDone   () { myDone  = ~0; }
0124   void SetAllWarn   () { myWarn  = ~0; }
0125   void SetAllAlarm  () { myAlarm = ~0; }
0126   void SetAllFail   () { myFail  = ~0; }
0127 
0128   //! Clear all statuses of each type 
0129   void ClearAllDone () { myDone  = Message_None; }
0130   void ClearAllWarn () { myWarn  = Message_None; }
0131   void ClearAllAlarm() { myAlarm = Message_None; }
0132   void ClearAllFail () { myFail  = Message_None; }
0133 
0134   //! Clear all statuses
0135   void Clear ()
0136   { 
0137     myDone = myWarn = myAlarm = myFail = Message_None;
0138   }
0139 
0140   //! Add statuses to me from theOther execution status
0141   void Add ( const Message_ExecStatus& theOther )
0142   {
0143     myDone  |= theOther.myDone;
0144     myWarn  |= theOther.myWarn;
0145     myAlarm |= theOther.myAlarm;
0146     myFail  |= theOther.myFail;
0147   }
0148   const Message_ExecStatus& operator |= ( const Message_ExecStatus& theOther )
0149   { Add ( theOther ); return *this; }
0150 
0151   //! Leave only the statuses common with theOther
0152   void And ( const Message_ExecStatus& theOther )
0153   {
0154     myDone  &= theOther.myDone;
0155     myWarn  &= theOther.myWarn;
0156     myAlarm &= theOther.myAlarm;
0157     myFail  &= theOther.myFail;
0158   }
0159   const Message_ExecStatus& operator &= ( const Message_ExecStatus& theOther )
0160   { And ( theOther ); return *this; }
0161 
0162   //@}
0163 
0164 public:
0165 
0166   //!@name Advanced: Iteration and analysis of status flags
0167   //!@{
0168 
0169   //! Definitions of range of available statuses
0170   enum StatusRange
0171   {
0172     FirstStatus     = 1,
0173     StatusesPerType = 32,
0174     NbStatuses      = 128,
0175     LastStatus      = 129
0176   };
0177 
0178   //! Returns index of status in whole range [FirstStatus, LastStatus]
0179   static Standard_Integer StatusIndex (Message_Status theStatus)
0180   {
0181     switch (TypeOfStatus (theStatus))
0182     {
0183       case Message_DONE:  return 0 * StatusesPerType + LocalStatusIndex(theStatus);
0184       case Message_WARN:  return 1 * StatusesPerType + LocalStatusIndex(theStatus);
0185       case Message_ALARM: return 2 * StatusesPerType + LocalStatusIndex(theStatus);
0186       case Message_FAIL:  return 3 * StatusesPerType + LocalStatusIndex(theStatus);
0187     }
0188     return 0;
0189   }
0190 
0191   //! Returns index of status inside type of status (Done or Warn or, etc) 
0192   //! in range [1, StatusesPerType]
0193   static Standard_Integer LocalStatusIndex (Message_Status theStatus)
0194   {
0195     return ((Standard_UInteger )theStatus & (Standard_UInteger )MIndex) + 1;
0196   }
0197 
0198   //! Returns status type (DONE, WARN, ALARM, or FAIL) 
0199   static Message_StatusType TypeOfStatus (Message_Status theStatus)
0200   {
0201     return (Message_StatusType )((Standard_UInteger )theStatus & (Standard_UInteger )MType);
0202   }
0203 
0204   //! Returns status with index theIndex in whole range [FirstStatus, LastStatus]
0205   static Message_Status StatusByIndex( const Standard_Integer theIndex )
0206   {
0207     Standard_Integer indx = theIndex - 1;
0208     if ( indx < 32 )
0209       return (Message_Status)(Message_DONE  + indx);
0210     else if ( indx < 64 )
0211       return (Message_Status)(Message_WARN  + ( indx - 32 ));
0212     else if ( indx < 96 )
0213       return (Message_Status)(Message_ALARM + ( indx - 64 ));
0214     else if ( indx < 128 )
0215       return (Message_Status)(Message_FAIL  + ( indx - 96 ));
0216     return Message_None;
0217   }
0218 
0219   //!@}
0220 
0221 private:
0222   Standard_Integer myDone;
0223   Standard_Integer myWarn;
0224   Standard_Integer myAlarm;
0225   Standard_Integer myFail;
0226 };
0227 
0228 #endif