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

DLogic.cpp

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.cpp,v 1.5 2002/11/21 18:08:36 khtan Exp $
00008 //
00009 //  Description:
00010 //  1) Basic functionality of Class DLogic implementation generated by enum_gen.
00011 //     CUJ Mar 1999 "Enum++ - an enum class code generator" by Art Walker
00012 //  2) Added operator!, operator!! and operator&& functionality
00013 //  3) Cannot use std::logical_or, std::logical_and and std::logical_not
00014 //     bec these return bool. VC6 cannot partially specialize these templates.
00015 //  4) Added DLogic*Functor in DLogic.hpp
00016 //---------------------------------------------------------------------- 
00017      
00018 #include "DLogic.h"
00019 #include <stdlib.h>
00020      
00021      
00022 //---------------------------------------------------------------------- 
00023 DLogic::EnumDefStruct  DLogic::m_defArr[] ={
00024     EnumDefStruct (     0, "ZERO"       ),
00025     EnumDefStruct (     1, "ONE"        ),
00026     EnumDefStruct (     2, "D"          ),
00027     EnumDefStruct (     3, "_D"         ),
00028     EnumDefStruct (     4, "X"          ),
00029     EnumDefStruct (     5, "_UNDEFINED" ),
00030 };
00031 
00032 const DLogic  DLogic::ZERO       (&m_defArr[0]);
00033 const DLogic  DLogic::ONE        (&m_defArr[1]);
00034 const DLogic  DLogic::D          (&m_defArr[2]);
00035 const DLogic  DLogic::_D         (&m_defArr[3]);
00036 const DLogic  DLogic::X          (&m_defArr[4]);
00037 const DLogic  DLogic::_UNDEFINED (&m_defArr[5]);
00038 // khtan added
00039 const DLogic  DLogic::DLogicAnd[5][5]={ {ZERO,ZERO,ZERO,ZERO,ZERO},
00040                                         {ZERO,ONE ,D   ,_D  ,X},
00041                                         {ZERO,D   ,ZERO,ZERO,X},
00042                                         {ZERO,_D  ,ZERO,_D  ,X},
00043                                         {ZERO,X   ,X   ,X   ,X},
00044                                         };
00045 const DLogic  DLogic::DLogicOr[5][5]={  {ZERO,ONE ,D   ,_D  ,X},
00046                                         {ONE ,ONE ,ONE ,ONE ,ONE},
00047                                         {D   ,ONE ,D   ,ONE ,X},
00048                                         {_D  ,ONE ,ONE ,_D  ,X},
00049                                         {X   ,ONE ,X   ,X   ,X},
00050                                         };
00051 const DLogic  DLogic::DLogicNot[5]={ONE,ZERO,_D,D,X};
00052 
00053 short  DLogic::m_defArrCount = sizeof(DLogic::m_defArr)/sizeof (EnumDefStruct);
00054      
00055 const char*  DLogic::m_errorMsg = "ERROR: DLogic undefined";
00056      
00057 //---------------------------------------------------------------------- 
00058 DLogic::DLogic (const string&  name){
00059     for (int k = 0; k < m_defArrCount - 1; k++){
00060         if (m_defArr[k].m_name == name){
00061             m_defPtr = &m_defArr[k];
00062             return;
00063         }
00064     }
00065     m_defPtr = _UNDEFINED.m_defPtr;
00066 }
00067      
00068 //---------------------------------------------------------------------- 
00069 DLogic::DLogic (const int  ival ){
00070     for (int k = 0; k < m_defArrCount - 1; k++){
00071         if (m_defArr[k].m_value == ival){
00072             m_defPtr = &m_defArr[k];
00073             return;
00074         }
00075     }
00076     m_defPtr = _UNDEFINED.m_defPtr;
00077 }
00078      
00079 //---------------------------------------------------------------------- 
00080 const char* DLogic::GetLabel() const {
00081     // Note: Do NOT modify this function to "return GetString().c_str()"; 
00082     // the result of GetString is a temporary which would be deleted upon 
00083     // return from this function, which means that the pointer returned by 
00084     // this function would point to a freed memory block!
00085      
00086     if (m_defPtr){
00087         return m_defPtr->m_name.c_str();
00088     }
00089     return _UNDEFINED.m_defPtr->m_name.c_str();
00090 }
00091      
00092 //---------------------------------------------------------------------- 
00093 string DLogic::GetString() const {
00094     if (m_defPtr){
00095         return m_defPtr->m_name;
00096     }
00097     return _UNDEFINED.m_defPtr->m_name;
00098 }
00099      
00100 //---------------------------------------------------------------------- 
00101 DLogic DLogic::operator++(){
00102     if (m_defPtr < _UNDEFINED.m_defPtr){
00103         m_defPtr++;
00104     }
00105     return *this;
00106 }
00107      
00108 //---------------------------------------------------------------------- 
00109 // Postfix ++
00110      
00111 DLogic DLogic::operator++(int){
00112     DLogic  tmp = *this;
00113     operator++();
00114     return tmp;
00115 }
00116      
00117 //---------------------------------------------------------------------- 
00118 DLogic DLogic::operator--(){
00119     if (m_defPtr > m_defArr){
00120         m_defPtr--;
00121     }else{
00122         m_defPtr = _UNDEFINED.m_defPtr;
00123     }
00124     return *this;
00125 }
00126      
00127      
00128 //---------------------------------------------------------------------- 
00129 // Postfix --
00130      
00131 DLogic DLogic::operator--(int) {
00132     DLogic  tmp = *this;
00133     operator--();
00134     return tmp;
00135 }
00136      
00137 //---------------------------------------------------------------------- 
00138 OSTREAM& operator<< (OSTREAM&  ostr,const DLogic&  objref ){
00139     ostr << " " << objref.GetString() << " "; 
00140     return ostr;
00141 }
00142      
00143 //---------------------------------------------------------------------- 
00144 ISTREAM& operator>> (ISTREAM&  istr,DLogic&  objref ){
00145     string  name;
00146     istr >> name;
00147     objref = DLogic (name);
00148     return istr;
00149 }
00150      
00151 //---------------------------------------------------------------------- 
00152 #if 1 // Workaround : to prevent error when comparing with _UNDEFINED
00153 void DLogic::RangeError(){
00154     cerr << m_errorMsg << endl;
00155     exit (1);
00156 }
00157 #else
00158 void DLogic::RangeError(){
00159 }
00160 #endif
00161 //---------------------------------------------------------------------- 

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