Any Any::operator + (const Any &r) const { switch (this->type()) { case Any::Int: switch (r.type()) { case Any::Int: return this->getInt() + r.getInt(); case Any::Float: return this->getInt() + r.getFloat(); case Any::String: return boost::lexical_cast<string>(this->getInt()) + r.getString(); } break; case Any::Float: switch (r.type()) { case Any::Int: return this->getFloat() + r.getInt(); case Any::Float: return this->getFloat() + r.getFloat(); case Any::String: return boost::lexical_cast<string>(this->getFloat()) + r.getString(); } break; case Any::String: switch (r.type()) { case Any::Int: return this->getString() + boost::lexical_cast<string>(r.getInt()); case Any::Float: return this->getString() + boost::lexical_cast<string>(r.getFloat()); case Any::String: return this->getString() + r.getString(); } break; } FIXME("Unsupported operation %s + %s", this->typeInfo().name(), r.typeInfo().name()); return 0; }
void MathInterface::functionAbs(void) { Any v = cb->popValue(); if (v.type() == Any::Float) { cb->pushValue(abs(v.getFloat())); return; } cb->pushValue(abs(v.getInt())); return; }
void MathInterface::functionWrapAngle(void) { Any a = cb->popValue(); if (a.type() == Any::Float) { cb->pushValue(wrapAngle(a.getFloat())); } else { // Has to be int cb->pushValue(wrapAngle(a.getInt())); } }
Any Any::operator / (const Any &r) const { switch (this->type()) { case Any::Int: switch (r.type()) { case Any::Int: return this->getInt() / r.getInt(); case Any::Float: return this->getInt() / r.getFloat(); } break; case Any::Float: switch (r.type()) { case Any::Int: return this->getFloat() / r.getInt(); case Any::Float: return this->getFloat() / r.getFloat(); } break; } FIXME("Unsupported operation %s / %s", this->typeInfo().name(), r.typeInfo().name()); return 0; }
Any Any::operator % (const Any &r) const { switch (this->type()) { case Any::Int: switch (r.type()) { case Any::Int: return this->getInt() % r.getInt(); case Any::Float: return (float)fmod((double)this->getInt(), (double)r.getFloat()); } break; case Any::Float: switch (r.type()) { case Any::Int: return (float)fmod((double)this->getFloat(), (double)r.getInt()); case Any::Float: return (float)fmod(this->getFloat(), r.getFloat()); } break; } FIXME("Unsupported operation %s % %s", this->typeInfo().name(), r.typeInfo().name()); return 0; }
void StringInterface::functionStr(void) { Any a = cb->popValue(); switch (a.type()) { case Any::Int: cb->pushValue(lexical_cast<string>(a.getInt())); return; case Any::Float: cb->pushValue(lexical_cast<string>(a.getFloat())); return; default: cb->pushValue(a); } }