GME  13
Input.cpp
Go to the documentation of this file.
00001 // Input.cpp: implementation of the CInput class.
00002 //
00004 
00005 #include "stdafx.h"
00006 //#include "ComHelp.h"
00007 //#include "GMECOM.h"
00008 //#include "ComponentConfig.h"
00009 //#include "RawComponent.h"
00010 #include "Input.h"
00011 
00012 #ifdef _DEBUG
00013 #undef THIS_FILE
00014 static char THIS_FILE[]=__FILE__;
00015 #define new DEBUG_NEW
00016 #endif
00017 
00019 // Construction/Destruction
00021 
00022 CInput::CInput()
00023 {
00024     
00025 }
00026 
00027 CInput::~CInput()
00028 {
00029 
00030 }
00031 
00032 //Get the search criterias
00033 void CInput::GetInput(CString strNameFirst, CString strRoleFirst, CString strKindFirst, CString strAttributeFirst,CString strNameSecond,CString strRoleSecond,CString strKindSecond,CString strAttributeSecond,
00034                       CString attrval, BOOL mod, BOOL atom, BOOL ref, BOOL set,BOOL connection,BOOL splSearch, BOOL full, 
00035                       IMgaFCO*, int, //WAS: IMgaFCO *root, int searchscope,
00036                       BOOL bMatchCase, int scopedSearch,int logicalExpr)
00037 {
00038     //doScopedSearch = bScopedSearch;
00039 
00040     m_bGetCaseIgnored = !bMatchCase;
00041     if( m_bGetCaseIgnored)
00042     {
00043         strNameFirst.MakeLower();
00044         strRoleFirst.MakeLower();
00045         strKindFirst.MakeLower();
00046         strAttributeFirst.MakeLower();
00047 
00048         //attrval seems not used
00049         attrval.MakeLower();
00050         //addded
00051         strNameSecond.MakeLower();
00052         strRoleSecond.MakeLower();
00053         strKindSecond.MakeLower();
00054         strAttributeSecond.MakeLower();
00055     }
00056     
00057     m_bFull=full;
00058 
00059     //get regular expression forms
00060     m_regNameFirst = GetRegExp(strNameFirst);
00061     m_regRoleFirst = GetRegExp(strRoleFirst);
00062     m_regKindFirst = GetRegExp(strKindFirst);
00063 
00064     m_regNameSecond=GetRegExp(strNameSecond);
00065     m_regKindSecond=GetRegExp(strKindSecond);
00066     m_regRoleSecond=GetRegExp(strRoleSecond);
00067 
00068     //get string forms
00069 
00070     //objVal = attrval;
00071     //objattribName = strAttributeFirst;
00072     m_strNameFirst=strNameFirst;
00073     m_strKindFirst=strKindFirst;
00074     m_strRoleFirst=strRoleFirst;
00075     m_strAttributeFirst=strAttributeFirst;
00076 
00077     m_strNameSecond=strNameSecond;
00078     m_strKindSecond=strKindSecond;
00079     m_strRoleSecond=strRoleSecond;
00080     m_strAttributeSecond=strAttributeSecond;
00081    
00082 
00083     //check if nothing is present in the second
00084     if(strAttributeSecond.Trim()==_T("") && strKindSecond.Trim()==_T("")&& strRoleSecond.Trim()==_T("") && strAttributeSecond.Trim()==_T(""))
00085     {
00086         m_bDoSecond=FALSE;
00087     }
00088     else m_bDoSecond=TRUE;
00089     //getSplSearch = spl;
00090 
00091     m_bGetModels = mod;
00092     m_bGetAtoms = atom;
00093     m_bGetReferences = ref;
00094     m_bGetSets = set;
00095     m_bGetConnections=connection;
00096     m_bGetSplSearch=splSearch;
00097     m_intScope=scopedSearch;
00098     m_intLogical=logicalExpr;
00099     ParseAttribute();
00100 }
00101 
00102 //Parses attribute expressions and keeps it in stack
00103 //Two stacks are used for both lhs and rhs search criteria
00104 void CInput::ParseAttribute()
00105 {
00106     //prepare the stack containing expressions and operations for first attribute
00107     PrepareExpressionStack(m_strAttributeFirst,m_stackExpressionFirst);
00108 
00109     //prepare the stack containing expressions and operations for second attribute
00110     PrepareExpressionStack(m_strAttributeSecond,m_stackExpressionSecond);
00111 }
00112 
00113 void CInput::PrepareExpressionStack(const CString &atrAttributeExpression,std::vector<Attribute>& stack)
00114 {
00115     //strOperation stores operators like &, |
00116     //strUnitExpression is the expression like age> 30, i.e. it
00117     //is a complete single expression without logical operator
00118     CString strOperation,strUnitExpression; 
00119 
00120     CString strAttributeExpression(atrAttributeExpression);
00121 
00122     //get the index of logical operator
00123     int index= strAttributeExpression.FindOneOf(_T("&|"));
00124 
00125     //if no logical operator was found push the whole expression
00126     if(index==-1 && strAttributeExpression!=_T(""))
00127     {
00128         stack.push_back(Attribute(strAttributeExpression.Trim()));
00129     }
00130    
00131     while(index!=-1)
00132     {
00133         //extract the operator
00134         strOperation=strAttributeExpression[index];
00135 
00136         //extract a single expression, the string on left of the index is a complete
00137         //expression
00138         AfxExtractSubString(strUnitExpression,strAttributeExpression,0,strAttributeExpression[index]);
00139 
00140         //put the expression on stack
00141         stack.push_back(Attribute(strUnitExpression.Trim()));
00142 
00143         //push the operator either &, |
00144         stack.push_back(Attribute(CString(strOperation)));
00145 
00146         //extract the remaining string on the right of index
00147         strAttributeExpression=strAttributeExpression.Right(strAttributeExpression.GetLength()-index-1);
00148         
00149         //again find the logical operator
00150         index= strAttributeExpression.FindOneOf(_T("&|"));
00151 
00152         //if no more found treat all remaining string as expression
00153         if(index==-1) stack.push_back(Attribute(strAttributeExpression.Trim()));
00154     }
00155 }
00156 
00157 //Obtain regular expression form of the string
00158 //supplied
00159 wregex CInput::GetRegExp(CString name)
00160 {
00161     CString temp=_T("");
00162     if(name.IsEmpty())
00163     {
00164         return wregex(name);
00165     }
00166     if(m_bFull)
00167     {
00168         temp=_T("^");
00169         temp+=name;
00170         temp+=_T("$");
00171         return wregex(temp);
00172     }
00173 
00174     return wregex(name);
00175 }