Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

XPRULE.H

Go to the documentation of this file.
00001 //: xprule.h
00009 #if defined (__GNUG__)
00010     #pragma interface "xprule.h"
00011 #endif
00012 
00013 #ifndef xprule_h
00014     #define xprule_h
00015 #include    "../include/xbool.h"
00016 
00017     #include <wx/wxprec.h>
00018 
00019     #ifdef __BORLANDC__
00020         #pragma hdrstop
00021     #endif
00022 
00023     #ifndef WX_PRECOMP
00024         #include <wx/wx.h>
00025     #endif
00026 
00027 
00028 extern bool xpShortcutMode;
00029 
00030 // Define symbolic logical operations
00031 #ifndef AND
00032     #define AND &&
00033     #define OR ||
00034     #define NOT !
00035 #endif
00036 
00039 
00040 class xpAgent :  public wxObject
00041 {   public:
00043         xpAgent()
00044         {}      // no functionality (yet)
00045 };//xpAgent
00046 
00048 
00055 class xpUserAgent :  public xpAgent
00056 {   public:
00058         xpUserAgent()
00059         {}
00060 };//xpUserAgent
00061 
00063 
00069 class xpDatabaseAgent :  public xpAgent
00070 {   public:
00072         xpDatabaseAgent()
00073         {}
00074 };//xpDatabaseAgent
00075 
00077   
00082 class   xpRuleGeneric : public xboolean
00083 {   protected:
00084         wxString HistoryString;     
00085         xpAgent *Agent;   
00086         wxString    Name;           
00087     public:
00090         xpRuleGeneric(  xpAgent *MyAgent=NULL)
00091         :xboolean()
00092         {   Agent = MyAgent;  // Save the agent working for us
00093         }// of xpRuleGeneric::xpRuleGeneric
00095         xpRuleGeneric(const xpRuleGeneric &xr) :
00096         xboolean(xr.value)
00097         {   HistoryString = xr.HistoryString;
00098             Agent = xr.Agent;
00099             Name = xr.Name;
00100         }
00104         virtual
00105         void    AddStringToHistory(wxString H = "")
00106         {   if(H.IsEmpty())
00107                 H = wxString::Format(_("(%s is %s)\n"),GetName(),GetValueString(value));
00108             HistoryString += H;
00109         }
00113         virtual
00114         void    CalculateValue(void)
00115         {   xpRuleGeneric a = Fire();   // Get the rule, resulting the value
00116             value = a.value;            // Store the calculated value
00117             HistoryString = a.GetHistoryString();   // as well as contrib to reasoning
00118         }
00123         virtual
00124         xpRuleGeneric Fire(void)
00125         {   return  *this;}
00128         virtual
00129         wxString    GetHistoryString(void) const
00130         {   return HistoryString.IsEmpty()
00131                 ? wxString::Format(_("%s is %s"), GetName(), GetValueString(value))
00132                 : HistoryString;
00133 //            return ""; // dummy return string for GNU 
00134         }
00137         virtual
00138         wxString    GetName(void) const
00139         {   return Name.IsEmpty()
00140                     ? wxString::Format(_("\"Generic rule\""))  // Name is empty, generic rule
00141                     : wxString::Format(_("\"%s\""),Name);       
00142         }
00146         virtual
00147         wxString    GetReasoning(void)
00148         {   CalculateValue();       // Make a fresh copy
00149             wxString H1 = wxString::Format(_("%s is %s"),GetName(),GetValueString(value));
00150             wxString H2 = GetHistoryString();
00151             return HistoryString.IsEmpty()
00152                 ? wxString::Format(_("%s (not an expression)"),H1)
00153                 : wxString::Format(_("%s because\n%s"),H1,H2);  
00154         }
00157       static bool GetShortcutMode(void)
00158       {   return xpShortcutMode;}
00161         virtual
00162         wxString    GetValueString(void)
00163         {   return GetValueString(GetValue());}
00167         virtual
00168         wxString    GetValueString(const xbool V) const
00169         {   if(True == V)
00170                 return _("TRUE");
00171             else if(False == V)
00172                 return _("FALSE");
00173             else return _("UNKNOWN");
00174         }
00177       static void SetShortcutMode(bool M)
00178       {   xpShortcutMode = M;}
00182         xpRuleGeneric& operator = ( xboolean &xb)
00183         {   xboolean::operator =(xb);
00184             return *this;
00185         }
00189         xpRuleGeneric&  operator = ( const xpRuleGeneric &xb) 
00190         {   value = xb.value;
00191             Name = xb.Name;
00192             HistoryString = xb.HistoryString;
00193             Agent = xb.Agent;
00194             return *this;
00195         }
00198         xpRuleGeneric operator ! (void)
00199         {   xboolean *xr =  (xboolean *)this;
00200             value = (!*xr).GetValue();
00201             wxString H =  GetHistoryString();
00202             Name = wxString::Format(_("NOT %s"),Name);
00203             HistoryString = wxString::Format(_("(NOT (\n%s\n)) is %s\n"), H, GetValueString(value));
00204             return *this;
00205         }
00210         friend xpRuleGeneric
00211         operator && ( const xpRuleGeneric &xrL, const xpRuleGeneric &xrR)  
00212         {   xpRuleGeneric res;
00213             xboolean *xrLv = (xboolean *) &xrL;
00214             xboolean *xrRv = (xboolean *) &xrR;
00215             res.value = (*xrLv && *xrRv).GetValue();     // Compute value
00216             // Now set the history string
00217             if(xpShortcutMode && ((False == xrL.value)))
00218                 res.HistoryString = xrL.GetHistoryString();
00219             else if(xpShortcutMode && ((False == xrR.value)))
00220                 res.HistoryString = xrR.GetHistoryString();
00221             else if(xpShortcutMode && ((Unknown == xrL.value)))
00222                 res.HistoryString = xrL.GetHistoryString();
00223             else if(xpShortcutMode && ((Unknown == xrR.value)))
00224                 res.HistoryString = xrR.GetHistoryString();
00225             else 
00226                 res.HistoryString = wxString::Format(_("(%s\n AND \n%s)"),xrL.GetHistoryString(),xrR.GetHistoryString());
00227             res.Agent = NULL;
00228             return res; 
00229         }
00234         friend xpRuleGeneric
00235         operator || ( const xpRuleGeneric &xrL, const xpRuleGeneric &xrR)  
00236         {   xpRuleGeneric res;
00237             xboolean *xrLv = (xboolean *) &xrL;
00238             xboolean *xrRv = (xboolean *) &xrR;
00239             res.value = (*xrLv || *xrRv).GetValue();     // Compute value
00240             // Now set the history string
00241             if(xpShortcutMode && (True == xrL.value) )
00242                 res.HistoryString = xrL.GetHistoryString();
00243             else if(xpShortcutMode && (True == xrR.value))
00244                 res.HistoryString = xrR.GetHistoryString();
00245             else if(xpShortcutMode && (Unknown == xrL.value))
00246                 res.HistoryString = xrL.GetHistoryString();
00247             else if(xpShortcutMode && (Unknown == xrR.value))
00248                 res.HistoryString = xrR.GetHistoryString();
00249             else
00250                 res.HistoryString = wxString::Format(_("(%s\n OR \n%s)"), xrL.GetHistoryString(), xrR.GetHistoryString());
00251              res.Agent = NULL;
00252             return res; 
00253         }
00254 };//xpRuleGeneric
00255 
00256 #endif //xprule_h

Generated on Tue Dec 23 10:24:08 2003 for xps4xps by doxygen 1.3.5