summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2011-09-03 04:10:36 (GMT)
committerMarius Kintel <marius@kintel.net>2011-09-03 04:10:36 (GMT)
commit6f632190a05417d44193e3b16a7b3000b2cc1145 (patch)
tree9ddccef57c10361a7019274f79f1d86edb7630d3
parent3129189342f3da7322efa0b860ff3ff676ba7b77 (diff)
Ported a bunch of stuff from Qt to STL
-rw-r--r--doc/visitor-changes.txt2
-rw-r--r--src/PolySetCGALEvaluator.cc10
-rw-r--r--src/builtin.h7
-rw-r--r--src/cgaladv.cc12
-rw-r--r--src/color.cc16
-rw-r--r--src/context.cc95
-rw-r--r--src/context.h37
-rw-r--r--src/control.cc14
-rw-r--r--src/dxfdim.cc73
-rw-r--r--src/dxfdim.h6
-rw-r--r--src/dxflinextrude.cc21
-rw-r--r--src/dxflinextrudenode.h3
-rw-r--r--src/dxfrotextrude.cc19
-rw-r--r--src/dxfrotextrudenode.h3
-rw-r--r--src/expr.cc158
-rw-r--r--src/expression.h14
-rw-r--r--src/func.cc103
-rw-r--r--src/function.h22
-rw-r--r--src/import.cc30
-rw-r--r--src/importnode.h5
-rw-r--r--src/mainwin.cc6
-rw-r--r--src/module.cc120
-rw-r--r--src/module.h51
-rw-r--r--src/parser.y202
-rw-r--r--src/primitives.cc22
-rw-r--r--src/projection.cc11
-rw-r--r--src/render.cc9
-rw-r--r--src/surface.cc46
-rw-r--r--src/transform.cc20
29 files changed, 580 insertions, 557 deletions
diff --git a/doc/visitor-changes.txt b/doc/visitor-changes.txt
index 1e05cee..2fdc944 100644
--- a/doc/visitor-changes.txt
+++ b/doc/visitor-changes.txt
@@ -1,3 +1,3 @@
Changes in visitor branch:
-o import_dxf(): layername="" imports all layers. Importing a single layer with a zero-length name is no longer supported.
+o import_dxf(): layername="" imports all layers. Importing a single layer with a zero-length name is no longer supported. FIXME: The same prob. goes for dims
o cylinder(): the r parameter will now always be used in place of a missing r1 or r2
diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc
index 500c87d..791ad51 100644
--- a/src/PolySetCGALEvaluator.cc
+++ b/src/PolySetCGALEvaluator.cc
@@ -246,7 +246,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const DxfLinearExtrudeNode &node,
DxfData *dxf;
- if (node.filename.isEmpty())
+ if (node.filename.empty())
{
// Before extruding, union all (2D) children nodes
// to a single DxfData, then tesselate this into a PolySet
@@ -260,7 +260,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const DxfLinearExtrudeNode &node,
dxf = sum.convertToDxfData();;
} else {
- dxf = new DxfData(node.fn, node.fs, node.fa, node.filename, node.layername, node.origin_x, node.origin_y, node.scale);
+ dxf = new DxfData(node.fn, node.fs, node.fa, QString::fromStdString(node.filename), QString::fromStdString(node.layername), node.origin_x, node.origin_y, node.scale);
}
PolySet *ps = extrudeDxfData(node, *dxf);
@@ -291,7 +291,7 @@ PolySet *PolySetCGALEvaluator::extrudeDxfData(const DxfLinearExtrudeNode &node,
continue;
if (first_open_path) {
PRINTF("WARNING: Open paths in dxf_linear_extrude(file = \"%s\", layer = \"%s\"):",
- node.filename.toAscii().data(), node.layername.toAscii().data());
+ node.filename.c_str(), node.layername.c_str());
first_open_path = false;
}
PRINTF(" %9.5f %10.5f ... %10.5f %10.5f",
@@ -343,7 +343,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const DxfRotateExtrudeNode &node,
DxfData *dxf;
- if (node.filename.isEmpty())
+ if (node.filename.empty())
{
// Before extruding, union all (2D) children nodes
// to a single DxfData, then tesselate this into a PolySet
@@ -357,7 +357,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const DxfRotateExtrudeNode &node,
dxf = sum.convertToDxfData();
} else {
- dxf = new DxfData(node.fn, node.fs, node.fa, node.filename, node.layername, node.origin_x, node.origin_y, node.scale);
+ dxf = new DxfData(node.fn, node.fs, node.fa, QString::fromStdString(node.filename), QString::fromStdString(node.layername), node.origin_x, node.origin_y, node.scale);
}
PolySet *ps = rotateDxfData(node, *dxf);
diff --git a/src/builtin.h b/src/builtin.h
index 79debe0..ae526f2 100644
--- a/src/builtin.h
+++ b/src/builtin.h
@@ -1,13 +1,14 @@
#ifndef BUILTIN_H_
#define BUILTIN_H_
-#include <QHash>
+#include <string>
+#include <boost/unordered_map.hpp>
-extern QHash<QString, class AbstractFunction*> builtin_functions;
+extern boost::unordered_map<std::string, class AbstractFunction*> builtin_functions;
extern void initialize_builtin_functions();
extern void destroy_builtin_functions();
-extern QHash<QString, class AbstractModule*> builtin_modules;
+extern boost::unordered_map<std::string, class AbstractModule*> builtin_modules;
extern void initialize_builtin_modules();
extern void destroy_builtin_modules();
diff --git a/src/cgaladv.cc b/src/cgaladv.cc
index 5b2e5df..908000d 100644
--- a/src/cgaladv.cc
+++ b/src/cgaladv.cc
@@ -32,6 +32,8 @@
#include "visitor.h"
#include <sstream>
#include <assert.h>
+#include <boost/assign/std/vector.hpp>
+using namespace boost::assign; // bring 'operator+=()' into scope
enum cgaladv_type_e {
MINKOWSKI,
@@ -88,17 +90,17 @@ AbstractNode *CgaladvModule::evaluate(const Context *ctx, const ModuleInstantiat
{
CgaladvNode *node = new CgaladvNode(inst, type);
- QVector<QString> argnames;
- QVector<Expression*> argexpr;
+ std::vector<std::string> argnames;
+ std::vector<Expression*> argexpr;
if (type == MINKOWSKI)
- argnames = QVector<QString>() << "convexity";
+ argnames += "convexity";
if (type == GLIDE)
- argnames = QVector<QString>() << "path" << "convexity";
+ argnames += "path", "convexity";
if (type == SUBDIV)
- argnames = QVector<QString>() << "type" << "level" << "convexity";
+ argnames += "type", "level", "convexity";
Context c(ctx);
c.args(argnames, argexpr, inst->argnames, inst->argvalues);
diff --git a/src/color.cc b/src/color.cc
index 7340612..c64745c 100644
--- a/src/color.cc
+++ b/src/color.cc
@@ -33,6 +33,8 @@
#include <sstream>
#include <assert.h>
#include <QColor>
+#include <boost/assign/std/vector.hpp>
+using namespace boost::assign; // bring 'operator+=()' into scope
class ColorModule : public AbstractModule
{
@@ -50,28 +52,28 @@ AbstractNode *ColorModule::evaluate(const Context *ctx, const ModuleInstantiatio
node->color[0] = node->color[1] = node->color[2] = -1.0;
node->color[3] = 1.0;
- QVector<QString> argnames;
- QVector<Expression*> argexpr;
+ std::vector<std::string> argnames;
+ std::vector<Expression*> argexpr;
- argnames = QVector<QString>() << "c" << "alpha";
+ argnames += "c", "alpha";
Context c(ctx);
c.args(argnames, argexpr, inst->argnames, inst->argvalues);
Value v = c.lookup_variable("c");
if (v.type == Value::VECTOR) {
- for (int i = 0; i < 4; i++)
+ for (size_t i = 0; i < 4; i++)
node->color[i] = i < v.vec.size() ? v.vec[i]->num : 1.0;
} else if (v.type == Value::STRING) {
- QString colorname = QString::fromStdString(v.text);
+ std::string colorname = v.text;
QColor color;
- color.setNamedColor(colorname);
+ color.setNamedColor(QString::fromStdString(colorname));
if (color.isValid()) {
node->color[0] = color.redF();
node->color[1] = color.greenF();
node->color[2] = color.blueF();
} else {
- PRINTA_NOCACHE("WARNING: Color name \"%1\" unknown. Please see", colorname);
+ PRINTF_NOCACHE("WARNING: Color name \"%s\" unknown. Please see", colorname.c_str());
PRINTF_NOCACHE("WARNING: http://en.wikipedia.org/wiki/Web_colors");
}
}
diff --git a/src/context.cc b/src/context.cc
index ba2690c..7a0e3cd 100644
--- a/src/context.cc
+++ b/src/context.cc
@@ -31,6 +31,7 @@
#include "printutils.h"
#include <QFileInfo>
#include <QDir>
+#include <boost/foreach.hpp>
Context::Context(const Context *parent)
{
@@ -40,7 +41,7 @@ Context::Context(const Context *parent)
usedlibs_p = NULL;
inst_p = NULL;
if (parent) document_path = parent->document_path;
- ctx_stack.append(this);
+ ctx_stack.push_back(this);
}
Context::~Context()
@@ -48,16 +49,16 @@ Context::~Context()
ctx_stack.pop_back();
}
-void Context::args(const QVector<QString> &argnames, const QVector<Expression*> &argexpr,
- const QVector<QString> &call_argnames, const QVector<Value> &call_argvalues)
+void Context::args(const std::vector<std::string> &argnames, const std::vector<Expression*> &argexpr,
+ const std::vector<std::string> &call_argnames, const std::vector<Value> &call_argvalues)
{
- for (int i=0; i<argnames.size(); i++) {
+ for (size_t i=0; i<argnames.size(); i++) {
set_variable(argnames[i], i < argexpr.size() && argexpr[i] ? argexpr[i]->evaluate(this->parent) : Value());
}
- int posarg = 0;
- for (int i=0; i<call_argnames.size(); i++) {
- if (call_argnames[i].isEmpty()) {
+ size_t posarg = 0;
+ for (size_t i=0; i<call_argnames.size(); i++) {
+ if (call_argnames[i].empty()) {
if (posarg < argnames.size())
set_variable(argnames[posarg++], call_argvalues[i]);
} else {
@@ -66,105 +67,103 @@ void Context::args(const QVector<QString> &argnames, const QVector<Expression*>
}
}
-QVector<const Context*> Context::ctx_stack;
+std::vector<const Context*> Context::ctx_stack;
-void Context::set_variable(QString name, Value value)
+void Context::set_variable(const std::string &name, Value value)
{
- if (name.startsWith("$"))
+ if (name[0] == '$')
config_variables[name] = value;
else
variables[name] = value;
}
-Value Context::lookup_variable(QString name, bool silent) const
+Value Context::lookup_variable(const std::string &name, bool silent) const
{
- if (name.startsWith("$")) {
+ if (name[0] == '$') {
for (int i = ctx_stack.size()-1; i >= 0; i--) {
- if (ctx_stack[i]->config_variables.contains(name))
- return ctx_stack[i]->config_variables[name];
+ const ValueMap &confvars = ctx_stack[i]->config_variables;
+ if (confvars.find(name) != confvars.end())
+ return confvars.find(name)->second;
}
return Value();
}
- if (!parent && constants.contains(name))
- return constants[name];
- if (variables.contains(name))
- return variables[name];
+ if (!parent && constants.find(name) != constants.end())
+ return constants.find(name)->second;
+ if (variables.find(name) != variables.end())
+ return variables.find(name)->second;
if (parent)
return parent->lookup_variable(name, silent);
if (!silent)
- PRINTA("WARNING: Ignoring unknown variable '%1'.", name);
+ PRINTF("WARNING: Ignoring unknown variable '%s'.", name.c_str());
return Value();
}
-void Context::set_constant(QString name, Value value)
+void Context::set_constant(const std::string &name, Value value)
{
- if (constants.contains(name))
- PRINTA("WARNING: Attempt to modify constant '%1'.",name);
- else
- constants.insert(name,value);
+ if (constants.count(name))
+ PRINTF("WARNING: Attempt to modify constant '%s'.",name.c_str());
+ else
+ constants[name] = value;
}
-Value Context::evaluate_function(QString name, const QVector<QString> &argnames, const QVector<Value> &argvalues) const
+Value Context::evaluate_function(const std::string &name, const std::vector<std::string> &argnames, const std::vector<Value> &argvalues) const
{
- if (functions_p && functions_p->contains(name))
- return functions_p->value(name)->evaluate(this, argnames, argvalues);
+ if (functions_p && functions_p->find(name) != functions_p->end())
+ return functions_p->find(name)->second->evaluate(this, argnames, argvalues);
if (usedlibs_p) {
- QHashIterator<QString, Module*> i(*usedlibs_p);
- while (i.hasNext()) {
- i.next();
- if (i.value()->functions.contains(name)) {
- Module *lib = i.value();
+ BOOST_FOREACH(const ModuleContainer::value_type &m, *usedlibs_p) {
+ if (m.second->functions.count(name)) {
+ Module *lib = m.second;
Context ctx(parent);
ctx.functions_p = &lib->functions;
ctx.modules_p = &lib->modules;
ctx.usedlibs_p = &lib->usedlibs;
- for (int j = 0; j < lib->assignments_var.size(); j++) {
+ for (size_t j = 0; j < lib->assignments_var.size(); j++) {
ctx.set_variable(lib->assignments_var[j], lib->assignments_expr[j]->evaluate(&ctx));
}
- return i.value()->functions.value(name)->evaluate(&ctx, argnames, argvalues);
+ return m.second->functions[name]->evaluate(&ctx, argnames, argvalues);
}
}
}
if (parent)
return parent->evaluate_function(name, argnames, argvalues);
- PRINTA("WARNING: Ignoring unkown function '%1'.", name);
+ PRINTF("WARNING: Ignoring unkown function '%s'.", name.c_str());
return Value();
}
AbstractNode *Context::evaluate_module(const ModuleInstantiation *inst) const
{
- if (modules_p && modules_p->contains(inst->modname))
- return modules_p->value(inst->modname)->evaluate(this, inst);
+ if (modules_p && modules_p->find(inst->modname) != modules_p->end())
+ return modules_p->find(inst->modname)->second->evaluate(this, inst);
if (usedlibs_p) {
- QHashIterator<QString, Module*> i(*usedlibs_p);
- while (i.hasNext()) {
- i.next();
- if (i.value()->modules.contains(inst->modname)) {
- Module *lib = i.value();
+ BOOST_FOREACH(const ModuleContainer::value_type &m, *usedlibs_p) {
+ if (m.second->modules.count(inst->modname)) {
+ Module *lib = m.second;
Context ctx(parent);
ctx.functions_p = &lib->functions;
ctx.modules_p = &lib->modules;
ctx.usedlibs_p = &lib->usedlibs;
- for (int j = 0; j < lib->assignments_var.size(); j++) {
+ for (size_t j = 0; j < lib->assignments_var.size(); j++) {
ctx.set_variable(lib->assignments_var[j], lib->assignments_expr[j]->evaluate(&ctx));
}
- return i.value()->modules.value(inst->modname)->evaluate(&ctx, inst);
+ return m.second->modules[inst->modname]->evaluate(&ctx, inst);
}
}
}
if (parent)
return parent->evaluate_module(inst);
- PRINTA("WARNING: Ignoring unkown module '%1'.", inst->modname);
+ PRINTF("WARNING: Ignoring unkown module '%s'.", inst->modname.c_str());
return NULL;
}
/*!
Returns the absolute path to the given filename, unless it's empty.
*/
-QString Context::get_absolute_path(const QString &filename) const
+std::string Context::get_absolute_path(const std::string &filename) const
{
- if (!filename.isEmpty()) {
- return QFileInfo(QDir(this->document_path), filename).absoluteFilePath();
+ if (!filename.empty()) {
+ return QFileInfo(QDir(QString::fromStdString(this->document_path)),
+ QString::fromStdString(filename)).absoluteFilePath().toStdString();
}
else {
return filename;
diff --git a/src/context.h b/src/context.h
index cbb1c4f..99726a9 100644
--- a/src/context.h
+++ b/src/context.h
@@ -1,38 +1,43 @@
#ifndef CONTEXT_H_
#define CONTEXT_H_
-#include <QHash>
-#include <QString>
+#include <string>
+#include <vector>
+#include <boost/unordered_map.hpp>
#include "value.h"
+using boost::unordered_map;
+
class Context
{
public:
const Context *parent;
- QHash<QString, Value> constants;
- QHash<QString, Value> variables;
- QHash<QString, Value> config_variables;
- const QHash<QString, class AbstractFunction*> *functions_p;
- const QHash<QString, class AbstractModule*> *modules_p;
- const QHash<QString, class Module*> *usedlibs_p;
+ typedef unordered_map<std::string, Value> ValueMap;
+ ValueMap constants;
+ ValueMap variables;
+ ValueMap config_variables;
+ const unordered_map<std::string, class AbstractFunction*> *functions_p;
+ const unordered_map<std::string, class AbstractModule*> *modules_p;
+ typedef unordered_map<std::string, class Module*> ModuleContainer;
+ const ModuleContainer *usedlibs_p;
const class ModuleInstantiation *inst_p;
- QString document_path;
+ std::string document_path;
- static QVector<const Context*> ctx_stack;
+ static std::vector<const Context*> ctx_stack;
Context(const Context *parent = NULL);
~Context();
- void args(const QVector<QString> &argnames, const QVector<class Expression*> &argexpr, const QVector<QString> &call_argnames, const QVector<Value> &call_argvalues);
+ void args(const std::vector<std::string> &argnames, const std::vector<class Expression*> &argexpr, const std::vector<std::string> &call_argnames, const std::vector<Value> &call_argvalues);
- void set_variable(QString name, Value value);
- Value lookup_variable(QString name, bool silent = false) const;
+ void set_variable(const std::string &name, Value value);
+ Value lookup_variable(const std::string &name, bool silent = false) const;
- void set_constant(QString name, Value value);
+ void set_constant(const std::string &name, Value value);
- QString get_absolute_path(const QString &filename) const;
+ std::string get_absolute_path(const std::string &filename) const;
- Value evaluate_function(QString name, const QVector<QString> &argnames, const QVector<Value> &argvalues) const;
+ Value evaluate_function(const std::string &name, const std::vector<std::string> &argnames, const std::vector<Value> &argvalues) const;
class AbstractNode *evaluate_module(const ModuleInstantiation *inst) const;
};
diff --git a/src/control.cc b/src/control.cc
index e1b816c..d2df4f5 100644
--- a/src/control.cc
+++ b/src/control.cc
@@ -47,10 +47,10 @@ public:
virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const;
};
-void for_eval(AbstractNode *node, int l, const QVector<QString> &call_argnames, const QVector<Value> &call_argvalues, const QVector<ModuleInstantiation*> arg_children, const Context *arg_context)
+void for_eval(AbstractNode *node, size_t l, const std::vector<std::string> &call_argnames, const std::vector<Value> &call_argvalues, const std::vector<ModuleInstantiation*> arg_children, const Context *arg_context)
{
if (call_argnames.size() > l) {
- QString it_name = call_argnames[l];
+ std::string it_name = call_argnames[l];
Value it_values = call_argvalues[l];
Context c(arg_context);
if (it_values.type == Value::RANGE) {
@@ -70,7 +70,7 @@ void for_eval(AbstractNode *node, int l, const QVector<QString> &call_argnames,
}
}
else if (it_values.type == Value::VECTOR) {
- for (int i = 0; i < it_values.vec.size(); i++) {
+ for (size_t i = 0; i < it_values.vec.size(); i++) {
c.set_variable(it_name, *it_values.vec[i]);
for_eval(node, l+1, call_argnames, call_argvalues, arg_children, &c);
}
@@ -91,7 +91,7 @@ AbstractNode *ControlModule::evaluate(const Context*, const ModuleInstantiation
{
if (type == CHILD)
{
- int n = 0;
+ size_t n = 0;
if (inst->argvalues.size() > 0) {
double v;
if (inst->argvalues[0].getnum(v))
@@ -122,8 +122,8 @@ AbstractNode *ControlModule::evaluate(const Context*, const ModuleInstantiation
for (int i = 0; i < inst->argnames.size(); i++) {
if (i > 0)
msg += QString(", ");
- if (!inst->argnames[i].isEmpty())
- msg += inst->argnames[i] + QString(" = ");
+ if (!inst->argnames[i].empty())
+ msg += QString::fromStdString(inst->argnames[i]) + QString(" = ");
msg += QString::fromStdString(inst->argvalues[i].toString());
}
PRINT(msg);
@@ -133,7 +133,7 @@ AbstractNode *ControlModule::evaluate(const Context*, const ModuleInstantiation
{
Context c(inst->ctx);
for (int i = 0; i < inst->argnames.size(); i++) {
- if (!inst->argnames[i].isEmpty())
+ if (!inst->argnames[i].empty())
c.set_variable(inst->argnames[i], inst->argvalues[i]);
}
foreach (ModuleInstantiation *v, inst->children) {
diff --git a/src/dxfdim.cc b/src/dxfdim.cc
index 666b53d..88e007c 100644
--- a/src/dxfdim.cc
+++ b/src/dxfdim.cc
@@ -33,48 +33,50 @@
#include "context.h"
#include "mathc99.h"
-#include <QHash>
#include <QDateTime>
#include <QFileInfo>
+#include <sstream>
-QHash<QString,Value> dxf_dim_cache;
-QHash<QString,Value> dxf_cross_cache;
+boost::unordered_map<std::string,Value> dxf_dim_cache;
+boost::unordered_map<std::string,Value> dxf_cross_cache;
-Value builtin_dxf_dim(const Context *ctx, const QVector<QString> &argnames, const QVector<Value> &args)
+Value builtin_dxf_dim(const Context *ctx, const std::vector<std::string> &argnames, const std::vector<Value> &args)
{
- QString filename;
- QString layername;
- QString name;
+ std::string filename;
+ std::string layername;
+ std::string name;
double xorigin = 0;
double yorigin = 0;
double scale = 1;
- for (int i = 0; i < argnames.count() && i < args.count(); i++) {
+ for (size_t i = 0; i < argnames.size() && i < args.size(); i++) {
if (argnames[i] == "file")
- filename = ctx->get_absolute_path(QString::fromStdString(args[i].text));
+ filename = ctx->get_absolute_path(args[i].text);
if (argnames[i] == "layer")
- layername = QString::fromStdString(args[i].text);
+ layername = args[i].text;
if (argnames[i] == "origin")
args[i].getv2(xorigin, yorigin);
if (argnames[i] == "scale")
args[i].getnum(scale);
if (argnames[i] == "name")
- name = QString::fromStdString(args[i].text);
+ name = args[i].text;
}
- QFileInfo fileInfo(filename);
+ QFileInfo fileInfo(QString::fromStdString(filename));
- QString key = filename + "|" + layername + "|" + name + "|" + QString::number(xorigin) + "|" + QString::number(yorigin) +
- "|" + QString::number(scale) + "|" + QString::number(fileInfo.lastModified().toTime_t()) + "|" + QString::number(fileInfo.size());
+ std::stringstream keystream;
+ keystream << filename << "|" << layername << "|" << name << "|" << xorigin
+ << "|" << yorigin <<"|" << scale << "|" << fileInfo.lastModified().toTime_t()
+ << "|" << fileInfo.size();
+ std::string key = keystream.str();
+ if (dxf_dim_cache.find(key) != dxf_dim_cache.end())
+ return dxf_dim_cache.find(key)->second;
- if (dxf_dim_cache.contains(key))
- return dxf_dim_cache[key];
-
- DxfData dxf(36, 0, 0, filename, layername, xorigin, yorigin, scale);
+ DxfData dxf(36, 0, 0, QString::fromStdString(filename), QString::fromStdString(layername), xorigin, yorigin, scale);
for (int i = 0; i < dxf.dims.count(); i++)
{
- if (!name.isNull() && dxf.dims[i].name != name)
+ if (!name.empty() && dxf.dims[i].name != QString::fromStdString(name))
continue;
DxfData::Dim *d = &dxf.dims[i];
@@ -114,43 +116,46 @@ Value builtin_dxf_dim(const Context *ctx, const QVector<QString> &argnames, cons
return dxf_dim_cache[key] = Value((d->type & 64) ? d->coords[3][0] : d->coords[3][1]);
}
- PRINTA("WARNING: Dimension `%1' in `%2', layer `%3' has unsupported type!", name, filename, layername);
+ PRINTF("WARNING: Dimension `%s' in `%s', layer `%s' has unsupported type!", name.c_str(), filename.c_str(), layername.c_str());
return Value();
}
- PRINTA("WARNING: Can't find dimension `%1' in `%2', layer `%3'!", name, filename, layername);
+ PRINTF("WARNING: Can't find dimension `%s' in `%s', layer `%s'!", name.c_str(), filename.c_str(), layername.c_str());
return Value();
}
-Value builtin_dxf_cross(const Context *ctx, const QVector<QString> &argnames, const QVector<Value> &args)
+Value builtin_dxf_cross(const Context *ctx, const std::vector<std::string> &argnames, const std::vector<Value> &args)
{
- QString filename;
- QString layername;
+ std::string filename;
+ std::string layername;
double xorigin = 0;
double yorigin = 0;
double scale = 1;
- for (int i = 0; i < argnames.count() && i < args.count(); i++) {
+ for (size_t i = 0; i < argnames.size() && i < args.size(); i++) {
if (argnames[i] == "file")
- filename = ctx->get_absolute_path(QString::fromStdString(args[i].text));
+ filename = ctx->get_absolute_path(args[i].text);
if (argnames[i] == "layer")
- layername = QString::fromStdString(args[i].text);
+ layername = args[i].text;
if (argnames[i] == "origin")
args[i].getv2(xorigin, yorigin);
if (argnames[i] == "scale")
args[i].getnum(scale);
}
- QFileInfo fileInfo(filename);
+ QFileInfo fileInfo(QString::fromStdString(filename));
- QString key = filename + "|" + layername + "|" + QString::number(xorigin) + "|" + QString::number(yorigin) +
- "|" + QString::number(scale) + "|" + QString::number(fileInfo.lastModified().toTime_t()) + "|" + QString::number(fileInfo.size());
+ std::stringstream keystream;
+ keystream << filename << "|" << layername << "|" << xorigin << "|" << yorigin
+ << "|" << scale << "|" << fileInfo.lastModified().toTime_t()
+ << "|" << fileInfo.size();
+ std::string key = keystream.str();
- if (dxf_cross_cache.contains(key))
- return dxf_cross_cache[key];
+ if (dxf_cross_cache.find(key) != dxf_cross_cache.end())
+ return dxf_cross_cache.find(key)->second;
- DxfData dxf(36, 0, 0, filename, layername, xorigin, yorigin, scale);
+ DxfData dxf(36, 0, 0, QString::fromStdString(filename), QString::fromStdString(layername), xorigin, yorigin, scale);
double coords[4][2];
@@ -182,7 +187,7 @@ Value builtin_dxf_cross(const Context *ctx, const QVector<QString> &argnames, co
}
}
- PRINTA("WARNING: Can't find cross in `%1', layer `%2'!", filename, layername);
+ PRINTF("WARNING: Can't find cross in `%s', layer `%s'!", filename.c_str(), layername.c_str());
return Value();
}
diff --git a/src/dxfdim.h b/src/dxfdim.h
index 9686760..bd42109 100644
--- a/src/dxfdim.h
+++ b/src/dxfdim.h
@@ -1,10 +1,10 @@
#ifndef DXFDIM_H_
#define DXFDIM_H_
-#include <QHash>
+#include <boost/unordered_map.hpp>
#include "value.h"
-extern QHash<QString,Value> dxf_cross_cache;
-extern QHash<QString,Value> dxf_dim_cache;
+extern boost::unordered_map<std::string,Value> dxf_dim_cache;
+extern boost::unordered_map<std::string,Value> dxf_cross_cache;
#endif
diff --git a/src/dxflinextrude.cc b/src/dxflinextrude.cc
index 4bae863..283c7f4 100644
--- a/src/dxflinextrude.cc
+++ b/src/dxflinextrude.cc
@@ -39,11 +39,9 @@
#include "openscad.h" // get_fragments_from_r()
#include <sstream>
+#include <boost/assign/std/vector.hpp>
+using namespace boost::assign; // bring 'operator+=()' into scope
-#include <QApplication>
-#include <QTime>
-#include <QProgressDialog>
-#include <QDateTime>
#include <QFileInfo>
class DxfLinearExtrudeModule : public AbstractModule
@@ -57,8 +55,9 @@ AbstractNode *DxfLinearExtrudeModule::evaluate(const Context *ctx, const ModuleI
{
DxfLinearExtrudeNode *node = new DxfLinearExtrudeNode(inst);
- QVector<QString> argnames = QVector<QString>() << "file" << "layer" << "height" << "origin" << "scale" << "center" << "twist" << "slices";
- QVector<Expression*> argexpr;
+ std::vector<std::string> argnames;
+ argnames += "file", "layer", "height", "origin", "scale", "center", "twist", "slices";
+ std::vector<Expression*> argexpr;
Context c(ctx);
c.args(argnames, argexpr, inst->argnames, inst->argvalues);
@@ -78,9 +77,9 @@ AbstractNode *DxfLinearExtrudeModule::evaluate(const Context *ctx, const ModuleI
Value slices = c.lookup_variable("slices", true);
if (!file.text.empty())
- node->filename = c.get_absolute_path(QString::fromStdString(file.text));
+ node->filename = c.get_absolute_path(file.text);
- node->layername = QString::fromStdString(layer.text);
+ node->layername = layer.text;
node->height = height.num;
node->convexity = (int)convexity.num;
origin.getv2(node->origin_x, node->origin_y);
@@ -109,7 +108,7 @@ AbstractNode *DxfLinearExtrudeModule::evaluate(const Context *ctx, const ModuleI
node->has_twist = true;
}
- if (node->filename.isEmpty()) {
+ if (node->filename.empty()) {
foreach (ModuleInstantiation *v, inst->children) {
AbstractNode *n = v->evaluate(inst->ctx);
if (n)
@@ -149,11 +148,9 @@ std::string DxfLinearExtrudeNode::toString() const
{
std::stringstream stream;
- QString text;
-
stream << this->name() << "("
"file = \"" << this->filename << "\", "
- "cache = \"" << QFileInfo(this->filename) << "\", "
+ "cache = \"" << QFileInfo(QString::fromStdString(this->filename)) << "\", "
"layer = \"" << this->layername << "\", "
"height = " << std::dec << this->height << ", "
"origin = [ " << this->origin_x << " " << this->origin_y << " ], "
diff --git a/src/dxflinextrudenode.h b/src/dxflinextrudenode.h
index 70e7a06..3c3beca 100644
--- a/src/dxflinextrudenode.h
+++ b/src/dxflinextrudenode.h
@@ -3,7 +3,6 @@
#include "node.h"
#include "visitor.h"
-#include <QString>
class DxfLinearExtrudeNode : public AbstractPolyNode
{
@@ -24,7 +23,7 @@ public:
double fn, fs, fa, height, twist;
double origin_x, origin_y, scale;
bool center, has_twist;
- QString filename, layername;
+ std::string filename, layername;
virtual PolySet *evaluate_polyset(render_mode_e mode, class PolySetEvaluator *) const;
};
diff --git a/src/dxfrotextrude.cc b/src/dxfrotextrude.cc
index 7fdcd41..b333fbf 100644
--- a/src/dxfrotextrude.cc
+++ b/src/dxfrotextrude.cc
@@ -37,11 +37,9 @@
#include "openscad.h" // get_fragments_from_r()
#include <sstream>
+#include <boost/assign/std/vector.hpp>
+using namespace boost::assign; // bring 'operator+=()' into scope
-#include <QTime>
-#include <QApplication>
-#include <QProgressDialog>
-#include <QDateTime>
#include <QFileInfo>
class DxfRotateExtrudeModule : public AbstractModule
@@ -55,8 +53,9 @@ AbstractNode *DxfRotateExtrudeModule::evaluate(const Context *ctx, const ModuleI
{
DxfRotateExtrudeNode *node = new DxfRotateExtrudeNode(inst);
- QVector<QString> argnames = QVector<QString>() << "file" << "layer" << "origin" << "scale";
- QVector<Expression*> argexpr;
+ std::vector<std::string> argnames;
+ argnames += "file", "layer", "origin", "scale";
+ std::vector<Expression*> argexpr;
Context c(ctx);
c.args(argnames, argexpr, inst->argnames, inst->argvalues);
@@ -72,9 +71,9 @@ AbstractNode *DxfRotateExtrudeModule::evaluate(const Context *ctx, const ModuleI
Value scale = c.lookup_variable("scale", true);
if (!file.text.empty())
- node->filename = c.get_absolute_path(QString::fromStdString(file.text));
+ node->filename = c.get_absolute_path(file.text);
- node->layername = QString::fromStdString(layer.text);
+ node->layername = layer.text;
node->convexity = (int)convexity.num;
origin.getv2(node->origin_x, node->origin_y);
node->scale = scale.num;
@@ -85,7 +84,7 @@ AbstractNode *DxfRotateExtrudeModule::evaluate(const Context *ctx, const ModuleI
if (node->scale <= 0)
node->scale = 1;
- if (node->filename.isEmpty()) {
+ if (node->filename.empty()) {
foreach (ModuleInstantiation *v, inst->children) {
AbstractNode *n = v->evaluate(inst->ctx);
if (n)
@@ -127,7 +126,7 @@ std::string DxfRotateExtrudeNode::toString() const
stream << this->name() << "("
"file = \"" << this->filename << "\", "
- "cache = \"" << QFileInfo(this->filename) << "\", "
+ "cache = \"" << QFileInfo(QString::fromStdString(this->filename)) << "\", "
"layer = \"" << this->layername << "\", "
"origin = [ " << std::dec << this->origin_x << " " << this->origin_y << " ], "
"scale = " << this->scale << ", "
diff --git a/src/dxfrotextrudenode.h b/src/dxfrotextrudenode.h
index aa22a73..797b53a 100644
--- a/src/dxfrotextrudenode.h
+++ b/src/dxfrotextrudenode.h
@@ -3,7 +3,6 @@
#include "node.h"
#include "visitor.h"
-#include <QString>
class DxfRotateExtrudeNode : public AbstractPolyNode
{
@@ -22,7 +21,7 @@ public:
int convexity;
double fn, fs, fa;
double origin_x, origin_y, scale;
- QString filename, layername;
+ std::string filename, layername;
virtual PolySet *evaluate_polyset(render_mode_e mode, class PolySetEvaluator *) const;
};
diff --git a/src/expr.cc b/src/expr.cc
index 72f92a0..8e482e8 100644
--- a/src/expr.cc
+++ b/src/expr.cc
@@ -29,59 +29,59 @@
#include "context.h"
#include <assert.h>
#include <sstream>
+#include <algorithm>
+#include "stl-utils.h"
Expression::Expression()
{
- const_value = NULL;
+ this->const_value = NULL;
}
Expression::~Expression()
{
- for (int i=0; i < children.size(); i++)
- delete children[i];
- if (const_value)
- delete const_value;
+ std::for_each(this->children.begin(), this->children.end(), del_fun<Expression>());
+ delete this->const_value;
}
Value Expression::evaluate(const Context *context) const
{
- if (type == "!")
- return ! children[0]->evaluate(context);
- if (type == "&&")
- return children[0]->evaluate(context) && children[1]->evaluate(context);
- if (type == "||")
- return children[0]->evaluate(context) || children[1]->evaluate(context);
- if (type == "*")
- return children[0]->evaluate(context) * children[1]->evaluate(context);
- if (type == "/")
- return children[0]->evaluate(context) / children[1]->evaluate(context);
- if (type == "%")
- return children[0]->evaluate(context) % children[1]->evaluate(context);
- if (type == "+")
- return children[0]->evaluate(context) + children[1]->evaluate(context);
- if (type == "-")
- return children[0]->evaluate(context) - children[1]->evaluate(context);
- if (type == "<")
- return children[0]->evaluate(context) < children[1]->evaluate(context);
- if (type == "<=")
- return children[0]->evaluate(context) <= children[1]->evaluate(context);
- if (type == "==")
- return children[0]->evaluate(context) == children[1]->evaluate(context);
- if (type == "!=")
- return children[0]->evaluate(context) != children[1]->evaluate(context);
- if (type == ">=")
- return children[0]->evaluate(context) >= children[1]->evaluate(context);
- if (type == ">")
- return children[0]->evaluate(context) > children[1]->evaluate(context);
- if (type == "?:") {
- Value v = children[0]->evaluate(context);
+ if (this->type == "!")
+ return ! this->children[0]->evaluate(context);
+ if (this->type == "&&")
+ return this->children[0]->evaluate(context) && this->children[1]->evaluate(context);
+ if (this->type == "||")
+ return this->children[0]->evaluate(context) || this->children[1]->evaluate(context);
+ if (this->type == "*")
+ return this->children[0]->evaluate(context) * this->children[1]->evaluate(context);
+ if (this->type == "/")
+ return this->children[0]->evaluate(context) / this->children[1]->evaluate(context);
+ if (this->type == "%")
+ return this->children[0]->evaluate(context) % this->children[1]->evaluate(context);
+ if (this->type == "+")
+ return this->children[0]->evaluate(context) + this->children[1]->evaluate(context);
+ if (this->type == "-")
+ return this->children[0]->evaluate(context) - this->children[1]->evaluate(context);
+ if (this->type == "<")
+ return this->children[0]->evaluate(context) < this->children[1]->evaluate(context);
+ if (this->type == "<=")
+ return this->children[0]->evaluate(context) <= this->children[1]->evaluate(context);
+ if (this->type == "==")
+ return this->children[0]->evaluate(context) == this->children[1]->evaluate(context);
+ if (this->type == "!=")
+ return this->children[0]->evaluate(context) != this->children[1]->evaluate(context);
+ if (this->type == ">=")
+ return this->children[0]->evaluate(context) >= this->children[1]->evaluate(context);
+ if (this->type == ">")
+ return this->children[0]->evaluate(context) > this->children[1]->evaluate(context);
+ if (this->type == "?:") {
+ Value v = this->children[0]->evaluate(context);
if (v.type == Value::BOOL)
- return children[v.b ? 1 : 2]->evaluate(context);
+ return this->children[v.b ? 1 : 2]->evaluate(context);
return Value();
}
- if (type == "[]") {
- Value v1 = children[0]->evaluate(context);
- Value v2 = children[1]->evaluate(context);
+ if (this->type == "[]") {
+ Value v1 = this->children[0]->evaluate(context);
+ Value v2 = this->children[1]->evaluate(context);
if (v1.type == Value::VECTOR && v2.type == Value::NUMBER) {
int i = (int)(v2.num);
if (i >= 0 && i < v1.vec.size())
@@ -89,14 +89,14 @@ Value Expression::evaluate(const Context *context) const
}
return Value();
}
- if (type == "I")
- return children[0]->evaluate(context).inv();
- if (type == "C")
- return *const_value;
- if (type == "R") {
- Value v1 = children[0]->evaluate(context);
- Value v2 = children[1]->evaluate(context);
- Value v3 = children[2]->evaluate(context);
+ if (this->type == "I")
+ return this->children[0]->evaluate(context).inv();
+ if (this->type == "C")
+ return *this->const_value;
+ if (this->type == "R") {
+ Value v1 = this->children[0]->evaluate(context);
+ Value v2 = this->children[1]->evaluate(context);
+ Value v3 = this->children[2]->evaluate(context);
if (v1.type == Value::NUMBER && v2.type == Value::NUMBER && v3.type == Value::NUMBER) {
Value r = Value();
r.type = Value::RANGE;
@@ -107,40 +107,40 @@ Value Expression::evaluate(const Context *context) const
}
return Value();
}
- if (type == "V") {
+ if (this->type == "V") {
Value v;
v.type = Value::VECTOR;
- for (int i = 0; i < children.size(); i++)
- v.append(new Value(children[i]->evaluate(context)));
+ for (int i = 0; i < this->children.size(); i++)
+ v.append(new Value(this->children[i]->evaluate(context)));
return v;
}
- if (type == "L")
- return context->lookup_variable(var_name);
- if (type == "N")
+ if (this->type == "L")
+ return context->lookup_variable(this->var_name);
+ if (this->type == "N")
{
- Value v = children[0]->evaluate(context);
+ Value v = this->children[0]->evaluate(context);
- if (v.type == Value::VECTOR && var_name == QString("x"))
+ if (v.type == Value::VECTOR && this->var_name == "x")
return *v.vec[0];
- if (v.type == Value::VECTOR && var_name == QString("y"))
+ if (v.type == Value::VECTOR && this->var_name == "y")
return *v.vec[1];
- if (v.type == Value::VECTOR && var_name == QString("z"))
+ if (v.type == Value::VECTOR && this->var_name == "z")
return *v.vec[2];
- if (v.type == Value::RANGE && var_name == QString("begin"))
+ if (v.type == Value::RANGE && this->var_name == "begin")
return Value(v.range_begin);
- if (v.type == Value::RANGE && var_name == QString("step"))
+ if (v.type == Value::RANGE && this->var_name == "step")
return Value(v.range_step);
- if (v.type == Value::RANGE && var_name == QString("end"))
+ if (v.type == Value::RANGE && this->var_name == "end")
return Value(v.range_end);
return Value();
}
- if (type == "F") {
- QVector<Value> argvalues;
- for (int i=0; i < children.size(); i++)
- argvalues.append(children[i]->evaluate(context));
- return context->evaluate_function(call_funcname, call_argnames, argvalues);
+ if (this->type == "F") {
+ std::vector<Value> argvalues;
+ for (int i=0; i < this->children.size(); i++)
+ argvalues.push_back(this->children[i]->evaluate(context));
+ return context->evaluate_function(this->call_funcname, this->call_argnames, argvalues);
}
abort();
}
@@ -152,43 +152,43 @@ std::string Expression::toString() const
if (this->type == "*" || this->type == "/" || this->type == "%" || this->type == "+" ||
this->type == "-" || this->type == "<" || this->type == "<=" || this->type == "==" ||
this->type == "!=" || this->type == ">=" || this->type == ">") {
- stream << "(" << *children[0] << " " << this->type << " " << *children[1] << ")";
+ stream << "(" << *this->children[0] << " " << this->type << " " << *this->children[1] << ")";
}
else if (this->type == "?:") {
- stream << "(" << *children[0] << " ? " << this->type << " : " << *children[1] << ")";
+ stream << "(" << *this->children[0] << " ? " << this->type << " : " << *this->children[1] << ")";
}
else if (this->type == "[]") {
- stream << "(" << *children[0] << "[" << *children[1] << "])";
+ stream << "(" << *this->children[0] << "[" << *this->children[1] << "])";
}
else if (this->type == "I") {
- stream << "(-" << *children[0] << ")";
+ stream << "(-" << *this->children[0] << ")";
}
else if (this->type == "C") {
- stream << *const_value;
+ stream << *this->const_value;
}
else if (this->type == "R") {
- stream << "[" << *children[0] << " : " << *children[1] << " : " << children[2] << "]";
+ stream << "[" << *this->children[0] << " : " << *this->children[1] << " : " << this->children[2] << "]";
}
else if (this->type == "V") {
stream << "[";
- for (int i=0; i < children.size(); i++) {
+ for (int i=0; i < this->children.size(); i++) {
if (i > 0) stream << ", ";
- stream << *children[i];
+ stream << *this->children[i];
}
stream << "]";
}
else if (this->type == "L") {
- stream << var_name;
+ stream << this->var_name;
}
else if (this->type == "N") {
- stream << "(" << *children[0] << "." << var_name << ")";
+ stream << "(" << *this->children[0] << "." << this->var_name << ")";
}
else if (this->type == "F") {
- stream << call_funcname << "(";
- for (int i=0; i < children.size(); i++) {
+ stream << this->call_funcname << "(";
+ for (int i=0; i < this->children.size(); i++) {
if (i > 0) stream << ", ";
- if (!call_argnames[i].isEmpty()) stream << call_argnames[i] << " = ";
- stream << *children[i];
+ if (!this->call_argnames[i].empty()) stream << this->call_argnames[i] << " = ";
+ stream << *this->children[i];
}
stream << ")";
}
diff --git a/src/expression.h b/src/expression.h
index 38043db..acbd6aa 100644
--- a/src/expression.h
+++ b/src/expression.h
@@ -1,19 +1,19 @@
#ifndef EXPRESSION_H_
#define EXPRESSION_H_
-#include <QVector>
-#include <QString>
+#include <string>
+#include <vector>
class Expression
{
public:
- QVector<Expression*> children;
+ std::vector<Expression*> children;
class Value *const_value;
- QString var_name;
+ std::string var_name;
- QString call_funcname;
- QVector<QString> call_argnames;
+ std::string call_funcname;
+ std::vector<std::string> call_argnames;
// Boolean: ! && ||
// Operators: * / % + -
@@ -28,7 +28,7 @@ public:
// Lookup Variable: L
// Lookup member per name: N
// Function call: F
- QString type;
+ std::string type;
Expression();
~Expression();
diff --git a/src/func.cc b/src/func.cc
index c10963c..31c8ad2 100644
--- a/src/func.cc
+++ b/src/func.cc
@@ -32,29 +32,33 @@
#include <sstream>
#include <ctime>
#include "mathc99.h"
+#include <algorithm>
+#include "stl-utils.h"
+#include <boost/foreach.hpp>
AbstractFunction::~AbstractFunction()
{
}
-Value AbstractFunction::evaluate(const Context*, const QVector<QString>&, const QVector<Value>&) const
+Value AbstractFunction::evaluate(const Context*, const std::vector<std::string>&, const std::vector<Value>&) const
{
return Value();
}
-QString AbstractFunction::dump(QString indent, QString name) const
+std::string AbstractFunction::dump(const std::string &indent, const std::string &name) const
{
- return QString("%1abstract function %2();\n").arg(indent, name);
+ std::stringstream dump;
+ dump << indent << "abstract function " << name << "();\n";
+ return dump.str();
}
Function::~Function()
{
- for (int i=0; i < argexpr.size(); i++)
- delete argexpr[i];
+ std::for_each(this->argexpr.begin(), this->argexpr.end(), del_fun<Expression>());
delete expr;
}
-Value Function::evaluate(const Context *ctx, const QVector<QString> &call_argnames, const QVector<Value> &call_argvalues) const
+Value Function::evaluate(const Context *ctx, const std::vector<std::string> &call_argnames, const std::vector<Value> &call_argvalues) const
{
Context c(ctx);
c.args(argnames, argexpr, call_argnames, call_argvalues);
@@ -63,34 +67,36 @@ Value Function::evaluate(const Context *ctx, const QVector<QString> &call_argnam
return Value();
}
-QString Function::dump(QString indent, QString name) const
+std::string Function::dump(const std::string &indent, const std::string &name) const
{
- QString text = QString("%1function %2(").arg(indent, name);
- for (int i=0; i < argnames.size(); i++) {
- if (i > 0)
- text += QString(", ");
- text += argnames[i];
- if (argexpr[i])
- text += QString(" = ") + QString::fromStdString(argexpr[i]->toString());
+ std::stringstream dump;
+ dump << indent << "function " << name << "(";
+ for (size_t i=0; i < argnames.size(); i++) {
+ if (i > 0) dump << ", ";
+ dump << argnames[i];
+ if (argexpr[i]) dump << " = " << *argexpr[i];
}
- text += QString(") = %1;\n").arg(QString::fromStdString(expr->toString()));
- return text;
+ dump << ") = " << *expr << ";\n";
+ return dump.str();
}
-QHash<QString, AbstractFunction*> builtin_functions;
+typedef boost::unordered_map<std::string, AbstractFunction*> BuiltinContainer;
+BuiltinContainer builtin_functions;
BuiltinFunction::~BuiltinFunction()
{
}
-Value BuiltinFunction::evaluate(const Context *ctx, const QVector<QString> &call_argnames, const QVector<Value> &call_argvalues) const
+Value BuiltinFunction::evaluate(const Context *ctx, const std::vector<std::string> &call_argnames, const std::vector<Value> &call_argvalues) const
{
return eval_func(ctx, call_argnames, call_argvalues);
}
-QString BuiltinFunction::dump(QString indent, QString name) const
+std::string BuiltinFunction::dump(const std::string &indent, const std::string &name) const
{
- return QString("%1builtin function %2();\n").arg(indent, name);
+ std::stringstream dump;
+ dump << indent << "builtin function " << name << "();\n";
+ return dump.str();
}
static double deg2rad(double x)
@@ -113,14 +119,14 @@ static double rad2deg(double x)
return x;
}
-Value builtin_abs(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_abs(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() == 1 && args[0].type == Value::NUMBER)
return Value(fabs(args[0].num));
return Value();
}
-Value builtin_sign(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_sign(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() == 1 && args[0].type == Value::NUMBER)
return Value((args[0].num<0) ? -1.0 : ((args[0].num>0) ? 1.0 : 0.0));
@@ -137,7 +143,7 @@ double frand(double min, double max)
return (min>max) ? frand()*(min-max)+max : frand()*(max-min)+min;
}
-Value builtin_rands(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_rands(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() == 3 &&
args[0].type == Value::NUMBER &&
@@ -172,11 +178,11 @@ Value builtin_rands(const Context *, const QVector<QString>&, const QVector<Valu
}
-Value builtin_min(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_min(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() >= 1 && args[0].type == Value::NUMBER) {
double val = args[0].num;
- for (int i = 1; i < args.size(); i++)
+ for (size_t i = 1; i < args.size(); i++)
if (args[1].type == Value::NUMBER)
val = fmin(val, args[i].num);
return Value(val);
@@ -184,11 +190,11 @@ Value builtin_min(const Context *, const QVector<QString>&, const QVector<Value>
return Value();
}
-Value builtin_max(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_max(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() >= 1 && args[0].type == Value::NUMBER) {
double val = args[0].num;
- for (int i = 1; i < args.size(); i++)
+ for (size_t i = 1; i < args.size(); i++)
if (args[1].type == Value::NUMBER)
val = fmax(val, args[i].num);
return Value(val);
@@ -196,98 +202,98 @@ Value builtin_max(const Context *, const QVector<QString>&, const QVector<Value>
return Value();
}
-Value builtin_sin(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_sin(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() == 1 && args[0].type == Value::NUMBER)
return Value(sin(deg2rad(args[0].num)));
return Value();
}
-Value builtin_cos(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_cos(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() == 1 && args[0].type == Value::NUMBER)
return Value(cos(deg2rad(args[0].num)));
return Value();
}
-Value builtin_asin(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_asin(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() == 1 && args[0].type == Value::NUMBER)
return Value(rad2deg(asin(args[0].num)));
return Value();
}
-Value builtin_acos(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_acos(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() == 1 && args[0].type == Value::NUMBER)
return Value(rad2deg(acos(args[0].num)));
return Value();
}
-Value builtin_tan(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_tan(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() == 1 && args[0].type == Value::NUMBER)
return Value(tan(deg2rad(args[0].num)));
return Value();
}
-Value builtin_atan(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_atan(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() == 1 && args[0].type == Value::NUMBER)
return Value(rad2deg(atan(args[0].num)));
return Value();
}
-Value builtin_atan2(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_atan2(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() == 2 && args[0].type == Value::NUMBER && args[1].type == Value::NUMBER)
return Value(rad2deg(atan2(args[0].num, args[1].num)));
return Value();
}
-Value builtin_pow(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_pow(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() == 2 && args[0].type == Value::NUMBER && args[1].type == Value::NUMBER)
return Value(pow(args[0].num, args[1].num));
return Value();
}
-Value builtin_round(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_round(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() == 1 && args[0].type == Value::NUMBER)
return Value(round(args[0].num));
return Value();
}
-Value builtin_ceil(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_ceil(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() == 1 && args[0].type == Value::NUMBER)
return Value(ceil(args[0].num));
return Value();
}
-Value builtin_floor(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_floor(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() == 1 && args[0].type == Value::NUMBER)
return Value(floor(args[0].num));
return Value();
}
-Value builtin_sqrt(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_sqrt(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() == 1 && args[0].type == Value::NUMBER)
return Value(sqrt(args[0].num));
return Value();
}
-Value builtin_exp(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_exp(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() == 1 && args[0].type == Value::NUMBER)
return Value(exp(args[0].num));
return Value();
}
-Value builtin_log(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_log(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() == 2 && args[0].type == Value::NUMBER && args[1].type == Value::NUMBER)
return Value(log(args[1].num) / log(args[0].num));
@@ -296,31 +302,31 @@ Value builtin_log(const Context *, const QVector<QString>&, const QVector<Value>
return Value();
}
-Value builtin_ln(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_ln(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
if (args.size() == 1 && args[0].type == Value::NUMBER)
return Value(log(args[0].num));
return Value();
}
-Value builtin_str(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_str(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
std::stringstream stream;
- for (int i = 0; i < args.size(); i++) {
+ for (size_t i = 0; i < args.size(); i++) {
stream << args[i];
}
return Value(stream.str());
}
-Value builtin_lookup(const Context *, const QVector<QString>&, const QVector<Value> &args)
+Value builtin_lookup(const Context *, const std::vector<std::string>&, const std::vector<Value> &args)
{
double p, low_p, low_v, high_p, high_v;
if (args.size() < 2 || !args[0].getnum(p) || args[1].vec.size() < 2 || args[1].vec[0]->vec.size() < 2)
return Value();
if (!args[1].vec[0]->getv2(low_p, low_v) || !args[1].vec[0]->getv2(high_p, high_v))
return Value();
- for (int i = 1; i < args[1].vec.size(); i++) {
+ for (size_t i = 1; i < args[1].vec.size(); i++) {
double this_p, this_v;
if (args[1].vec[i]->getv2(this_p, this_v)) {
if (this_p <= p && (this_p > low_p || low_p > p)) {
@@ -370,8 +376,7 @@ void initialize_builtin_functions()
void destroy_builtin_functions()
{
- foreach (AbstractFunction *v, builtin_functions)
- delete v;
+ BOOST_FOREACH(BuiltinContainer::value_type &f, builtin_functions) delete f.second;
+//std::for_each(builtin_functions.begin(), builtin_functions.end(), del_fun<AbstractFunction>());
builtin_functions.clear();
}
-
diff --git a/src/function.h b/src/function.h
index 7b58e38..623ef7e 100644
--- a/src/function.h
+++ b/src/function.h
@@ -2,43 +2,43 @@
#define FUNCTION_H_
#include "value.h"
-#include <QString>
-#include <QVector>
+#include <string>
+#include <vector>
class AbstractFunction
{
public:
virtual ~AbstractFunction();
- virtual Value evaluate(const class Context *ctx, const QVector<QString> &call_argnames, const QVector<Value> &call_argvalues) const;
- virtual QString dump(QString indent, QString name) const;
+ virtual Value evaluate(const class Context *ctx, const std::vector<std::string> &call_argnames, const std::vector<Value> &call_argvalues) const;
+ virtual std::string dump(const std::string &indent, const std::string &name) const;
};
class BuiltinFunction : public AbstractFunction
{
public:
- typedef Value (*eval_func_t)(const Context *ctx, const QVector<QString> &argnames, const QVector<Value> &args);
+ typedef Value (*eval_func_t)(const Context *ctx, const std::vector<std::string> &argnames, const std::vector<Value> &args);
eval_func_t eval_func;
BuiltinFunction(eval_func_t f) : eval_func(f) { }
virtual ~BuiltinFunction();
- virtual Value evaluate(const Context *ctx, const QVector<QString> &call_argnames, const QVector<Value> &call_argvalues) const;
- virtual QString dump(QString indent, QString name) const;
+ virtual Value evaluate(const Context *ctx, const std::vector<std::string> &call_argnames, const std::vector<Value> &call_argvalues) const;
+ virtual std::string dump(const std::string &indent, const std::string &name) const;
};
class Function : public AbstractFunction
{
public:
- QVector<QString> argnames;
- QVector<class Expression*> argexpr;
+ std::vector<std::string> argnames;
+ std::vector<class Expression*> argexpr;
Expression *expr;
Function() { }
virtual ~Function();
- virtual Value evaluate(const Context *ctx, const QVector<QString> &call_argnames, const QVector<Value> &call_argvalues) const;
- virtual QString dump(QString indent, QString name) const;
+ virtual Value evaluate(const Context *ctx, const std::vector<std::string> &call_argnames, const std::vector<Value> &call_argvalues) const;
+ virtual std::string dump(const std::string &indent, const std::string &name) const;
};
#endif
diff --git a/src/import.cc b/src/import.cc
index 737ab31..b26d05d 100644
--- a/src/import.cc
+++ b/src/import.cc
@@ -42,6 +42,8 @@
#include <sys/stat.h>
#include <sstream>
#include <assert.h>
+#include <boost/assign/std/vector.hpp>
+using namespace boost::assign; // bring 'operator+=()' into scope
class ImportModule : public AbstractModule
{
@@ -55,17 +57,17 @@ AbstractNode *ImportModule::evaluate(const Context *ctx, const ModuleInstantiati
{
ImportNode *node = new ImportNode(inst, type);
- QVector<QString> argnames;
+ std::vector<std::string> argnames;
if (this->type == TYPE_DXF) {
- argnames = QVector<QString>() << "file" << "layer" << "convexity" << "origin" << "scale";
+ argnames += "file", "layer", "convexity", "origin", "scale";
} else {
- argnames = QVector<QString>() << "file" << "convexity";
+ argnames += "file", "convexity";
}
- QVector<Expression*> argexpr;
+ std::vector<Expression*> argexpr;
// Map old argnames to new argnames for compatibility
- QVector<QString> inst_argnames = inst->argnames;
- for (int i=0; i<inst_argnames.size(); i++) {
+ std::vector<std::string> inst_argnames = inst->argnames;
+ for (size_t i=0; i<inst_argnames.size(); i++) {
if (inst_argnames[i] == "filename")
inst_argnames[i] = "file";
if (inst_argnames[i] == "layername")
@@ -80,9 +82,9 @@ AbstractNode *ImportModule::evaluate(const Context *ctx, const ModuleInstantiati
node->fa = c.lookup_variable("$fa").num;
Value v = c.lookup_variable("file");
- node->filename = c.get_absolute_path(QString::fromStdString(v.text));
-// node->filename = c.get_absolute_path(QString::fromStdString(c.lookup_variable("file").text));
- node->layername = QString::fromStdString(c.lookup_variable("layer", true).text);
+ node->filename = c.get_absolute_path(v.text);
+// node->filename = c.get_absolute_path(c.lookup_variable("file").text);
+ node->layername = c.lookup_variable("layer", true).text;
node->convexity = c.lookup_variable("convexity", true).num;
if (node->convexity <= 0)
@@ -114,10 +116,10 @@ PolySet *ImportNode::evaluate_polyset(render_mode_e, class PolySetEvaluator *) c
if (this->type == TYPE_STL)
{
- handle_dep(this->filename);
- QFile f(this->filename);
+ handle_dep(QString::fromStdString(this->filename));
+ QFile f(QString::fromStdString(this->filename));
if (!f.open(QIODevice::ReadOnly)) {
- PRINTF("WARNING: Can't open import file `%s'.", this->filename.toAscii().data());
+ PRINTF("WARNING: Can't open import file `%s'.", this->filename.c_str());
return p;
}
@@ -196,7 +198,7 @@ PolySet *ImportNode::evaluate_polyset(render_mode_e, class PolySetEvaluator *) c
if (this->type == TYPE_DXF)
{
- DxfData dd(this->fn, this->fs, this->fa, this->filename, this->layername, this->origin_x, this->origin_y, this->scale);
+ DxfData dd(this->fn, this->fs, this->fa, QString::fromStdString(this->filename), QString::fromStdString(this->layername), this->origin_x, this->origin_y, this->scale);
p->is2d = true;
dxf_tesselate(p, dd, 0, true, false, 0);
dxf_border_to_ps(p, &dd);
@@ -212,7 +214,7 @@ std::string ImportNode::toString() const
QString text;
struct stat st;
memset(&st, 0, sizeof(struct stat));
- stat(this->filename.toAscii().data(), &st);
+ stat(this->filename.c_str(), &st);
stream << this->name();
switch (this->type) {
diff --git a/src/importnode.h b/src/importnode.h
index 94417b9..3fcdb37 100644
--- a/src/importnode.h
+++ b/src/importnode.h
@@ -3,7 +3,6 @@
#include "node.h"
#include "visitor.h"
-#include <QString>
enum import_type_e {
TYPE_STL,
@@ -22,8 +21,8 @@ public:
virtual std::string name() const;
import_type_e type;
- QString filename;
- QString layername;
+ std::string filename;
+ std::string layername;
int convexity;
double fn, fs, fa;
double origin_x, origin_y, scale;
diff --git a/src/mainwin.cc b/src/mainwin.cc
index a2c845d..c82f5f1 100644
--- a/src/mainwin.cc
+++ b/src/mainwin.cc
@@ -495,7 +495,7 @@ MainWindow::setFileName(const QString &filename)
{
if (filename.isEmpty()) {
this->fileName.clear();
- this->root_ctx.document_path = currentdir;
+ this->root_ctx.document_path = currentdir.toStdString();
setWindowTitle("OpenSCAD - New Document[*]");
}
else {
@@ -518,7 +518,7 @@ MainWindow::setFileName(const QString &filename)
this->fileName = fileinfo.fileName();
}
- this->root_ctx.document_path = fileinfo.dir().absolutePath();
+ this->root_ctx.document_path = fileinfo.dir().absolutePath().toStdString();
QDir::setCurrent(fileinfo.dir().absolutePath());
}
@@ -1310,7 +1310,7 @@ void MainWindow::actionDisplayAST()
e->setWindowTitle("AST Dump");
e->setReadOnly(true);
if (root_module) {
- e->setPlainText(root_module->dump("", ""));
+ e->setPlainText(QString::fromStdString(root_module->dump("", "")));
} else {
e->setPlainText("No AST to dump. Please try compiling first...");
}
diff --git a/src/module.cc b/src/module.cc
index 0f1b1aa..49a5f1b 100644
--- a/src/module.cc
+++ b/src/module.cc
@@ -31,6 +31,8 @@
#include "function.h"
#include "builtin.h"
#include "printutils.h"
+#include <boost/foreach.hpp>
+#include <sstream>
AbstractModule::~AbstractModule()
{
@@ -49,9 +51,11 @@ AbstractNode *AbstractModule::evaluate(const Context*, const ModuleInstantiation
return node;
}
-QString AbstractModule::dump(QString indent, QString name) const
+std::string AbstractModule::dump(const std::string &indent, const std::string &name) const
{
- return QString("%1abstract module %2();\n").arg(indent, name);
+ std::stringstream dump;
+ dump << indent << "abstract module " << name << "();\n";
+ return dump.str();
}
ModuleInstantiation::~ModuleInstantiation()
@@ -68,44 +72,42 @@ IfElseModuleInstantiation::~IfElseModuleInstantiation()
delete v;
}
-QString ModuleInstantiation::dump(QString indent) const
+std::string ModuleInstantiation::dump(const std::string &indent) const
{
- QString text = indent;
- if (!label.isEmpty())
- text += label + QString(": ");
- text += modname + QString("(");
- for (int i=0; i < argnames.size(); i++) {
- if (i > 0)
- text += QString(", ");
- if (!argnames[i].isEmpty())
- text += argnames[i] + QString(" = ");
- text += QString::fromStdString(argexpr[i]->toString());
+ std::stringstream dump;
+ dump << indent;
+ if (!label.empty()) dump << label <<": ";
+ dump << modname + "(";
+ for (size_t i=0; i < argnames.size(); i++) {
+ if (i > 0) dump << ", ";
+ if (!argnames[i].empty()) dump << argnames[i] << " = ";
+ dump << *argexpr[i];
}
if (children.size() == 0) {
- text += QString(");\n");
+ dump << ");\n";
} else if (children.size() == 1) {
- text += QString(")\n");
- text += children[0]->dump(indent + QString("\t"));
+ dump << ")\n";
+ dump << children[0]->dump(indent + "\t");
} else {
- text += QString(") {\n");
- for (int i = 0; i < children.size(); i++) {
- text += children[i]->dump(indent + QString("\t"));
+ dump << ") {\n";
+ for (size_t i = 0; i < children.size(); i++) {
+ dump << children[i]->dump(indent + "\t");
}
- text += QString("%1}\n").arg(indent);
+ dump << indent << "}\n";
}
- return text;
+ return dump.str();
}
AbstractNode *ModuleInstantiation::evaluate(const Context *ctx) const
{
AbstractNode *node = NULL;
if (this->ctx) {
- PRINTA("WARNING: Ignoring recursive module instanciation of '%1'.", modname);
+ PRINTF("WARNING: Ignoring recursive module instanciation of '%s'.", modname.c_str());
} else {
ModuleInstantiation *that = (ModuleInstantiation*)this;
that->argvalues.clear();
foreach (Expression *v, that->argexpr) {
- that->argvalues.append(v->evaluate(ctx));
+ that->argvalues.push_back(v->evaluate(ctx));
}
that->ctx = ctx;
node = ctx->evaluate_module(this);
@@ -119,10 +121,12 @@ Module::~Module()
{
foreach (Expression *v, assignments_expr)
delete v;
- foreach (AbstractFunction *v, functions)
- delete v;
- foreach (AbstractModule *v, modules)
- delete v;
+ BOOST_FOREACH(FunctionContainer::value_type &f, functions) {
+ delete f.second;
+ }
+ BOOST_FOREACH(AbstractModuleContainer::value_type &m, modules) {
+ delete m.second;
+ }
foreach (ModuleInstantiation *v, children)
delete v;
}
@@ -143,12 +147,12 @@ AbstractNode *Module::evaluate(const Context *ctx, const ModuleInstantiation *in
else
c.usedlibs_p = NULL;
- for (int i = 0; i < assignments_var.size(); i++) {
+ for (size_t i = 0; i < assignments_var.size(); i++) {
c.set_variable(assignments_var[i], assignments_expr[i]->evaluate(&c));
}
AbstractNode *node = new AbstractNode(inst);
- for (int i = 0; i < children.size(); i++) {
+ for (size_t i = 0; i < children.size(); i++) {
AbstractNode *n = children[i]->evaluate(&c);
if (n != NULL)
node->children.push_back(n);
@@ -157,48 +161,39 @@ AbstractNode *Module::evaluate(const Context *ctx, const ModuleInstantiation *in
return node;
}
-QString Module::dump(QString indent, QString name) const
+std::string Module::dump(const std::string &indent, const std::string &name) const
{
- QString text, tab;
- if (!name.isEmpty()) {
- text = QString("%1module %2(").arg(indent, name);
- for (int i=0; i < argnames.size(); i++) {
- if (i > 0)
- text += QString(", ");
- text += argnames[i];
- if (argexpr[i])
- text += QString(" = ") + QString::fromStdString(argexpr[i]->toString());
+ std::stringstream dump;
+ std::string tab;
+ if (!name.empty()) {
+ dump << indent << "module " << name << "(";
+ for (size_t i=0; i < argnames.size(); i++) {
+ if (i > 0) dump << ", ";
+ dump << argnames[i];
+ if (argexpr[i]) dump << " = " << *argexpr[i];
}
- text += QString(") {\n");
+ dump << ") {\n";
tab = "\t";
}
- {
- QHashIterator<QString, AbstractFunction*> i(functions);
- while (i.hasNext()) {
- i.next();
- text += i.value()->dump(indent + tab, i.key());
- }
+ BOOST_FOREACH(const FunctionContainer::value_type &f, functions) {
+ dump << f.second->dump(indent + tab, f.first);
}
- {
- QHashIterator<QString, AbstractModule*> i(modules);
- while (i.hasNext()) {
- i.next();
- text += i.value()->dump(indent + tab, i.key());
- }
+ BOOST_FOREACH(const AbstractModuleContainer::value_type &m, modules) {
+ dump << m.second->dump(indent + tab, m.first);
}
- for (int i = 0; i < assignments_var.size(); i++) {
- text += QString("%1%2 = %3;\n").arg(indent + tab, assignments_var[i], QString::fromStdString(assignments_expr[i]->toString()));
+ for (size_t i = 0; i < assignments_var.size(); i++) {
+ dump << indent << tab << assignments_var[i] << " = " << *assignments_expr[i] << ";\n";
}
- for (int i = 0; i < children.size(); i++) {
- text += children[i]->dump(indent + tab);
+ for (size_t i = 0; i < children.size(); i++) {
+ dump << children[i]->dump(indent + tab);
}
- if (!name.isEmpty()) {
- text += QString("%1}\n").arg(indent);
+ if (!name.empty()) {
+ dump << indent << "}\n";
}
- return text;
+ return dump.str();
}
-QHash<QString, AbstractModule*> builtin_modules;
+Module::AbstractModuleContainer builtin_modules;
void initialize_builtin_modules()
{
@@ -220,7 +215,8 @@ void initialize_builtin_modules()
void destroy_builtin_modules()
{
- foreach (AbstractModule *v, builtin_modules)
- delete v;
+ BOOST_FOREACH(Module::AbstractModuleContainer::value_type &m, builtin_modules) {
+ delete m.second;
+ }
builtin_modules.clear();
}
diff --git a/src/module.h b/src/module.h
index b680ea1..5262bfc 100644
--- a/src/module.h
+++ b/src/module.h
@@ -1,20 +1,20 @@
#ifndef MODULE_H_
#define MODULE_H_
-#include <QString>
-#include <QVector>
-#include <QHash>
+#include <string>
+#include <vector>
+#include <boost/unordered_map.hpp>
#include "value.h"
class ModuleInstantiation
{
public:
- QString label;
- QString modname;
- QVector<QString> argnames;
- QVector<class Expression*> argexpr;
- QVector<Value> argvalues;
- QVector<ModuleInstantiation*> children;
+ std::string label;
+ std::string modname;
+ std::vector<std::string> argnames;
+ std::vector<class Expression*> argexpr;
+ std::vector<Value> argvalues;
+ std::vector<ModuleInstantiation*> children;
bool tag_root;
bool tag_highlight;
@@ -24,7 +24,7 @@ public:
ModuleInstantiation() : tag_root(false), tag_highlight(false), tag_background(false), ctx(NULL) { }
virtual ~ModuleInstantiation();
- QString dump(QString indent) const;
+ std::string dump(const std::string &indent) const;
class AbstractNode *evaluate(const Context *ctx) const;
};
@@ -32,7 +32,7 @@ class IfElseModuleInstantiation : public ModuleInstantiation {
public:
virtual ~IfElseModuleInstantiation();
- QVector<ModuleInstantiation*> else_children;
+ std::vector<ModuleInstantiation*> else_children;
};
class AbstractModule
@@ -40,37 +40,40 @@ class AbstractModule
public:
virtual ~AbstractModule();
virtual class AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const;
- virtual QString dump(QString indent, QString name) const;
+ virtual std::string dump(const std::string &indent, const std::string &name) const;
};
class Module : public AbstractModule
{
public:
- QHash< QString, Module*> usedlibs;
+ typedef boost::unordered_map<std::string, class Module*> ModuleContainer;
+ ModuleContainer usedlibs;
struct libs_cache_ent {
Module *mod;
- QString cache_id, msg;
+ std::string cache_id, msg;
};
- static QHash<QString, libs_cache_ent> libs_cache;
- static Module *compile_library(QString filename);
+ static boost::unordered_map<std::string, libs_cache_ent> libs_cache;
+ static Module *compile_library(std::string filename);
- QVector<QString> argnames;
- QVector<Expression*> argexpr;
+ std::vector<std::string> argnames;
+ std::vector<Expression*> argexpr;
- QVector<QString> assignments_var;
- QVector<Expression*> assignments_expr;
+ std::vector<std::string> assignments_var;
+ std::vector<Expression*> assignments_expr;
- QHash<QString, class AbstractFunction*> functions;
- QHash<QString, AbstractModule*> modules;
+ typedef boost::unordered_map<std::string, class AbstractFunction*> FunctionContainer;
+ FunctionContainer functions;
+ typedef boost::unordered_map<std::string, AbstractModule*> AbstractModuleContainer;
+ AbstractModuleContainer modules;
- QVector<ModuleInstantiation*> children;
+ std::vector<ModuleInstantiation*> children;
Module() { }
virtual ~Module();
virtual AbstractNode *evaluate(const Context *ctx, const ModuleInstantiation *inst) const;
- virtual QString dump(QString indent, QString name) const;
+ virtual std::string dump(const std::string &indent, const std::string &name) const;
};
#endif
diff --git a/src/parser.y b/src/parser.y
index 2bd425f..219dd5e 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -44,6 +44,8 @@
#include "value.h"
#include "function.h"
#include "printutils.h"
+#include <sstream>
+#include <boost/foreach.hpp>
int parser_error_pos = -1;
@@ -54,18 +56,18 @@ int lexerget_lineno(void);
int lexerlex_destroy(void);
int lexerlex(void);
-QVector<Module*> module_stack;
+std::vector<Module*> module_stack;
Module *module;
class ArgContainer {
-public:
- QString argname;
+public:
+ std::string argname;
Expression *argexpr;
};
class ArgsContainer {
public:
- QVector<QString> argnames;
- QVector<Expression*> argexpr;
+ std::vector<std::string> argnames;
+ std::vector<Expression*> argexpr;
};
%}
@@ -144,29 +146,29 @@ statement:
'{' inner_input '}' |
module_instantiation {
if ($1) {
- module->children.append($1);
+ module->children.push_back($1);
} else {
delete $1;
}
} |
TOK_ID '=' expr ';' {
bool add_new_assignment = true;
- for (int i = 0; i < module->assignments_var.size(); i++) {
- if (module->assignments_var[i] != QString($1))
+ for (size_t i = 0; i < module->assignments_var.size(); i++) {
+ if (module->assignments_var[i] != $1)
continue;
delete module->assignments_expr[i];
module->assignments_expr[i] = $3;
add_new_assignment = false;
}
if (add_new_assignment) {
- module->assignments_var.append($1);
- module->assignments_expr.append($3);
+ module->assignments_var.push_back($1);
+ module->assignments_expr.push_back($3);
free($1);
}
} |
TOK_MODULE TOK_ID '(' arguments_decl optional_commas ')' {
Module *p = module;
- module_stack.append(module);
+ module_stack.push_back(module);
module = new Module();
p->modules[$2] = module;
module->argnames = $4->argnames;
@@ -174,7 +176,7 @@ statement:
free($2);
delete $4;
} statement {
- module = module_stack.last();
+ module = module_stack.back();
module_stack.pop_back();
} |
TOK_FUNCTION TOK_ID '(' arguments_decl optional_commas ')' '=' expr {
@@ -192,7 +194,7 @@ children_instantiation:
module_instantiation {
$$ = new ModuleInstantiation();
if ($1) {
- $$->children.append($1);
+ $$->children.push_back($1);
} else {
delete $1;
}
@@ -205,13 +207,13 @@ if_statement:
TOK_IF '(' expr ')' children_instantiation {
$$ = new IfElseModuleInstantiation();
$$->modname = "if";
- $$->argnames.append(QString());
- $$->argexpr.append($3);
+ $$->argnames.push_back("");
+ $$->argexpr.push_back($3);
if ($$) {
$$->children = $5->children;
} else {
- for (int i = 0; i < $5->children.count(); i++)
+ for (size_t i = 0; i < $5->children.size(); i++)
delete $5->children[i];
}
$5->children.clear();
@@ -227,7 +229,7 @@ ifelse_statement:
if ($$) {
$$->else_children = $3->children;
} else {
- for (int i = 0; i < $3->children.count(); i++)
+ for (size_t i = 0; i < $3->children.size(); i++)
delete $3->children[i];
}
$3->children.clear();
@@ -243,7 +245,7 @@ module_instantiation:
if ($$) {
$$->children = $2->children;
} else {
- for (int i = 0; i < $2->children.count(); i++)
+ for (size_t i = 0; i < $2->children.size(); i++)
delete $2->children[i];
}
$2->children.clear();
@@ -261,7 +263,7 @@ module_instantiation_list:
$$ = $1;
if ($$) {
if ($2)
- $$->children.append($2);
+ $$->children.push_back($2);
} else {
delete $2;
}
@@ -270,7 +272,7 @@ module_instantiation_list:
single_module_instantiation:
TOK_ID '(' arguments_call ')' {
$$ = new ModuleInstantiation();
- $$->modname = QString($1);
+ $$->modname = $1;
$$->argnames = $3->argnames;
$$->argexpr = $3->argexpr;
free($1);
@@ -279,7 +281,7 @@ single_module_instantiation:
TOK_ID ':' single_module_instantiation {
$$ = $3;
if ($$)
- $$->label = QString($1);
+ $$->label = $1;
free($1);
} |
'!' single_module_instantiation {
@@ -321,14 +323,14 @@ expr:
TOK_ID {
$$ = new Expression();
$$->type = "L";
- $$->var_name = QString($1);
+ $$->var_name = $1;
free($1);
} |
expr '.' TOK_ID {
$$ = new Expression();
$$->type = "N";
- $$->children.append($1);
- $$->var_name = QString($3);
+ $$->children.push_back($1);
+ $$->var_name = $3;
free($3);
} |
TOK_STRING {
@@ -348,16 +350,16 @@ expr:
e_one->const_value = new Value(1.0);
$$ = new Expression();
$$->type = "R";
- $$->children.append($2);
- $$->children.append(e_one);
- $$->children.append($4);
+ $$->children.push_back($2);
+ $$->children.push_back(e_one);
+ $$->children.push_back($4);
} |
'[' expr ':' expr ':' expr ']' {
$$ = new Expression();
$$->type = "R";
- $$->children.append($2);
- $$->children.append($4);
- $$->children.append($6);
+ $$->children.push_back($2);
+ $$->children.push_back($4);
+ $$->children.push_back($6);
} |
'[' optional_commas ']' {
$$ = new Expression();
@@ -371,80 +373,80 @@ expr:
expr '*' expr {
$$ = new Expression();
$$->type = "*";
- $$->children.append($1);
- $$->children.append($3);
+ $$->children.push_back($1);
+ $$->children.push_back($3);
} |
expr '/' expr {
$$ = new Expression();
$$->type = "/";
- $$->children.append($1);
- $$->children.append($3);
+ $$->children.push_back($1);
+ $$->children.push_back($3);
} |
expr '%' expr {
$$ = new Expression();
$$->type = "%";
- $$->children.append($1);
- $$->children.append($3);
+ $$->children.push_back($1);
+ $$->children.push_back($3);
} |
expr '+' expr {
$$ = new Expression();
$$->type = "+";
- $$->children.append($1);
- $$->children.append($3);
+ $$->children.push_back($1);
+ $$->children.push_back($3);
} |
expr '-' expr {
$$ = new Expression();
$$->type = "-";
- $$->children.append($1);
- $$->children.append($3);
+ $$->children.push_back($1);
+ $$->children.push_back($3);
} |
expr '<' expr {
$$ = new Expression();
$$->type = "<";
- $$->children.append($1);
- $$->children.append($3);
+ $$->children.push_back($1);
+ $$->children.push_back($3);
} |
expr LE expr {
$$ = new Expression();
$$->type = "<=";
- $$->children.append($1);
- $$->children.append($3);
+ $$->children.push_back($1);
+ $$->children.push_back($3);
} |
expr EQ expr {
$$ = new Expression();
$$->type = "==";
- $$->children.append($1);
- $$->children.append($3);
+ $$->children.push_back($1);
+ $$->children.push_back($3);
} |
expr NE expr {
$$ = new Expression();
$$->type = "!=";
- $$->children.append($1);
- $$->children.append($3);
+ $$->children.push_back($1);
+ $$->children.push_back($3);
} |
expr GE expr {
$$ = new Expression();
$$->type = ">=";
- $$->children.append($1);
- $$->children.append($3);
+ $$->children.push_back($1);
+ $$->children.push_back($3);
} |
expr '>' expr {
$$ = new Expression();
$$->type = ">";
- $$->children.append($1);
- $$->children.append($3);
+ $$->children.push_back($1);
+ $$->children.push_back($3);
} |
expr AND expr {
$$ = new Expression();
$$->type = "&&";
- $$->children.append($1);
- $$->children.append($3);
+ $$->children.push_back($1);
+ $$->children.push_back($3);
} |
expr OR expr {
$$ = new Expression();
$$->type = "||";
- $$->children.append($1);
- $$->children.append($3);
+ $$->children.push_back($1);
+ $$->children.push_back($3);
} |
'+' expr {
$$ = $2;
@@ -452,12 +454,12 @@ expr:
'-' expr {
$$ = new Expression();
$$->type = "I";
- $$->children.append($2);
+ $$->children.push_back($2);
} |
'!' expr {
$$ = new Expression();
$$->type = "!";
- $$->children.append($2);
+ $$->children.push_back($2);
} |
'(' expr ')' {
$$ = $2;
@@ -465,20 +467,20 @@ expr:
expr '?' expr ':' expr {
$$ = new Expression();
$$->type = "?:";
- $$->children.append($1);
- $$->children.append($3);
- $$->children.append($5);
+ $$->children.push_back($1);
+ $$->children.push_back($3);
+ $$->children.push_back($5);
} |
expr '[' expr ']' {
$$ = new Expression();
$$->type = "[]";
- $$->children.append($1);
- $$->children.append($3);
+ $$->children.push_back($1);
+ $$->children.push_back($3);
} |
TOK_ID '(' arguments_call ')' {
$$ = new Expression();
$$->type = "F";
- $$->call_funcname = QString($1);
+ $$->call_funcname = $1;
$$->call_argnames = $3->argnames;
$$->children = $3->argexpr;
free($1);
@@ -492,11 +494,11 @@ vector_expr:
expr {
$$ = new Expression();
$$->type = 'V';
- $$->children.append($1);
+ $$->children.push_back($1);
} |
vector_expr ',' optional_commas expr {
$$ = $1;
- $$->children.append($4);
+ $$->children.push_back($4);
} ;
arguments_decl:
@@ -505,27 +507,27 @@ arguments_decl:
} |
argument_decl {
$$ = new ArgsContainer();
- $$->argnames.append($1->argname);
- $$->argexpr.append($1->argexpr);
+ $$->argnames.push_back($1->argname);
+ $$->argexpr.push_back($1->argexpr);
delete $1;
} |
arguments_decl ',' optional_commas argument_decl {
$$ = $1;
- $$->argnames.append($4->argname);
- $$->argexpr.append($4->argexpr);
+ $$->argnames.push_back($4->argname);
+ $$->argexpr.push_back($4->argexpr);
delete $4;
} ;
argument_decl:
TOK_ID {
$$ = new ArgContainer();
- $$->argname = QString($1);
+ $$->argname = $1;
$$->argexpr = NULL;
free($1);
} |
TOK_ID '=' expr {
$$ = new ArgContainer();
- $$->argname = QString($1);
+ $$->argname = $1;
$$->argexpr = $3;
free($1);
} ;
@@ -536,14 +538,14 @@ arguments_call:
} |
argument_call {
$$ = new ArgsContainer();
- $$->argnames.append($1->argname);
- $$->argexpr.append($1->argexpr);
+ $$->argnames.push_back($1->argname);
+ $$->argexpr.push_back($1->argexpr);
delete $1;
} |
arguments_call ',' optional_commas argument_call {
$$ = $1;
- $$->argnames.append($4->argname);
- $$->argexpr.append($4->argexpr);
+ $$->argnames.push_back($4->argname);
+ $$->argexpr.push_back($4->argexpr);
delete $4;
} ;
@@ -554,7 +556,7 @@ argument_call:
} |
TOK_ID '=' expr {
$$ = new ArgContainer();
- $$->argname = QString($1);
+ $$->argname = $1;
$$->argexpr = $3;
free($1);
} ;
@@ -596,13 +598,11 @@ AbstractModule *parse(const char *text, const char *path, int debug)
if (!module)
return NULL;
- QHashIterator<QString, Module*> i(module->usedlibs);
- while (i.hasNext()) {
- i.next();
- module->usedlibs[i.key()] = Module::compile_library(i.key());
- if (!module->usedlibs[i.key()]) {
- PRINTF("WARNING: Failed to compile library `%s'.", i.key().toUtf8().data());
- module->usedlibs.remove(i.key());
+ BOOST_FOREACH(Module::ModuleContainer::value_type &m, module->usedlibs) {
+ module->usedlibs[m.first] = Module::compile_library(m.first);
+ if (!module->usedlibs[m.first]) {
+ PRINTF("WARNING: Failed to compile library `%s'.", m.first.c_str());
+ module->usedlibs.erase(m.first);
}
}
@@ -610,46 +610,48 @@ AbstractModule *parse(const char *text, const char *path, int debug)
return module;
}
-QHash<QString, Module::libs_cache_ent> Module::libs_cache;
+boost::unordered_map<std::string, Module::libs_cache_ent> Module::libs_cache;
-Module *Module::compile_library(QString filename)
+Module *Module::compile_library(std::string filename)
{
struct stat st;
memset(&st, 0, sizeof(struct stat));
- stat(filename.toAscii().data(), &st);
+ stat(filename.c_str(), &st);
- QString cache_id;
- cache_id.sprintf("%x.%x", (int)st.st_mtime, (int)st.st_size);
+ std::stringstream idstream;
+ // FIXME: stream as hex
+ idstream << st.st_mtime << "." << st.st_size;
+ std::string cache_id = idstream.str();
- if (libs_cache.contains(filename) && libs_cache[filename].cache_id == cache_id) {
- PRINT(libs_cache[filename].msg);
- return &(*libs_cache[filename].mod);
+ if (libs_cache.find(filename) != libs_cache.end() && libs_cache[filename].cache_id == cache_id) {
+ PRINTF("%s", libs_cache[filename].msg.c_str());
+ return &(*libs_cache[filename].mod);
}
- QFile f(filename);
+ QFile f(QString::fromStdString(filename));
if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
- PRINTF("WARNING: Can't open library file `%s'.", filename.toUtf8().data());
+ PRINTF("WARNING: Can't open library file `%s'.", filename.c_str());
return NULL;
}
QString text = QTextStream(&f).readAll();
print_messages_push();
- PRINTF("Compiling library `%s'.", filename.toUtf8().data());
- libs_cache_ent e = { NULL, cache_id, QString("WARNING: Library `%1' tries to recursively use itself!").arg(filename) };
- if (libs_cache.contains(filename))
+ PRINTF("Compiling library `%s'.", filename.c_str());
+ libs_cache_ent e = { NULL, cache_id, std::string("WARNING: Library `") + filename + "' tries to recursively use itself!" };
+ if (libs_cache.find(filename) != libs_cache.end())
delete libs_cache[filename].mod;
libs_cache[filename] = e;
Module *backup_mod = module;
- Module *lib_mod = dynamic_cast<Module*>(parse(text.toLocal8Bit(), QFileInfo(filename).absoluteDir().absolutePath().toLocal8Bit(), 0));
+ Module *lib_mod = dynamic_cast<Module*>(parse(text.toLocal8Bit(), QFileInfo(QString::fromStdString(filename)).absoluteDir().absolutePath().toLocal8Bit(), 0));
module = backup_mod;
if (lib_mod) {
libs_cache[filename].mod = lib_mod;
- libs_cache[filename].msg = print_messages_stack.last();
+ libs_cache[filename].msg = print_messages_stack.last().toStdString();
} else {
- libs_cache.remove(filename);
+ libs_cache.erase(filename);
}
print_messages_pop();
diff --git a/src/primitives.cc b/src/primitives.cc
index 0da8fba..1a04cad 100644
--- a/src/primitives.cc
+++ b/src/primitives.cc
@@ -36,6 +36,8 @@
#include "visitor.h"
#include <sstream>
#include <assert.h>
+#include <boost/assign/std/vector.hpp>
+using namespace boost::assign; // bring 'operator+=()' into scope
#define F_MINIMUM 0.01
@@ -110,30 +112,30 @@ AbstractNode *PrimitiveModule::evaluate(const Context *ctx, const ModuleInstanti
node->center = false;
node->x = node->y = node->z = node->h = node->r1 = node->r2 = 1;
- QVector<QString> argnames;
- QVector<Expression*> argexpr;
+ std::vector<std::string> argnames;
+ std::vector<Expression*> argexpr;
switch (this->type) {
case CUBE:
- argnames = QVector<QString>() << "size" << "center";
+ argnames += "size", "center";
break;
case SPHERE:
- argnames = QVector<QString>() << "r";
+ argnames += "r";
break;
case CYLINDER:
- argnames = QVector<QString>() << "h" << "r1" << "r2" << "center";
+ argnames += "h", "r1", "r2", "center";
break;
case POLYHEDRON:
- argnames = QVector<QString>() << "points" << "triangles" << "convexity";
+ argnames += "points", "triangles", "convexity";
break;
case SQUARE:
- argnames = QVector<QString>() << "size" << "center";
+ argnames += "size", "center";
break;
case CIRCLE:
- argnames = QVector<QString>() << "r";
+ argnames += "r";
break;
case POLYGON:
- argnames = QVector<QString>() << "points" << "paths" << "convexity";
+ argnames += "points", "paths", "convexity";
break;
default:
assert(false && "PrimitiveModule::evaluate(): Unknown node type");
@@ -463,7 +465,7 @@ sphere_next_r2:
{
p->append_poly();
for (size_t j=0; j<this->triangles.vec[i]->vec.size(); j++) {
- int pt = this->triangles.vec[i]->vec[j]->num;
+ size_t pt = this->triangles.vec[i]->vec[j]->num;
if (pt < this->points.vec.size()) {
double px, py, pz;
if (this->points.vec[pt]->getv3(px, py, pz))
diff --git a/src/projection.cc b/src/projection.cc
index 67bd683..ce702e4 100644
--- a/src/projection.cc
+++ b/src/projection.cc
@@ -44,10 +44,8 @@
#include <assert.h>
#include <sstream>
-
-#include <QApplication>
-#include <QTime>
-#include <QProgressDialog>
+#include <boost/assign/std/vector.hpp>
+using namespace boost::assign; // bring 'operator+=()' into scope
class ProjectionModule : public AbstractModule
{
@@ -60,8 +58,9 @@ AbstractNode *ProjectionModule::evaluate(const Context *ctx, const ModuleInstant
{
ProjectionNode *node = new ProjectionNode(inst);
- QVector<QString> argnames = QVector<QString>() << "cut";
- QVector<Expression*> argexpr;
+ std::vector<std::string> argnames;
+ argnames += "cut";
+ std::vector<Expression*> argexpr;
Context c(ctx);
c.args(argnames, argexpr, inst->argnames, inst->argvalues);
diff --git a/src/render.cc b/src/render.cc
index a463c67..15b4863 100644
--- a/src/render.cc
+++ b/src/render.cc
@@ -36,9 +36,9 @@
#include "progress.h"
#include "visitor.h"
-#include <QApplication>
-#include <QTime>
#include <sstream>
+#include <boost/assign/std/vector.hpp>
+using namespace boost::assign; // bring 'operator+=()' into scope
class RenderModule : public AbstractModule
{
@@ -51,8 +51,9 @@ AbstractNode *RenderModule::evaluate(const Context *ctx, const ModuleInstantiati
{
RenderNode *node = new RenderNode(inst);
- QVector<QString> argnames = QVector<QString>() << "convexity";
- QVector<Expression*> argexpr;
+ std::vector<std::string> argnames;
+ argnames += "convexity";
+ std::vector<Expression*> argexpr;
Context c(ctx);
c.args(argnames, argexpr, inst->argnames, inst->argvalues);
diff --git a/src/surface.cc b/src/surface.cc
index 2a4fec6..d9a0c6e 100644
--- a/src/surface.cc
+++ b/src/surface.cc
@@ -38,6 +38,9 @@
#include <QRegExp>
#include <QStringList>
#include <sstream>
+#include <boost/unordered_map.hpp>
+#include <boost/assign/std/vector.hpp>
+using namespace boost::assign; // bring 'operator+=()' into scope
class SurfaceModule : public AbstractModule
{
@@ -56,7 +59,7 @@ public:
virtual std::string toString() const;
virtual std::string name() const { return "surface"; }
- QString filename;
+ std::string filename;
bool center;
int convexity;
virtual PolySet *evaluate_polyset(render_mode_e mode, class PolySetEvaluator *) const;
@@ -68,13 +71,14 @@ AbstractNode *SurfaceModule::evaluate(const Context *ctx, const ModuleInstantiat
node->center = false;
node->convexity = 1;
- QVector<QString> argnames = QVector<QString>() << "file" << "center" << "convexity";
- QVector<Expression*> argexpr;
+ std::vector<std::string> argnames;
+ argnames += "file", "center", "convexity";
+ std::vector<Expression*> argexpr;
Context c(ctx);
c.args(argnames, argexpr, inst->argnames, inst->argvalues);
- node->filename = c.get_absolute_path(QString::fromStdString(c.lookup_variable("file").text));
+ node->filename = c.get_absolute_path(c.lookup_variable("file").text);
Value center = c.lookup_variable("center", true);
if (center.type == Value::BOOL) {
@@ -97,16 +101,16 @@ void register_builtin_surface()
PolySet *SurfaceNode::evaluate_polyset(render_mode_e, class PolySetEvaluator *) const
{
PolySet *p = new PolySet();
- handle_dep(filename);
- QFile f(filename);
+ handle_dep(QString::fromStdString(filename));
+ QFile f(QString::fromStdString(filename));
if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
- PRINTF("WARNING: Can't open DAT file `%s'.", filename.toAscii().data());
+ PRINTF("WARNING: Can't open DAT file `%s'.", filename.c_str());
return p;
}
int lines = 0, columns = 0;
- QHash<QPair<int,int>,double> data;
+ boost::unordered_map<std::pair<int,int>,double> data;
double min_val = 0;
while (!f.atEnd())
@@ -123,7 +127,7 @@ PolySet *SurfaceNode::evaluate_polyset(render_mode_e, class PolySetEvaluator *)
if (i >= columns)
columns = i + 1;
double v = fields[i].toDouble();
- data[QPair<int,int>(lines, i)] = v;
+ data[std::make_pair(lines, i)] = v;
min_val = fmin(v-1, min_val);
}
lines++;
@@ -137,10 +141,10 @@ PolySet *SurfaceNode::evaluate_polyset(render_mode_e, class PolySetEvaluator *)
for (int i = 1; i < lines; i++)
for (int j = 1; j < columns; j++)
{
- double v1 = data[QPair<int,int>(i-1, j-1)];
- double v2 = data[QPair<int,int>(i-1, j)];
- double v3 = data[QPair<int,int>(i, j-1)];
- double v4 = data[QPair<int,int>(i, j)];
+ double v1 = data[std::make_pair(i-1, j-1)];
+ double v2 = data[std::make_pair(i-1, j)];
+ double v3 = data[std::make_pair(i, j-1)];
+ double v4 = data[std::make_pair(i, j)];
double vx = (v1 + v2 + v3 + v4) / 4;
p->append_poly();
@@ -168,14 +172,14 @@ PolySet *SurfaceNode::evaluate_polyset(render_mode_e, class PolySetEvaluator *)
{
p->append_poly();
p->append_vertex(ox + 0, oy + i-1, min_val);
- p->append_vertex(ox + 0, oy + i-1, data[QPair<int,int>(i-1, 0)]);
- p->append_vertex(ox + 0, oy + i, data[QPair<int,int>(i, 0)]);
+ p->append_vertex(ox + 0, oy + i-1, data[std::make_pair(i-1, 0)]);
+ p->append_vertex(ox + 0, oy + i, data[std::make_pair(i, 0)]);
p->append_vertex(ox + 0, oy + i, min_val);
p->append_poly();
p->insert_vertex(ox + columns-1, oy + i-1, min_val);
- p->insert_vertex(ox + columns-1, oy + i-1, data[QPair<int,int>(i-1, columns-1)]);
- p->insert_vertex(ox + columns-1, oy + i, data[QPair<int,int>(i, columns-1)]);
+ p->insert_vertex(ox + columns-1, oy + i-1, data[std::make_pair(i-1, columns-1)]);
+ p->insert_vertex(ox + columns-1, oy + i, data[std::make_pair(i, columns-1)]);
p->insert_vertex(ox + columns-1, oy + i, min_val);
}
@@ -183,14 +187,14 @@ PolySet *SurfaceNode::evaluate_polyset(render_mode_e, class PolySetEvaluator *)
{
p->append_poly();
p->insert_vertex(ox + i-1, oy + 0, min_val);
- p->insert_vertex(ox + i-1, oy + 0, data[QPair<int,int>(0, i-1)]);
- p->insert_vertex(ox + i, oy + 0, data[QPair<int,int>(0, i)]);
+ p->insert_vertex(ox + i-1, oy + 0, data[std::make_pair(0, i-1)]);
+ p->insert_vertex(ox + i, oy + 0, data[std::make_pair(0, i)]);
p->insert_vertex(ox + i, oy + 0, min_val);
p->append_poly();
p->append_vertex(ox + i-1, oy + lines-1, min_val);
- p->append_vertex(ox + i-1, oy + lines-1, data[QPair<int,int>(lines-1, i-1)]);
- p->append_vertex(ox + i, oy + lines-1, data[QPair<int,int>(lines-1, i)]);
+ p->append_vertex(ox + i-1, oy + lines-1, data[std::make_pair(lines-1, i-1)]);
+ p->append_vertex(ox + i, oy + lines-1, data[std::make_pair(lines-1, i)]);
p->append_vertex(ox + i, oy + lines-1, min_val);
}
diff --git a/src/transform.cc b/src/transform.cc
index 07aaee8..8975fd5 100644
--- a/src/transform.cc
+++ b/src/transform.cc
@@ -37,6 +37,8 @@
#include <sstream>
#include <vector>
#include <assert.h>
+#include <boost/assign/std/vector.hpp>
+using namespace boost::assign; // bring 'operator+=()' into scope
enum transform_type_e {
SCALE,
@@ -86,24 +88,24 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti
for (int i = 0; i < 16; i++)
node->matrix[i] = i % 5 == 0 ? 1.0 : 0.0;
- QVector<QString> argnames;
- QVector<Expression*> argexpr;
+ std::vector<std::string> argnames;
+ std::vector<Expression*> argexpr;
switch (this->type) {
case SCALE:
- argnames = QVector<QString>() << "v";
+ argnames += "v";
break;
case ROTATE:
- argnames = QVector<QString>() << "a" << "v";
+ argnames += "a", "v";
break;
case MIRROR:
- argnames = QVector<QString>() << "v";
+ argnames += "v";
break;
case TRANSLATE:
- argnames = QVector<QString>() << "v";
+ argnames += "v";
break;
case MULTMATRIX:
- argnames = QVector<QString>() << "m";
+ argnames += "m";
break;
default:
assert(false);
@@ -127,7 +129,7 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti
Value val_a = c.lookup_variable("a");
if (val_a.type == Value::VECTOR)
{
- for (int i = 0; i < 3 && i < val_a.vec.size(); i++) {
+ for (size_t i = 0; i < 3 && i < val_a.vec.size(); i++) {
double a;
val_a.vec[i]->getnum(a);
double c = cos(a*M_PI/180.0);
@@ -230,7 +232,7 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanti
Value v = c.lookup_variable("m");
if (v.type == Value::VECTOR) {
for (int i = 0; i < 16; i++) {
- int x = i / 4, y = i % 4;
+ size_t x = i / 4, y = i % 4;
if (y < v.vec.size() && v.vec[y]->type == Value::VECTOR && x < v.vec[y]->vec.size())
v.vec[y]->vec[x]->getnum(node->matrix[i]);
}
contact: Jan Huwald // Impressum