00001 #include "rtreemulticontextrule.h" 00002 #include "multicontext.h" 00003 00004 MultiContextRule::MultiContextRule(List* iphpInPattern, Variable* icontrolVariable, List* itplOutPattern, List* iphpOutPattern) : 00005 ContextRule(iphpInPattern,itplOutPattern,iphpOutPattern), controlVariable(icontrolVariable) {}; 00006 00007 MultiContextRule::~MultiContextRule(){ 00008 delete controlVariable; 00009 }; 00010 00011 RuleContext* MultiContextRule::generateSubcontext(RuleContext *context, const Node::Assignment &assign) const { 00012 const Node::Assignment::const_iterator controlVarialbeMatchedPair= assign.find(controlVariable->getId()); 00013 if (controlVarialbeMatchedPair == assign.end()){ 00014 cout << "A" << endl; 00015 return new MultiContext(context, controlVariable->getId()); 00016 } else { 00017 const Node* controlVariableMatched = controlVarialbeMatchedPair->second; 00018 if (controlVariableMatched->getName()!=CPHPVariable) 00019 throw "ERROR: MultiContextRule::generateSubcontext - control variable is not given by constant"; 00020 const PHPVariable* phpVariable = dynamic_cast<const PHPVariable*>(controlVariableMatched); 00021 return new MultiContext(context, controlVariable->getId(), 00022 dynamic_cast<const Constant*>(phpVariable->getStatement1())->getValue()); 00023 }; 00024 }; 00025 00026 ostream& MultiContextRule::print (ostream& os) const{ 00027 os << "MultiContextRule - "; 00028 phpInPattern->print(os); 00029 return os; 00030 }; 00031 00032 Rule* MultiContextRule::copy(){ 00033 return new MultiContextRule(phpInPattern->copyList(), 00034 dynamic_cast<Variable*>(controlVariable->copy()), 00035 tplOutPattern->copyList(), 00036 phpOutPattern->copyList()); 00037 };