Main Page   Namespace List   Alphabetical List   Compound List   File List   Compound Members   File Members  

DLogic.h

Go to the documentation of this file.
00001 /* Copyright (C) Kwee Heong Tan 2002 - 2003
00002    Permission is granted to use this code without restriction as
00003    long as this copyright notice appears in all source files.
00004 */
00005 //---------------------------------------------------------------------- 
00006 //
00007 //  Filename: $Id: DLogic.h,v 1.3 2002/11/21 18:09:02 khtan Exp $
00008 //
00009 //  Description:
00010 //
00011 //---------------------------------------------------------------------- 
00012 #ifndef _DLogic_H
00013 #define _DLogic_H
00014      
00015 // The OSTREAM and ISTREAM typedefs are used due to a problem that occurs
00016 // when compiling enum classes using MS Visual C++ 5.0; even with the 
00017 // "using namespace std" declaration, lines containing ostream and istream 
00018 // are flagged as ambiguous by VC++.
00019      
00020 #ifdef WIN32
00021     #include <string>
00022     #include <iostream>
00023      
00024     using namespace std;
00025      
00026     typedef std::ostream  OSTREAM;
00027     typedef std::istream  ISTREAM;
00028      
00029 #else  // SGI
00030     #include <iostream.h>
00031     #include <mstring.h>   // Needed for string class on SGI
00032      
00033     typedef ostream  OSTREAM;
00034     typedef istream  ISTREAM;
00035      
00036 #endif
00037 //---------------------------------------------------------------------- 
00038 #ifdef ENUMS_USE_EXCEPTION_HANDLING
00039     #define DLogic_THROW_DECL    throw (const char *) 
00040     #define DLogic_THROW_EXEC    throw m_errorMsg;
00041 #else
00042     #define DLogic_THROW_DECL
00043     #define DLogic_THROW_EXEC    DLogic::RangeError()
00044 #endif
00045 //---------------------------------------------------------------------- 
00046 class DLogic{
00047 public:  
00048     static const DLogic  ZERO;
00049     static const DLogic  ONE;
00050     static const DLogic  D;
00051     static const DLogic  _D;
00052     static const DLogic  X;
00053     static const DLogic  _UNDEFINED;
00054     // khtan added
00055     static const DLogic DLogicAnd[5][5];
00056     static const DLogic DLogicOr[5][5];
00057     static const DLogic DLogicNot[5];
00058 public:
00059     DLogic(){
00060         m_defPtr = _UNDEFINED.m_defPtr;
00061     }
00062     DLogic (const DLogic&  objref ){
00063         m_defPtr = objref.m_defPtr;
00064     }
00065     explicit DLogic ( const string&  estr );
00066     explicit DLogic ( const int  ival );
00067     // GetInt is used instead of "operator int()" to enforce explicit 
00068     // conversion from DLogic to int.
00069     short GetInt() const DLogic_THROW_DECL {
00070         if (m_defPtr == _UNDEFINED.m_defPtr){
00071             DLogic_THROW_EXEC;
00072         }
00073         return m_defPtr->m_value;
00074     }
00075     bool valid() const {
00076         return (m_defPtr != _UNDEFINED.m_defPtr);
00077     }
00078     DLogic& operator= ( const DLogic&  objref ){
00079       // Q - no need to check for assignment to self?
00080         m_defPtr = objref.m_defPtr;
00081         return *this;
00082     }
00083     bool operator== ( const DLogic&  objref ) const DLogic_THROW_DECL {
00084         if ( (m_defPtr == _UNDEFINED.m_defPtr) || (objref.m_defPtr == _UNDEFINED.m_defPtr) ){
00085             DLogic_THROW_EXEC;
00086         }
00087         return m_defPtr == objref.m_defPtr;
00088     }
00089     bool operator!= ( const DLogic&  objref ) const DLogic_THROW_DECL {
00090         if ( (m_defPtr == _UNDEFINED.m_defPtr) || (objref.m_defPtr == _UNDEFINED.m_defPtr) ){
00091             DLogic_THROW_EXEC;
00092         }
00093         return m_defPtr != objref.m_defPtr;
00094     }
00095     bool operator< ( const DLogic&  objref ) const DLogic_THROW_DECL {
00096         if ( (m_defPtr == _UNDEFINED.m_defPtr) || (objref.m_defPtr == _UNDEFINED.m_defPtr) ){
00097             DLogic_THROW_EXEC;
00098         }
00099         return m_defPtr < objref.m_defPtr;
00100     }
00101     bool operator<= ( const DLogic&  objref ) const DLogic_THROW_DECL {
00102         if ( (m_defPtr == _UNDEFINED.m_defPtr) || (objref.m_defPtr == _UNDEFINED.m_defPtr) ){
00103             DLogic_THROW_EXEC;
00104         }
00105         return m_defPtr <= objref.m_defPtr;
00106     }
00107     bool operator> ( const DLogic&  objref ) const DLogic_THROW_DECL {
00108         if ( (m_defPtr == _UNDEFINED.m_defPtr) || (objref.m_defPtr == _UNDEFINED.m_defPtr) ){
00109             DLogic_THROW_EXEC;
00110         }
00111         return m_defPtr > objref.m_defPtr;
00112     }
00113     bool operator>= (const DLogic&  objref ) const DLogic_THROW_DECL {
00114         if ( (m_defPtr == _UNDEFINED.m_defPtr) || (objref.m_defPtr == _UNDEFINED.m_defPtr) ){
00115             DLogic_THROW_EXEC;
00116         }
00117         return m_defPtr >= objref.m_defPtr;
00118     }
00119     DLogic operator++();
00120     DLogic operator++(int);
00121     DLogic operator--();
00122     DLogic operator--(int);
00123     const char* GetLabel() const;
00124     string GetString() const;
00125     friend OSTREAM& operator<< ( OSTREAM& ostr, const DLogic&  objref );
00126     friend ISTREAM& operator>> ( ISTREAM& ostr, DLogic&  objref );
00127     // khtan added
00128     const DLogic& operator&&(const DLogic &rhs) const{
00129       return DLogic::DLogicAnd[m_defPtr->m_value][rhs.m_defPtr->m_value];
00130     }
00131     const DLogic& operator||(const DLogic &rhs) const{
00132       return DLogic::DLogicOr[m_defPtr->m_value][rhs.m_defPtr->m_value];
00133     }
00134     const DLogic& operator!() const{
00135       return DLogic::DLogicNot[m_defPtr->m_value];
00136     }
00137 public: 
00138     static DLogic first(){ return ZERO; }
00139     static DLogic last(){ return X; }
00140     static int count(){ return m_defArrCount - 1; }
00141 private:  
00142     struct EnumDefStruct{
00143         short   m_value;
00144         string  m_name;
00145         EnumDefStruct(const int value,const char* name):m_value(value), m_name(name){}
00146     };
00147     // The class constructor with a EnumDefStruct* argument should only 
00148     // be used to construct the static constants that make up the enum 
00149     // values; thus it's declared private.
00150     DLogic (EnumDefStruct*  defPtr ){ m_defPtr = defPtr; }
00151     static void RangeError();
00152 private:
00153     EnumDefStruct*  m_defPtr;
00154 private:
00155     static short          m_defArrCount; 
00156     static EnumDefStruct  m_defArr[];
00157     static const char*    m_errorMsg;
00158 };
00159      
00160 #endif

Generated on Mon Jan 20 11:54:26 2003 for ATPG by doxygen1.3-rc1