Skip to content

Commit

Permalink
Merge pull request #4396 from thehans/replace_str
Browse files Browse the repository at this point in the history
Replace STR macro with recursive template function.
  • Loading branch information
thehans committed Oct 25, 2022
2 parents 18b0dbd + 208f783 commit 2d27703
Show file tree
Hide file tree
Showing 29 changed files with 103 additions and 83 deletions.
2 changes: 1 addition & 1 deletion src/Feature.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ ExperimentalFeatureException::~ExperimentalFeatureException() throw()
void ExperimentalFeatureException::check(const Feature& feature)
{
if (!feature.is_enabled()) {
throw ExperimentalFeatureException(STR("ERROR: Experimental feature not enabled: '" << feature.get_name() << "'. Please check preferences."));
throw ExperimentalFeatureException(STR("ERROR: Experimental feature not enabled: '", feature.get_name(), "'. Please check preferences."));
}
}
2 changes: 1 addition & 1 deletion src/core/CSGTreeEvaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ shared_ptr<CSGNode> CSGTreeEvaluator::evaluateCSGNodeFromGeometry(
// 3D PolySets are tessellated before inserting into Geometry cache, inside GeometryEvaluator::evaluateGeometry
}

shared_ptr<CSGNode> t(new CSGLeaf(g, state.matrix(), state.color(), STR(node.name() << node.index()), node.index()));
shared_ptr<CSGNode> t(new CSGLeaf(g, state.matrix(), state.color(), STR(node.name(), node.index()), node.index()));
if (modinst->isHighlight() || state.isHighlight()) t->setHighlight(true);
if (modinst->isBackground() || state.isBackground()) t->setBackground(true);
return t;
Expand Down
2 changes: 1 addition & 1 deletion src/core/ColorNode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ static std::shared_ptr<AbstractNode> builtin_color(const ModuleInstantiation *in

std::string ColorNode::toString() const
{
return STR("color([" << this->color[0] << ", " << this->color[1] << ", " << this->color[2] << ", " << this->color[3] << "])");
return STR("color([", this->color[0], ", ", this->color[1], ", ", this->color[2], ", ", this->color[3], "])");
}

std::string ColorNode::name() const
Expand Down
2 changes: 1 addition & 1 deletion src/core/Expression.cc
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ void Assert::performAssert(const AssignmentList& arguments, const Location& loca
}

if (!parameters["condition"].toBool()) {
std::string conditionString = conditionExpression ? STR(" '" << *conditionExpression << "'") : "";
std::string conditionString = conditionExpression ? STR(" '", *conditionExpression, "'") : "";
std::string messageString = parameters.contains("message") ? (": " + parameters["message"].toEchoStringNoThrow()) : "";
LOG(message_group::Error, location, context->documentRoot(), "Assertion%1$s failed%2$s", conditionString, messageString);
throw AssertionFailedException("Assertion Failed", location);
Expand Down
2 changes: 1 addition & 1 deletion src/core/Parameters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void print_argCnt_warning(
const Location& loc,
const std::string& documentRoot
){
LOG(message_group::Warning, loc, documentRoot, "%1$s() number of parameters does not match: expected " + expected + ", found " + STR(found), name);
LOG(message_group::Warning, loc, documentRoot, "%1$s() number of parameters does not match: expected %2$s, found %3$i", name, expected, found);
}

void print_argConvert_warning(
Expand Down
4 changes: 2 additions & 2 deletions src/core/ProjectionNode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ static std::shared_ptr<AbstractNode> builtin_projection(const ModuleInstantiatio

std::string ProjectionNode::toString() const
{
return STR("projection(cut = " << (this->cut_mode ? "true" : "false")
<< ", convexity = " << this->convexity << ")");
return STR("projection(cut = ", (this->cut_mode ? "true" : "false"),
", convexity = ", this->convexity, ")");
}

void register_builtin_projection()
Expand Down
2 changes: 1 addition & 1 deletion src/core/RenderNode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static std::shared_ptr<AbstractNode> builtin_render(const ModuleInstantiation *i

std::string RenderNode::toString() const
{
return STR(this->name() << "(convexity = " << convexity << ")");
return STR(this->name(), "(convexity = ", convexity, ")");
}

void register_builtin_render()
Expand Down
2 changes: 1 addition & 1 deletion src/core/SourceFileCache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ std::time_t SourceFileCache::evaluate(const std::string& mainFile, const std::st
LOG(message_group::Warning, Location::NONE, "", "Can't open library file '%1$s'\n", filename);
return 0;
}
text = STR(ifs.rdbuf() << "\n\x03\n" << commandline_commands);
text = STR(ifs.rdbuf(), "\n\x03\n", commandline_commands);
}

print_messages_push();
Expand Down
2 changes: 1 addition & 1 deletion src/core/TextNode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ FreetypeRenderer::Params TextNode::get_params() const

std::string TextNode::toString() const
{
return STR(name() << "(" << this->params << ")");
return STR(name(), "(", this->params, ")");
}

void register_builtin_text()
Expand Down
60 changes: 30 additions & 30 deletions src/core/Value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ class tostring_visitor : public boost::static_visitor<std::string>
public:
template <typename T> std::string operator()(const T& op1) const {
assert(false && "unhandled tostring_visitor type");
return boost::lexical_cast<std::string>(op1);
return STR(op1);
}

std::string operator()(const str_utf8_wrapper& op1) const {
Expand Down Expand Up @@ -777,7 +777,7 @@ Value VectorType::operator==(const VectorType& v) const {
for ( ; (first1 != last1) && (first2 != last2); ++first1, ++first2, ++i) {
Value temp = *first1 == *first2;
if (temp.isUndefined()) {
temp.toUndef().append(STR("in vector comparison at index " << i));
temp.toUndef().append(STR("in vector comparison at index ", i));
return temp;
}
if (!temp.toBool()) return false;
Expand All @@ -798,7 +798,7 @@ Value VectorType::operator<(const VectorType& v) const {
for ( ; (first1 != last1) && (first2 != last2); ++first1, ++first2, ++i) {
Value temp = *first1 < *first2;
if (temp.isUndefined()) {
temp.toUndef().append(STR("in vector comparison at index " << i));
temp.toUndef().append(STR("in vector comparison at index ", i));
return temp;
}
if (temp.toBool()) return true;
Expand Down Expand Up @@ -845,7 +845,7 @@ class less_visitor : public boost::static_visitor<Value>
{
public:
template <typename T, typename U> Value operator()(const T& op1, const U& op2) const {
return Value::undef(STR("undefined operation (" << getTypeName(op1) << " < " << getTypeName(op2) << ")"));
return Value::undef(STR("undefined operation (", getTypeName(op1), " < ", getTypeName(op2), ")"));
}
template <typename T> Value operator()(const T& op1, const T& op2) const { return op1 < op2; }
template <typename T> Value operator()(const ValuePtr<T>& op1, const ValuePtr<T>& op2) const { return *op1 < *op2; }
Expand All @@ -855,7 +855,7 @@ class greater_visitor : public boost::static_visitor<Value>
{
public:
template <typename T, typename U> Value operator()(const T& op1, const U& op2) const {
return Value::undef(STR("undefined operation (" << getTypeName(op1) << " > " << getTypeName(op2) << ")"));
return Value::undef(STR("undefined operation (", getTypeName(op1), " > ", getTypeName(op2), ")"));
}
template <typename T> Value operator()(const T& op1, const T& op2) const { return op1 > op2; }
template <typename T> Value operator()(const ValuePtr<T>& op1, const ValuePtr<T>& op2) const { return *op1 > *op2; }
Expand All @@ -865,7 +865,7 @@ class lessequal_visitor : public boost::static_visitor<Value>
{
public:
template <typename T, typename U> Value operator()(const T& op1, const U& op2) const {
return Value::undef(STR("undefined operation (" << getTypeName(op1) << " <= " << getTypeName(op2) << ")"));
return Value::undef(STR("undefined operation (", getTypeName(op1), " <= ", getTypeName(op2), ")"));
}
template <typename T> Value operator()(const T& op1, const T& op2) const { return op1 <= op2; }
template <typename T> Value operator()(const ValuePtr<T>& op1, const ValuePtr<T>& op2) const { return *op1 <= *op2; }
Expand All @@ -875,7 +875,7 @@ class greaterequal_visitor : public boost::static_visitor<Value>
{
public:
template <typename T, typename U> Value operator()(const T& op1, const U& op2) const {
return Value::undef(STR("undefined operation (" << getTypeName(op1) << " >= " << getTypeName(op2) << ")"));
return Value::undef(STR("undefined operation (", getTypeName(op1), " >= ", getTypeName(op2), ")"));
}
template <typename T> Value operator()(const T& op1, const T& op2) const { return op1 >= op2; }
template <typename T> Value operator()(const ValuePtr<T>& op1, const ValuePtr<T>& op2) const { return *op1 >= *op2; }
Expand Down Expand Up @@ -919,7 +919,7 @@ class plus_visitor : public boost::static_visitor<Value>
{
public:
template <typename T, typename U> Value operator()(const T& op1, const U& op2) const {
return Value::undef(STR("undefined operation (" << getTypeName(op1) << " + " << getTypeName(op2) << ")"));
return Value::undef(STR("undefined operation (", getTypeName(op1), " + ", getTypeName(op2), ")"));
}

Value operator()(const double& op1, const double& op2) const {
Expand Down Expand Up @@ -949,7 +949,7 @@ class minus_visitor : public boost::static_visitor<Value>
{
public:
template <typename T, typename U> Value operator()(const T& op1, const U& op2) const {
return Value::undef(STR("undefined operation (" << getTypeName(op1) << " - " << getTypeName(op2) << ")"));
return Value::undef(STR("undefined operation (", getTypeName(op1), " - ", getTypeName(op2), ")"));
}

Value operator()(const double& op1, const double& op2) const {
Expand Down Expand Up @@ -987,15 +987,15 @@ Value multmatvec(const VectorType& matrixvec, const VectorType& vectorvec)
for (size_t i = 0; i < matrixvec.size(); ++i) {
if (matrixvec[i].type() != Value::Type::VECTOR ||
matrixvec[i].toVector().size() != vectorvec.size()) {
return Value::undef(STR("Matrix must be rectangular. Problem at row " << i));
return Value::undef(STR("Matrix must be rectangular. Problem at row ", i));
}
double r_e = 0.0;
for (size_t j = 0; j < matrixvec[i].toVector().size(); ++j) {
if (matrixvec[i].toVector()[j].type() != Value::Type::NUMBER) {
return Value::undef(STR("Matrix must contain only numbers. Problem at row " << i << ", col " << j));
return Value::undef(STR("Matrix must contain only numbers. Problem at row ", i, ", col ", j));
}
if (vectorvec[j].type() != Value::Type::NUMBER) {
return Value::undef(STR("Vector must contain only numbers. Problem at index " << j));
return Value::undef(STR("Vector must contain only numbers. Problem at index ", j));
}
r_e += matrixvec[i].toVector()[j].toDouble() * vectorvec[j].toDouble();
}
Expand All @@ -1016,15 +1016,15 @@ Value multvecmat(const VectorType& vectorvec, const VectorType& matrixvec)
if (matrixvec[j].type() != Value::Type::VECTOR ||
matrixvec[j].toVector().size() != firstRowSize) {
LOG(message_group::Warning, Location::NONE, "", "Matrix must be rectangular. Problem at row %1$lu", j);
return Value::undef(STR("Matrix must be rectangular. Problem at row " << j));
return Value::undef(STR("Matrix must be rectangular. Problem at row ", j));
}
if (vectorvec[j].type() != Value::Type::NUMBER) {
LOG(message_group::Warning, Location::NONE, "", "Vector must contain only numbers. Problem at index %1$lu", j);
return Value::undef(STR("Vector must contain only numbers. Problem at index " << j));
return Value::undef(STR("Vector must contain only numbers. Problem at index ", j));
}
if (matrixvec[j].toVector()[i].type() != Value::Type::NUMBER) {
LOG(message_group::Warning, Location::NONE, "", "Matrix must contain only numbers. Problem at row %1$lu, col %2$lu", j, i);
return Value::undef(STR("Matrix must contain only numbers. Problem at row " << j << ", col " << i));
return Value::undef(STR("Matrix must contain only numbers. Problem at row ", j, ", col ", i));
}
r_e += vectorvec[j].toDouble() * matrixvec[j].toVector()[i].toDouble();
}
Expand All @@ -1038,7 +1038,7 @@ Value multvecvec(const VectorType& vec1, const VectorType& vec2) {
auto r = 0.0;
for (size_t i = 0; i < vec1.size(); i++) {
if (vec1[i].type() != Value::Type::NUMBER || vec2[i].type() != Value::Type::NUMBER) {
return Value::undef(STR("undefined operation (" << vec1[i].typeName() << " * " << vec2[i].typeName() << ")"));
return Value::undef(STR("undefined operation (", vec1[i].typeName(), " * ", vec2[i].typeName(), ")"));
}
r += vec1[i].toDouble() * vec2[i].toDouble();
}
Expand All @@ -1049,7 +1049,7 @@ class multiply_visitor : public boost::static_visitor<Value>
{
public:
template <typename T, typename U> Value operator()(const T& op1, const U& op2) const {
return Value::undef(STR("undefined operation (" << getTypeName(op1) << " * " << getTypeName(op2) << ")"));
return Value::undef(STR("undefined operation (", getTypeName(op1), " * ", getTypeName(op2), ")"));
}
Value operator()(const double& op1, const double& op2) const { return op1 * op2; }
Value operator()(const double& op1, const VectorType& op2) const { return multvecnum(op2, op1); }
Expand All @@ -1062,26 +1062,26 @@ class multiply_visitor : public boost::static_visitor<Value>
if (eltype1 == Value::Type::NUMBER) {
if (eltype2 == Value::Type::NUMBER) {
if (op1.size() == op2.size()) return multvecvec(op1, op2);
else return Value::undef(STR("vector*vector requires matching lengths (" << op1.size() << " != " << op2.size() << ')'));
else return Value::undef(STR("vector*vector requires matching lengths (", op1.size(), " != ", op2.size(), ')'));
} else if (eltype2 == Value::Type::VECTOR) {
if (op1.size() == op2.size()) return multvecmat(op1, op2);
else return Value::undef(STR("vector*matrix requires vector length to match matrix row count (" << op1.size() << " != " << op2.size() << ')'));
else return Value::undef(STR("vector*matrix requires vector length to match matrix row count (", op1.size(), " != ", op2.size(), ')'));
}
} else if (eltype1 == Value::Type::VECTOR) {
if (eltype2 == Value::Type::NUMBER) {
if ((*first1).toVector().size() == op2.size()) return multmatvec(op1, op2);
else return Value::undef(STR("matrix*vector requires matrix column count to match vector length (" << (*first1).toVector().size() << " != " << op2.size() << ')'));
else return Value::undef(STR("matrix*vector requires matrix column count to match vector length (", (*first1).toVector().size(), " != ", op2.size(), ')'));
} else if (eltype2 == Value::Type::VECTOR) {
if ((*first1).toVector().size() == op2.size()) {
// Matrix * Matrix
VectorType dstv(op1.evaluation_session());
size_t i = 0;
for (const auto& srcrow : op1) {
const auto& srcrowvec = srcrow.toVector();
if (srcrowvec.size() != op2.size()) return Value::undef(STR("matrix*matrix left operand row length does not match right operand row count (" << srcrowvec.size() << " != " << op2.size() << ") at row " << i));
if (srcrowvec.size() != op2.size()) return Value::undef(STR("matrix*matrix left operand row length does not match right operand row count (", srcrowvec.size(), " != ", op2.size(), ") at row ", i));
auto temp = multvecmat(srcrowvec, op2);
if (temp.isUndefined()) {
temp.toUndef().append(STR("while processing left operand at row " << i));
temp.toUndef().append(STR("while processing left operand at row ", i));
return temp;
} else {
dstv.emplace_back(std::move(temp));
Expand All @@ -1090,11 +1090,11 @@ class multiply_visitor : public boost::static_visitor<Value>
}
return Value(std::move(dstv));
} else {
return Value::undef(STR("matrix*matrix requires left operand column count to match right operand row count (" << (*first1).toVector().size() << " != " << op2.size() << ')'));
return Value::undef(STR("matrix*matrix requires left operand column count to match right operand row count (", (*first1).toVector().size(), " != ", op2.size(), ')'));
}
}
}
return Value::undef(STR("undefined vector*vector multiplication where first elements are types " << (*first1).typeName() << " and " << (*first2).typeName() ));
return Value::undef(STR("undefined vector*vector multiplication where first elements are types ", (*first1).typeName(), " and ", (*first2).typeName() ));
}
};

Expand All @@ -1120,15 +1120,15 @@ Value Value::operator/(const Value& v) const
}
return std::move(dstv);
}
return Value::undef(STR("undefined operation (" << this->typeName() << " / " << v.typeName() << ")"));
return Value::undef(STR("undefined operation (", this->typeName(), " / ", v.typeName(), ")"));
}

Value Value::operator%(const Value& v) const
{
if (this->type() == Type::NUMBER && v.type() == Type::NUMBER) {
return fmod(boost::get<double>(this->value), boost::get<double>(v.value));
}
return Value::undef(STR("undefined operation (" << this->typeName() << " % " << v.typeName() << ")"));
return Value::undef(STR("undefined operation (", this->typeName(), " % ", v.typeName(), ")"));
}

Value Value::operator-() const
Expand All @@ -1142,15 +1142,15 @@ Value Value::operator-() const
}
return std::move(dstv);
}
return Value::undef(STR("undefined operation (-" << this->typeName() << ")"));
return Value::undef(STR("undefined operation (-", this->typeName(), ")"));
}

Value Value::operator^(const Value& v) const
{
if (this->type() == Type::NUMBER && v.type() == Type::NUMBER) {
return {pow(boost::get<double>(this->value), boost::get<double>(v.value))};
}
return Value::undef(STR("undefined operation (" << this->typeName() << " ^ " << v.typeName() << ")"));
return Value::undef(STR("undefined operation (", this->typeName(), " ^ ", v.typeName(), ")"));
}

/*
Expand Down Expand Up @@ -1180,7 +1180,7 @@ class bracket_visitor : public boost::static_visitor<Value>
Value operator()(const VectorType& vec, const double& idx) const {
const auto i = convert_to_uint32(idx);
if (i < vec.size()) return vec[i].clone();
return Value::undef(STR("index " << i << " out of bounds for vector of size " << vec.size()));
return Value::undef(STR("index ", i, " out of bounds for vector of size ", vec.size()));
}

Value operator()(const ObjectType& obj, const str_utf8_wrapper& key) const {
Expand All @@ -1199,7 +1199,7 @@ class bracket_visitor : public boost::static_visitor<Value>

template <typename T, typename U> Value operator()(const T& op1, const U& op2) const {
//std::cout << "generic bracket_visitor " << getTypeName(op1) << " " << getTypeName(op2) << "\n";
return Value::undef(STR("undefined operation " << getTypeName(op1) << "[" << getTypeName(op2) << "]"));
return Value::undef(STR("undefined operation ", getTypeName(op1), "[", getTypeName(op2), "]"));
}
};

Expand Down
8 changes: 4 additions & 4 deletions src/glview/OffscreenContextEGL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ std::string get_os_info()
if (uname(&u) < 0) {
return STR("OS info: unknown, uname() error\n");
} else {
return STR("OS info: " << u.sysname << " " << u.release << " " << u.version << "\n" <<
"Machine: " << u.machine);
return STR("OS info: ", u.sysname, " ", u.release, " ", u.version, "\n",
"Machine: ", u.machine);
}
return "";
}
Expand All @@ -74,8 +74,8 @@ std::string get_gl_info(EGLDisplay display)
char const *version = eglQueryString(display, EGL_VERSION);

return STR("GL context creator: EGL\n"
<< "EGL version: " << version << " (" << vendor << ")" << "\n"
<< get_os_info());
, "EGL version: ", version, " (", vendor, ")", "\n"
, get_os_info());
}

std::string offscreen_context_getinfo(OffscreenContext *ctx)
Expand Down
10 changes: 5 additions & 5 deletions src/glview/OffscreenContextGLX.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ std::string get_os_info()
if (uname(&u) < 0) {
return STR("OS info: unknown, uname() error\n");
} else {
return STR("OS info: " << u.sysname << " " << u.release << " " << u.version << "\n" <<
"Machine: " << u.machine);
return STR("OS info: ", u.sysname, " ", u.release, " ", u.version, "\n",
"Machine: ", u.machine);
}
return "";
}
Expand All @@ -90,9 +90,9 @@ std::string offscreen_context_getinfo(OffscreenContext *ctx)
int major, minor;
glXQueryVersion(ctx->xdisplay, &major, &minor);

return STR("GL context creator: GLX\n" <<
"PNG generator: lodepng\n" <<
"GLX version: " << major << "." << minor << "\n" <<
return STR("GL context creator: GLX\n",
"PNG generator: lodepng\n",
"GLX version: ", major, ".", minor, "\n",
get_os_info());
}

Expand Down

0 comments on commit 2d27703

Please sign in to comment.