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

streelist.cpp

Go to the documentation of this file.
00001 #include "streelist.h"
00002 
00003 List *List::copyContent(List *newList) const{
00004     const_iterator it = begin();
00005     const_iterator eit = end();
00006     while (it!=eit){
00007       newList->push_back((*it)->copy());
00008       it++;
00009     };
00010     return newList;
00011 }
00012 
00013 List::List(string iname) : name(iname) {};
00014 
00015 List::List(string iname, Node *statement): name(iname){
00016     push_back(statement);
00017 };
00018 
00019 List* List::push_back(Node *statement){
00020     list<Node*>::push_back(statement);
00021     return this;
00022 };
00023 
00024 List* List::push_front(Node *statement){
00025     list<Node*>::push_front(statement);
00026     return this;
00027 };
00028 
00029 List* List::append(List* toappend){
00030     //merge(*toappend);
00031     insert(end(),toappend->begin(),toappend->end());
00032     toappend->clear();
00033     delete toappend;
00034     return this;
00035 } 
00036 
00037 
00038 ostream& List::print(ostream &os) const{
00039     os << name << "[";
00040     const_iterator it = begin();
00041     const_iterator eit = end();
00042     while (it!=eit){
00043       (*it)->print(os);
00044       it++;
00045       if (it!=eit) os << ":";
00046     };
00047     return os << "]";
00048 };
00049 
00050 ostream& List::php(ostream &os) const{
00051       cerr <<"ERROR: php can not be called for unnamed lists  : " << name << endl;
00052       return print(os);
00053 }
00054   
00055 bool List::match(const Node *p, Assignment &assign, const NameSpace &nameSpace) const{
00056     // todo : bosuga SListVariable
00057     if (p->getType()!=SList) return false;
00058     
00059     const List *lp = dynamic_cast<const List*>(p);
00060     if ((lp->getLength()!=getLength())||(lp->getName()!=getName())) return false;
00061 
00062     const_iterator it = begin();
00063     const_iterator eit = end();
00064     const_iterator pit = lp->begin();
00065     //    const_iterator peit = lp->end();
00066     while (it!=eit){
00067       if (!(*it)->match(*pit,assign,nameSpace)) return false;
00068       it++;
00069       pit++;
00070     };
00071     return true;
00072 };
00073 
00074 bool List::matchToBegining(const List *p, Assignment &assign, const NameSpace &nameSpace) const{
00075     if (p->getLength()<getLength()) return false;
00076 
00077     const_iterator pit = p->begin();
00078     //    const_iterator peit = p->end();
00079     const_iterator it = begin();
00080     const_iterator eit = end();
00081 
00082     while (it!=eit){
00083       if (!(*it)->match(*pit,assign,nameSpace)) return false;
00084       it++;
00085       pit++;
00086     };
00087     return true;
00088 };
00089 
00090 
00091 bool List::compare(const Node *p) const{
00092     if (p->getType()!=SList) return false;
00093 
00094     List *lp = (List*)p;
00095     if ((lp->getLength()!=getLength())||(lp->getName()!=getName())) return false;
00096 
00097     const_iterator it = begin();
00098     const_iterator eit = end();
00099     const_iterator pit = lp->begin();
00100     //    const_iterator peit = lp->end();
00101     while (it!=eit){
00102       if (!(*it)->compare(*pit)) return false;
00103       it++;
00104       pit++;
00105     }
00106     return true;
00107 };
00108 
00109 Node* List::substitute(const Assignment &assign){
00110     iterator it = begin();
00111     iterator eit = end();
00112     while (it!=eit){
00113       substituteNode(*it,assign);
00114       it++;
00115     };
00116     return this;
00117 };
00118 
00119 Node* List::copy() const{
00120     return copyContent(new List(getName()));
00121 };
00122 
00123 List* List::copyList() const{
00124     return dynamic_cast<List*>(copy());
00125 };
00126 
00127 List::~List(){
00128     iterator it = begin();
00129     iterator eit = end();
00130     while (it!=eit){
00131       delete *it;
00132       it++;
00133     };    
00134 };
00135 
00136 void List::getVariables(VariableList &vlist) const{
00137     const_iterator it = begin();
00138     const_iterator eit = end();
00139     while (it!=eit){
00140       (*it)->getVariables(vlist);
00141       it++;
00142     };    
00143 };
00144 
00145 Node* List::transform(const Transformer* transformer){
00146   iterator it = begin();
00147   iterator eit = end();
00148   while (it!=eit){
00149     Node *targ = (*it)->transform(transformer);
00150     if (targ!=*it) {
00151       delete *it;
00152       *it = targ;
00153     }
00154     it++;
00155   };
00156   return transformer->transform(this);
00157 };
00158 
00159 bool List::forall(const Tester* tester, const NameSpace &nameSpace) const{
00160   if (!tester->test(this, nameSpace))
00161     return false;
00162   const_iterator it = begin();
00163   const_iterator eit = end();
00164   while (it!=eit){
00165     if (!(*it)->forall(tester, nameSpace))
00166       return false;
00167     it++;
00168   };
00169   return true;
00170 };
00171 
00172 bool List::exists(const Tester* tester, const NameSpace &nameSpace) const{
00173   if (tester->test(this, nameSpace))
00174     return true;
00175   const_iterator it = begin();
00176   const_iterator eit = end();
00177   while (it!=eit){
00178     if ((*it)->exists(tester, nameSpace))
00179       return true;
00180     it++;
00181   };
00182   return false;
00183 };
00184 
00185 string List::evaluate(const NameSpace &nameSpace) const{
00186   throw "ERROR: List::evaluate";
00187 };

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