00001 #include "namedcontext.h"
00002
00003 NamedContext::NamedContext(const string &iname, RuleList &irules, NameSpace &inameSpace)
00004 : RuleContext(irules, inameSpace), name(iname), usedNames(0) {
00005 };
00006
00011 void NamedContext::generateVariableNames(const Node::VariableList &vlist, Node::Assignment &phpAssign, Node::Assignment &tplAssign){
00012 Node::VariableList::const_iterator it = vlist.begin();
00013 Node::VariableList::const_iterator eit = vlist.end();
00014 while (it!=eit){
00015 string newVariableName = generateVariableName();
00016 phpAssign.insert(pair<int,const Node*>(*it,new Constant(newVariableName)));
00017 tplAssign.insert(pair<int,const Node*>(*it,new Constant(newVariableName)));
00018 it++;
00019 };
00020 };
00021
00022 const string NamedContext::getVariableNamePrefix(){
00023 return name;
00024 };
00025
00026
00027 const string NamedContext::getVariableNameSufix(const bool stripControlVariableDollar){
00028 return "";
00029 };
00030
00031
00032 const string NamedContext::generateVariableName(){
00033 usedNames++;
00034 stringstream str;
00035 str << getVariableNamePrefix() << usedNames;
00036 registerSmartyVariable(str.str());
00037 return str.str();
00038 };
00039
00040 void NamedContext::registerSmartyVariable(const string &variable){
00041 smartyVariableList.insert(variable);
00042 };
00043
00044 void NamedContext::processSmartyAssign(SmartyAssign *smartyAssign){
00045 stringstream str;
00046 str << "$smarty->assign(\"" << smartyAssign->getVariable()
00047 << "\"," << smartyAssign->getAssignment() << ");" << endl;
00048 smartyAssign->setPHPOut(str.str());
00049 };
00050
00051 void NamedContext::leaveContext(List *phpOut, List *tplOut){
00052 SmartyVariableList::iterator it = smartyVariableList.begin();
00053 SmartyVariableList::iterator eit = smartyVariableList.end();
00054 while (it!=eit){
00055 stringstream str;
00056 str << "$smarty->assign_by_ref(\"" << (*it) << "\",$" << (*it) << ");" << endl;
00057 phpOut->push_back(new Constant(str.str()));
00058 it++;
00059 };
00060 };
00061
00062 void NamedContext::processTemplate(Node* tpl) const{
00063
00064 };
00065
00066
00067