#ifndef COLLAPSETRANSFORMATION_H #define COLLAPSETRANSFORMATION_H #include #include #include "NodeTransformation.h" template class CollapseTransformation: public NodeTransformation { public: CollapseTransformation(T toCollapse); ~CollapseTransformation(); virtual NodeTree* transform(NodeTree* from); private: T toCollapse; }; #endif template CollapseTransformation::CollapseTransformation(T toCollapse) { this->toCollapse = toCollapse; } template CollapseTransformation::~CollapseTransformation() { // } template NodeTree* CollapseTransformation::transform(NodeTree* from) { std::queue*> toProcess; toProcess.push(from); while(!toProcess.empty()) { NodeTree* node = toProcess.front(); toProcess.pop(); std::vector*> children = node->getChildren(); for (int i = 0; i < children.size(); i++) { if (children[i]->getData() == toCollapse) { node->removeChild(children[i]); std::vector*> newChildren = children[i]->getChildren(); node->insertChildren(i,newChildren); toProcess.push(node); //Do this node again } else toProcess.push(children[i]); } } return from; }