diff options
-rw-r--r-- | openscad.pro | 3 | ||||
-rw-r--r-- | src/cgaladv.cc | 2 | ||||
-rw-r--r-- | src/control.cc | 8 | ||||
-rw-r--r-- | src/csgops.cc | 2 | ||||
-rw-r--r-- | src/dxflinextrude.cc | 2 | ||||
-rw-r--r-- | src/dxflinextrudenode.h | 1 | ||||
-rw-r--r-- | src/dxfrotextrude.cc | 2 | ||||
-rw-r--r-- | src/dxfrotextrudenode.h | 1 | ||||
-rw-r--r-- | src/importnode.h | 1 | ||||
-rw-r--r-- | src/module.cc | 4 | ||||
-rw-r--r-- | src/node.cc | 9 | ||||
-rw-r--r-- | src/node.h | 10 | ||||
-rw-r--r-- | src/projection.cc | 2 | ||||
-rw-r--r-- | src/projectionnode.h | 1 | ||||
-rw-r--r-- | src/render.cc | 2 | ||||
-rw-r--r-- | src/rendernode.h | 1 | ||||
-rw-r--r-- | src/stl-utils.h | 19 | ||||
-rw-r--r-- | src/transform.cc | 2 | ||||
-rw-r--r-- | src/traverser.cc | 18 | ||||
-rw-r--r-- | src/traverser.h | 2 |
20 files changed, 59 insertions, 33 deletions
diff --git a/openscad.pro b/openscad.pro index 00d646c..d89a074 100644 --- a/openscad.pro +++ b/openscad.pro @@ -164,7 +164,8 @@ HEADERS += src/renderer.h \ src/CSGTermEvaluator.h \ src/myqhash.h \ src/Tree.h \ - src/mathc99.h + src/mathc99.h \ + src/stl-utils.h SOURCES += src/openscad.cc \ src/mainwin.cc \ diff --git a/src/cgaladv.cc b/src/cgaladv.cc index f3f2cbd..6e26713 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -138,7 +138,7 @@ AbstractNode *CgaladvModule::evaluate(const Context *ctx, const ModuleInstantiat foreach (ModuleInstantiation *v, inst->children) { AbstractNode *n = v->evaluate(inst->ctx); if (n) - node->children.append(n); + node->children.push_back(n); } return node; diff --git a/src/control.cc b/src/control.cc index ca1a4c6..e1b816c 100644 --- a/src/control.cc +++ b/src/control.cc @@ -82,7 +82,7 @@ void for_eval(AbstractNode *node, int l, const QVector<QString> &call_argnames, foreach (ModuleInstantiation *v, arg_children) { AbstractNode *n = v->evaluate(arg_context); if (n != NULL) - node->children.append(n); + node->children.push_back(n); } } } @@ -139,7 +139,7 @@ AbstractNode *ControlModule::evaluate(const Context*, const ModuleInstantiation foreach (ModuleInstantiation *v, inst->children) { AbstractNode *n = v->evaluate(&c); if (n != NULL) - node->children.append(n); + node->children.push_back(n); } } @@ -155,14 +155,14 @@ AbstractNode *ControlModule::evaluate(const Context*, const ModuleInstantiation foreach (ModuleInstantiation *v, ifelse->children) { AbstractNode *n = v->evaluate(ifelse->ctx); if (n != NULL) - node->children.append(n); + node->children.push_back(n); } } else { foreach (ModuleInstantiation *v, ifelse->else_children) { AbstractNode *n = v->evaluate(ifelse->ctx); if (n != NULL) - node->children.append(n); + node->children.push_back(n); } } } diff --git a/src/csgops.cc b/src/csgops.cc index 53e9ed6..334db16 100644 --- a/src/csgops.cc +++ b/src/csgops.cc @@ -47,7 +47,7 @@ AbstractNode *CsgModule::evaluate(const Context*, const ModuleInstantiation *ins foreach (ModuleInstantiation *v, inst->children) { AbstractNode *n = v->evaluate(inst->ctx); if (n != NULL) - node->children.append(n); + node->children.push_back(n); } return node; } diff --git a/src/dxflinextrude.cc b/src/dxflinextrude.cc index 64c4c35..4bae863 100644 --- a/src/dxflinextrude.cc +++ b/src/dxflinextrude.cc @@ -113,7 +113,7 @@ AbstractNode *DxfLinearExtrudeModule::evaluate(const Context *ctx, const ModuleI foreach (ModuleInstantiation *v, inst->children) { AbstractNode *n = v->evaluate(inst->ctx); if (n) - node->children.append(n); + node->children.push_back(n); } } diff --git a/src/dxflinextrudenode.h b/src/dxflinextrudenode.h index dba03e8..70e7a06 100644 --- a/src/dxflinextrudenode.h +++ b/src/dxflinextrudenode.h @@ -3,6 +3,7 @@ #include "node.h" #include "visitor.h" +#include <QString> class DxfLinearExtrudeNode : public AbstractPolyNode { diff --git a/src/dxfrotextrude.cc b/src/dxfrotextrude.cc index ec75a52..7fdcd41 100644 --- a/src/dxfrotextrude.cc +++ b/src/dxfrotextrude.cc @@ -89,7 +89,7 @@ AbstractNode *DxfRotateExtrudeModule::evaluate(const Context *ctx, const ModuleI foreach (ModuleInstantiation *v, inst->children) { AbstractNode *n = v->evaluate(inst->ctx); if (n) - node->children.append(n); + node->children.push_back(n); } } diff --git a/src/dxfrotextrudenode.h b/src/dxfrotextrudenode.h index 38ca087..aa22a73 100644 --- a/src/dxfrotextrudenode.h +++ b/src/dxfrotextrudenode.h @@ -3,6 +3,7 @@ #include "node.h" #include "visitor.h" +#include <QString> class DxfRotateExtrudeNode : public AbstractPolyNode { diff --git a/src/importnode.h b/src/importnode.h index bdbf193..94417b9 100644 --- a/src/importnode.h +++ b/src/importnode.h @@ -3,6 +3,7 @@ #include "node.h" #include "visitor.h" +#include <QString> enum import_type_e { TYPE_STL, diff --git a/src/module.cc b/src/module.cc index efe98e4..81dddf9 100644 --- a/src/module.cc +++ b/src/module.cc @@ -43,7 +43,7 @@ AbstractNode *AbstractModule::evaluate(const Context*, const ModuleInstantiation foreach (ModuleInstantiation *v, inst->children) { AbstractNode *n = v->evaluate(inst->ctx); if (n) - node->children.append(n); + node->children.push_back(n); } return node; @@ -151,7 +151,7 @@ AbstractNode *Module::evaluate(const Context *ctx, const ModuleInstantiation *in for (int i = 0; i < children.size(); i++) { AbstractNode *n = children[i]->evaluate(&c); if (n != NULL) - node->children.append(n); + node->children.push_back(n); } return node; diff --git a/src/node.cc b/src/node.cc index 3bc8d7b..e2f3fa0 100644 --- a/src/node.cc +++ b/src/node.cc @@ -32,9 +32,10 @@ #include "polyset.h" #include "visitor.h" #include "nodedumper.h" +#include "stl-utils.h" -#include <QRegExp> #include <sstream> +#include <algorithm> size_t AbstractNode::idx_counter; @@ -46,8 +47,7 @@ AbstractNode::AbstractNode(const ModuleInstantiation *mi) AbstractNode::~AbstractNode() { - foreach (AbstractNode *v, children) - delete v; + std::for_each(this->children.begin(), this->children.end(), del_fun<AbstractNode>()); } Response AbstractNode::accept(class State &state, Visitor &visitor) const @@ -87,8 +87,7 @@ std::string AbstractIntersectionNode::name() const void AbstractNode::progress_prepare() { - foreach (AbstractNode *v, children) - v->progress_prepare(); + std::for_each(this->children.begin(), this->children.end(), std::mem_fun(&AbstractNode::progress_prepare)); this->progress_mark = ++progress_report_count; } @@ -1,8 +1,7 @@ #ifndef NODE_H_ #define NODE_H_ -#include <QCache> -#include <QVector> +#include <vector> #include "traverser.h" @@ -38,16 +37,15 @@ public: virtual std::string name() const; // FIXME: Make return value a reference - const std::list<AbstractNode*> getChildren() const { - return this->children.toList().toStdList(); + const std::vector<AbstractNode*> getChildren() const { + return this->children; } size_t index() const { return this->idx; } static void resetIndexCounter() { idx_counter = 1; } - // FIXME: Rewrite to STL container? // FIXME: Make protected - QVector<AbstractNode*> children; + std::vector<AbstractNode*> children; const ModuleInstantiation *modinst; // progress_mark is a running number used for progress indication diff --git a/src/projection.cc b/src/projection.cc index 8497405..67bd683 100644 --- a/src/projection.cc +++ b/src/projection.cc @@ -77,7 +77,7 @@ AbstractNode *ProjectionModule::evaluate(const Context *ctx, const ModuleInstant foreach (ModuleInstantiation *v, inst->children) { AbstractNode *n = v->evaluate(inst->ctx); if (n) - node->children.append(n); + node->children.push_back(n); } return node; diff --git a/src/projectionnode.h b/src/projectionnode.h index 0c32181..4c29b7b 100644 --- a/src/projectionnode.h +++ b/src/projectionnode.h @@ -3,6 +3,7 @@ #include "node.h" #include "visitor.h" +#include <string> class ProjectionNode : public AbstractPolyNode { diff --git a/src/render.cc b/src/render.cc index cac03c3..a463c67 100644 --- a/src/render.cc +++ b/src/render.cc @@ -64,7 +64,7 @@ AbstractNode *RenderModule::evaluate(const Context *ctx, const ModuleInstantiati foreach (ModuleInstantiation *v, inst->children) { AbstractNode *n = v->evaluate(inst->ctx); if (n != NULL) - node->children.append(n); + node->children.push_back(n); } return node; diff --git a/src/rendernode.h b/src/rendernode.h index c5ebdae..9138c29 100644 --- a/src/rendernode.h +++ b/src/rendernode.h @@ -3,6 +3,7 @@ #include "node.h" #include "visitor.h" +#include <string> class RenderNode : public AbstractNode { diff --git a/src/stl-utils.h b/src/stl-utils.h new file mode 100644 index 0000000..a48b7d5 --- /dev/null +++ b/src/stl-utils.h @@ -0,0 +1,19 @@ +#ifndef STLUTILS_H_ +#define STLUTILS_H_ + +template<class T> +struct del_fun_t +{ + del_fun_t& operator()(T* p) { + delete p; + return *this; + } +}; + +template<class T> +del_fun_t<T> del_fun() +{ + return del_fun_t<T>(); +} + +#endif diff --git a/src/transform.cc b/src/transform.cc index b22b766..92ff973 100644 --- a/src/transform.cc +++ b/src/transform.cc @@ -275,7 +275,7 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti foreach (ModuleInstantiation *v, inst->children) { AbstractNode *n = v->evaluate(inst->ctx); if (n != NULL) - node->children.append(n); + node->children.push_back(n); } return node; diff --git a/src/traverser.cc b/src/traverser.cc index 27bb116..a87449b 100644 --- a/src/traverser.cc +++ b/src/traverser.cc @@ -2,6 +2,7 @@ #include "visitor.h" #include "node.h" #include "state.h" +#include <algorithm> void Traverser::execute() { @@ -9,6 +10,15 @@ void Traverser::execute() traverse(this->root, state); } +struct TraverseNode +{ + Traverser *traverser; + const State &state; + TraverseNode(Traverser *traverser, const State &state) : + traverser(traverser), state(state) {} + void operator()(const AbstractNode *node) { traverser->traverse(*node, state); } +}; + void Traverser::traverse(const AbstractNode &node, const State &state) { // FIXME: Handle abort @@ -23,13 +33,7 @@ void Traverser::traverse(const AbstractNode &node, const State &state) } newstate.setParent(&node); - const std::list<AbstractNode*> &children = node.getChildren(); - for (std::list<AbstractNode*>::const_iterator iter = children.begin(); - iter != children.end(); - iter++) { - - traverse(**iter, newstate); - } + std::for_each(node.getChildren().begin(), node.getChildren().end(), TraverseNode(this, newstate)); if (traversaltype == POSTFIX || traversaltype == PRE_AND_POSTFIX) { newstate.setParent(state.parent()); diff --git a/src/traverser.h b/src/traverser.h index a96b05b..85373cc 100644 --- a/src/traverser.h +++ b/src/traverser.h @@ -14,9 +14,9 @@ public: virtual ~Traverser() { } void execute(); -private: // FIXME: reverse parameters void traverse(const AbstractNode &node, const class State &state); +private: Visitor &visitor; const AbstractNode &root; |