00001 #ifndef _TESTERS_H_
00002 #define _TESTERS_H_
00003
00004 #include "streenode.h"
00005 #include "namespace.h"
00006
00007 #include <list>
00008
00010 class NameTester : public Node::Tester{
00011 Node *name;
00012 public:
00013 NameTester(Node *iname) : name(iname) {};
00014 ~NameTester(){
00015 delete name;
00016 };
00017
00018 virtual bool test(const Node* node, const NameSpace& nameSpace) const {
00019 cout << "NODE NAME " << node->toString() << " " << (name->toString()) << " " << (node->toString() == name->toString()) << endl;
00020 return (node->toString() == name->toString());
00021 };
00022 virtual Tester* copy() const {
00023 return new NameTester(name->copy());
00024 };
00025 virtual Tester* substitute(const Node::Assignment &assign){
00026 substituteNode(name,assign);
00027 return this;
00028 };
00029 };
00030
00032 class TypeTester : public Node::Tester{
00033 Node *type;
00034 public:
00035 TypeTester(Node *itype) : type(itype) {};
00036 ~TypeTester(){
00037 delete type;
00038 };
00039
00040 virtual bool test(const Node* node, const NameSpace& nameSpace) const {
00041 cout << "NODE NAME " << node->getName() << " " << (type->toString()) << " " << (node->getName() == type->toString()) << endl;
00042 return (node->getName() == type->toString());
00043 };
00044 virtual Tester* copy() const {
00045 return new TypeTester(type->copy());
00046 };
00047 virtual Tester* substitute(const Node::Assignment &assign){
00048 substituteNode(type,assign);
00049 return this;
00050 };
00051 };
00052
00053 class AdaptedTester : public Node::Tester{
00054 protected:
00055 Tester *tester;
00056 public:
00057 AdaptedTester(Tester *itester) : tester(itester) {};
00058
00059 virtual ~AdaptedTester(){
00060 delete tester;
00061 };
00062 virtual Tester* substitute(const Node::Assignment &assign){
00063 tester->substitute(assign);
00064 return this;
00065 };
00066 };
00067
00068 class ExistsTester : public AdaptedTester{
00069 public:
00070 ExistsTester(Tester *itester) : AdaptedTester(itester) {};
00071
00072 virtual bool test(const Node* node, const NameSpace& nameSpace) const {
00073 return node->exists(tester, nameSpace);
00074 };
00075
00076 virtual Tester* copy() const {
00077 return new ExistsTester(tester->copy());
00078 };
00079 };
00080
00081 class ForallTester : public AdaptedTester{
00082 public:
00083 ForallTester(Tester *itester) : AdaptedTester(itester) {};
00084
00085 virtual bool test(const Node* node, const NameSpace& nameSpace) const {
00086 return node->forall(tester, nameSpace);
00087 };
00088
00089 virtual Tester* copy() const {
00090 return new ForallTester(tester->copy());
00091 };
00092 };
00093
00094 class NotTester : public AdaptedTester{
00095 public:
00096 NotTester(Tester *itester) : AdaptedTester(itester) {};
00097
00098 virtual bool test(const Node* node, const NameSpace& nameSpace) const {
00099 return !tester->test(node, nameSpace);
00100 };
00101
00102 virtual Tester* copy() const {
00103 return new NotTester(tester->copy());
00104 };
00105 };
00106
00107 class AttributeIssetTester : public Node::Tester{
00108 const string attribute;
00109 const bool global;
00110 public:
00111 AttributeIssetTester(const string& iattribute, const bool iglobal) : attribute(iattribute), global(iglobal) {};
00112 AttributeIssetTester(const Constant* iattribute, const bool iglobal) : attribute(iattribute->getValue()), global(iglobal) { delete iattribute; };
00113
00114 virtual bool test(const Node* node, const NameSpace& nameSpace) const {
00115 return nameSpace.isAttributeSet(node->toString(),attribute,global);
00116 };
00117
00118 virtual Tester* copy() const {
00119 return new AttributeIssetTester(attribute,global);
00120 };
00121
00122 virtual Tester* substitute(const Node::Assignment &assign){
00123 return this;
00124 };
00125
00126 };
00127
00128 class AttributeIsequalTester : public Node::Tester{
00129 const string attribute;
00130 Node* value;
00131 const bool global;
00132 public:
00133 AttributeIsequalTester(const string& iattribute, Node* ivalue, const bool iglobal)
00134 : attribute(iattribute), value(ivalue), global(iglobal) {};
00135 AttributeIsequalTester(const Constant* iattribute, Node* ivalue, const bool iglobal)
00136 : attribute(iattribute->getValue()), value(ivalue), global(iglobal) { delete iattribute; };
00137
00138 ~AttributeIsequalTester(){
00139 delete value;
00140 };
00141
00142 virtual bool test(const Node* node, const NameSpace& nameSpace) const {
00143 return nameSpace.isAttributeEqual(node->toString(),attribute,value->toString(),global);
00144 };
00145
00146 virtual Tester* copy() const {
00147 return new AttributeIsequalTester(new Constant(attribute),value->copy(),global);
00148 };
00149
00150 virtual Tester* substitute(const Node::Assignment &assign){
00151 substituteNode(value,assign);
00152 return this;
00153 };
00154 };
00155
00156 class LocalAttributeIssetTester : public Node::Tester{
00157 const string attribute;
00158 const bool global;
00159 public:
00160 LocalAttributeIssetTester(const string& iattribute, const bool iglobal) : attribute(iattribute), global(iglobal) {};
00161 LocalAttributeIssetTester(const Constant* iattribute, const bool iglobal) : attribute(iattribute->getValue()), global(iglobal) { delete iattribute; };
00162
00163 virtual bool test(const Node* node, const NameSpace& nameSpace) const {
00164 return nameSpace.isAttributeSet("",attribute,global);
00165 };
00166
00167 virtual Tester* copy() const {
00168 return new LocalAttributeIssetTester(attribute,global);
00169 };
00170
00171 virtual Tester* substitute(const Node::Assignment &assign){
00172 return this;
00173 };
00174
00175 };
00176
00177 class LocalAttributeIsequalTester : public Node::Tester{
00178 const string attribute;
00179 Node* value;
00180 const bool global;
00181 public:
00182 LocalAttributeIsequalTester(const string& iattribute, Node* ivalue, const bool iglobal)
00183 : attribute(iattribute), value(ivalue), global(iglobal) {};
00184 LocalAttributeIsequalTester(const Constant* iattribute, Node* ivalue, const bool iglobal)
00185 : attribute(iattribute->getValue()), value(ivalue), global(iglobal) { delete iattribute; };
00186
00187 ~LocalAttributeIsequalTester(){
00188 delete value;
00189 };
00190
00191 virtual bool test(const Node* node, const NameSpace& nameSpace) const {
00192 return nameSpace.isAttributeEqual("",attribute,value->toString(),global);
00193 };
00194
00195 virtual Tester* copy() const {
00196 return new LocalAttributeIsequalTester(new Constant(attribute),value->copy(),global);
00197 };
00198
00199 virtual Tester* substitute(const Node::Assignment &assign){
00200 substituteNode(value,assign);
00201 return this;
00202 };
00203 };
00204
00205 class TesterSet : public Node::Tester, protected list<Node::Tester*> {
00206 protected:
00207 TesterSet* copyContent(TesterSet* newTesterSet) const{
00208 const_iterator it = begin();
00209 const_iterator eit = end();
00210 while (it!=eit){
00211 newTesterSet->insert((*it)->copy());
00212 it++;
00213 };
00214 return newTesterSet;
00215 };
00216
00217 TesterSet() {};
00218 TesterSet(Tester* tester) { push_back(tester); };
00219
00220 public:
00221
00222 TesterSet* insert(Tester* tester){
00223 push_back(tester);
00224 return this;
00225 };
00226
00227 virtual ~TesterSet(){
00228 iterator it = begin();
00229 iterator eit = end();
00230 while (it!=eit){
00231 delete *it;
00232 it++;
00233 };
00234 };
00235
00236 virtual Tester* substitute(const Node::Assignment &assign){
00237 iterator it = begin();
00238 iterator eit = end();
00239 while (it!=eit){
00240 (*it)->substitute(assign);
00241 it++;
00242 };
00243 return this;
00244 };
00245 };
00246
00247 class TesterSetForall : public TesterSet{
00248 public:
00249 TesterSetForall() : TesterSet() {};
00250 TesterSetForall(Tester* tester) : TesterSet(tester) {};
00251 TesterSetForall(Tester* tester1, Tester* tester2) { insert(tester1); insert(tester2); };
00252
00253 virtual bool test(const Node* node, const NameSpace& nameSpace) const {
00254 const_iterator it = begin();
00255 const_iterator eit = end();
00256 while (it!=eit){
00257 if (!(*it)->test(node,nameSpace)) return false;
00258 it++;
00259 };
00260 return true;
00261 };
00262
00263 virtual Tester* copy() const{
00264 return copyContent(new TesterSetForall());
00265 };
00266 };
00267
00268 class TesterSetExists : public TesterSet{
00269 public:
00270 TesterSetExists() : TesterSet() {};
00271 TesterSetExists(Tester* tester) : TesterSet(tester) { };
00272 TesterSetExists(Tester* tester1, Tester* tester2) { insert(tester1); insert(tester2); };
00273
00274 virtual bool test(const Node* node, const NameSpace& nameSpace) const {
00275 const_iterator it = begin();
00276 const_iterator eit = end();
00277 while (it!=eit){
00278 if ((*it)->test(node,nameSpace)) return true;
00279 it++;
00280 };
00281 return false;
00282 };
00283
00284 virtual Tester* copy() const{
00285 return copyContent(new TesterSetExists());
00286 };
00287 };
00288
00289 #endif