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

rtreeactionrule.cpp

Go to the documentation of this file.
00001 #include "rtreeactionrule.h"
00002 
00003 ActionWrite::ActionWrite(Node* iexpr) : expr(iexpr) {};
00004 ActionWrite::~ActionWrite() {
00005   delete expr;
00006 };
00007 
00008 void ActionWrite::execute(NameSpace &nameSpace){
00009   cout << expr->evaluate(nameSpace) << endl;
00010 };
00011 
00012 Action* ActionWrite::copy() const{
00013   return new ActionWrite(expr->copy());
00014 };
00015 
00016 Action* ActionWrite::substitute(const Node::Assignment &assign){
00017   substituteNode(expr,assign);
00018   return this;
00019 };
00020 
00021 
00022 ActionSet::ActionSet(Node* iname, Constant* iattribute, Node* iexpr, bool iglobal) 
00023   : name(iname), attribute(iattribute->getValue()),expr(iexpr), global(iglobal) 
00024 {
00025   delete iattribute;
00026 };
00027 ActionSet::~ActionSet(){
00028   delete name;
00029   delete expr;
00030 };
00031 
00032 void ActionSet::execute(NameSpace &nameSpace){
00033   nameSpace.setAttributeValue(name->toString(),
00034                               attribute,
00035                               expr->evaluate(nameSpace),global);
00036 };
00037 
00038 Action* ActionSet::copy() const{
00039   return new ActionSet(name->copy(), new Constant(attribute), expr->copy(), global);
00040 };
00041 
00042 Action* ActionSet::substitute(const Node::Assignment &assign){
00043   substituteNode(name,assign);
00044   substituteNode(expr,assign);
00045   return this;
00046 };
00047 
00048 ActionList::~ActionList(){
00049   iterator it = begin();
00050   iterator eit = end();
00051   while (it!=eit){
00052     delete *it;
00053     it++;
00054   };
00055 };
00056 
00057 ActionList* ActionList::copy() const{
00058   ActionList* result = new ActionList();
00059   const_iterator it = begin();
00060   const_iterator eit = end();
00061   while (it!=eit){
00062     result->push_back((*it)->copy());
00063     it++;
00064   };
00065   return result;
00066 }
00067 
00068 ActionList* ActionList::substitute(const Node::Assignment &assign){
00069   iterator it = begin();
00070   iterator eit = end();
00071   while (it!=eit){
00072     (*it)->substitute(assign);
00073     it++;
00074   };
00075   return this;
00076 }
00077 
00078 void ActionList::execute(NameSpace &nameSpace) const{
00079   const_iterator it = begin();
00080   const_iterator eit = end();
00081   while (it!=eit){
00082     (*it)->execute(nameSpace);
00083     it++;
00084   };
00085 };
00086 
00087 ActionList* ActionList::push_back(Action* action){
00088     list<Action*>::push_back(action);
00089     return this;
00090 };
00091 
00092 
00093 
00094 ActionRule::ActionRule(List* iphpInPattern, ActionList* iactions)
00095   : phpInPattern(iphpInPattern), actions(iactions) {};
00096 
00097 ActionRule::~ActionRule(){
00098   delete phpInPattern;
00099   delete actions;
00100 };
00101 
00102 bool ActionRule::execute(RuleContext* context, List* phpIn, List* phpOut, List* tplOut,Node::Assignment &assign) const {
00103   if (phpInPattern->matchToBegining(phpIn,assign,context->getNameSpace())){
00104     ActionList *toDo = actions->copy()->substitute(assign);
00105     toDo->execute(context->getNameSpace());
00106     for (int i=0 ; i<phpInPattern->getLength() ; i++){
00107       phpOut->push_back(phpIn->front());
00108       phpIn->pop_front();
00109     };
00110     delete toDo;
00111     return true;
00112   }
00113   return false;
00114 };
00115 
00116 Rule* ActionRule::copy(){
00117   return new ActionRule(phpInPattern->copyList(),actions->copy());
00118 };
00119 
00120 Rule* ActionRule::substitute(const Node::Assignment &assign){
00121   phpInPattern->substitute(assign);
00122   actions->substitute(assign);
00123   return this;
00124 };
00125 
00126 ostream& ActionRule::print(ostream& os) const{
00127   os << "ActionRule - ";
00128   phpInPattern->print(os);
00129   //      tplOutPattern->print(os);
00130   return os;
00131 };
00132 
00133 
00134 RuleWithActionRule::RuleWithActionRule(Rule* irule, ActionList* iactions)
00135   : rule(irule), actions(iactions) {};
00136 
00137 RuleWithActionRule::~RuleWithActionRule(){
00138   delete rule;
00139   delete actions;
00140 };
00141 
00142 bool RuleWithActionRule::execute(RuleContext* context, List* phpIn, List* phpOut, List* tplOut,Node::Assignment &assign) const {
00143   if (rule->execute(context,phpIn,phpOut,tplOut,assign)) {
00144     ActionList *toDo = actions->copy()->substitute(assign);
00145     toDo->execute(context->getNameSpace());
00146     delete toDo;
00147     return true;
00148   }
00149   return false;
00150 };
00151 
00152 Rule* RuleWithActionRule::copy(){
00153   return new RuleWithActionRule(rule->copy(),actions->copy());
00154 };
00155 
00156 Rule* RuleWithActionRule::substitute(const Node::Assignment &assign){
00157   rule->substitute(assign);
00158   actions->substitute(assign);
00159   return this;
00160 };
00161 
00162 ostream& RuleWithActionRule::print(ostream& os) const{
00163   os << "RuleWithActionRule - " << rule;
00164   return os;
00165 };

Generated on Fri Nov 21 17:54:03 2003 for PHPX by doxygen 1.3.3