GME
13
|
00001 #include "stdafx.h" 00002 #include "Attribute.h" 00003 00004 00005 Attribute::Attribute(void):eval(FALSE) 00006 { 00007 } 00008 Attribute::Attribute(CString &strInput):eval(FALSE) 00009 { 00010 if(strInput==_T("&") ||strInput==_T("|")) 00011 { 00012 name =strInput; 00013 return; 00014 } 00015 name=strInput; 00016 00017 //parse the attribute expressions for operators and operands 00018 //keep single lettered operators first 00019 Parse(strInput,_T("<")); 00020 Parse(strInput,_T(">")); 00021 Parse(strInput,_T("=")); 00022 Parse(strInput,_T(">=")); 00023 Parse(strInput,_T("<=")); 00024 Parse(strInput,_T("!=")); 00025 00026 } 00027 00028 void Attribute::Parse(const CString& strInput,const CString& operation) 00029 { 00030 CString strTemp(strInput); 00031 int index=strTemp.Find(operation,0); 00032 //CString token=temp.Tokenize(_T("<="),index); 00033 if(index!=-1) 00034 { 00035 name=strTemp.Left(index).Trim(); 00036 this->operation=operation; 00037 value=strTemp.Right(strTemp.GetLength()-index-operation.GetLength()).Trim(); 00038 return; 00039 } 00040 00041 } 00042 00043 Attribute::~Attribute(void) 00044 { 00045 } 00046 00047 BOOL Attribute::Compare(CString& rhs,int type) 00048 { 00049 switch(type) 00050 { 00051 case 0: 00052 return _tcscmp(value,rhs); 00053 00054 case 1: 00055 return CheckInteger(_ttoi(value),_ttoi(rhs)); 00056 00057 case 2: 00058 return CheckDouble(_ttof(value),_ttof(rhs)); 00059 break; 00060 case 3: 00061 return value==rhs; 00062 break; 00063 default: 00064 break; 00065 } 00066 return TRUE; 00067 } 00068 00069 //compare the integer values based on operator it has 00070 BOOL Attribute::CheckInteger(int lhs,int rhs) 00071 { 00072 if(operation==_T(">=")) 00073 { 00074 return lhs>=rhs; 00075 } 00076 if(operation==_T("<=")) 00077 { 00078 return lhs<=rhs; 00079 } 00080 if(operation==_T("!=")) 00081 { 00082 return lhs!=rhs; 00083 } 00084 if(operation==_T("=")) 00085 { 00086 return lhs==rhs; 00087 } 00088 if(operation==_T(">")) 00089 { 00090 return lhs>rhs; 00091 } 00092 if(operation==_T("<")) 00093 { 00094 return lhs<rhs; 00095 } 00096 return TRUE; 00097 } 00098 00099 //Compare the double values best on operator it has 00100 BOOL Attribute::CheckDouble(double lhs,double rhs) 00101 { 00102 if(operation==_T(">=")) 00103 { 00104 return lhs>=rhs; 00105 } 00106 if(operation==_T("<=")) 00107 { 00108 return lhs<=rhs; 00109 } 00110 if(operation==_T("!=")) 00111 { 00112 return lhs!=rhs; 00113 } 00114 if(operation==_T("=")) 00115 { 00116 return lhs==rhs; 00117 } 00118 if(operation==_T(">")) 00119 { 00120 return lhs>rhs; 00121 } 00122 if(operation==_T("<")) 00123 { 00124 return lhs<rhs; 00125 } 00126 return TRUE; 00127 } 00128 00129 BOOL Attribute::CheckBool(BOOL lhs,BOOL rhs) 00130 { 00131 if(operation==_T("=")) 00132 { 00133 return lhs==rhs; 00134 } 00135 else if(operation==_T("!=")) 00136 { 00137 return lhs!=rhs; 00138 } 00139 return FALSE; 00140 } 00141 00142 BOOL Attribute::CheckString(BOOL lhs) 00143 { 00144 if(operation==_T("=")) 00145 return lhs; 00146 else if(operation==_T("!=")) 00147 return !lhs; 00148 return FALSE; 00149 } 00150 00151 BOOL Attribute::LogicalCompare(BOOL lhs,const Attribute & operation,BOOL rhs) 00152 { 00153 if(operation.name==_T("&")) 00154 { 00155 return lhs&&rhs; 00156 } 00157 if(operation.name==_T("|")) 00158 { 00159 return lhs||rhs; 00160 } 00161 return FALSE; 00162 } 00163 00164 std::tr1::wregex Attribute::GetRegExp(CString& str,BOOL full) 00165 { 00166 CString strTemp; 00167 if(full) 00168 { 00169 strTemp.Append(_T("^")); 00170 strTemp.Append(str); 00171 strTemp.Append(_T("$")); 00172 00173 } 00174 else 00175 strTemp=str; 00176 00177 return std::tr1::wregex(strTemp); 00178 }