MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / anyToString

Function anyToString

src/App/Expression.cpp:567–596  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

565}
566
567std::string anyToString(const App::any &value) {
568 if (is_type(value, typeid(bool))) {
569 return (cast<bool>(value) ? QObject::tr("True") : QObject::tr("False")).toStdString();
570 }
571 else if (is_type(value, typeid(int))) {
572 return std::to_string(cast<int>(value));
573 }
574 else if (is_type(value, typeid(long))) {
575 return std::to_string(cast<long>(value));
576 }
577 else if (is_type(value, typeid(float)) || is_type(value, typeid(double))) {
578 Quantity q(is_type(value, typeid(float)) ? cast<float>(value) : cast<double>(value));
579 return q.getUserString();
580 }
581 else if (is_type(value, typeid(Quantity))) {
582 const Quantity& q = cast<Quantity>(value);
583 return q.getUserString();
584 }
585 else if (is_type(value, typeid(const char*))) {
586 const char* p = cast<const char*>(value);
587 return p ? std::string(p) : QObject::tr("Null").toStdString();
588 }
589 else if (is_type(value, typeid(std::string))) {
590 return cast<std::string>(value);
591 }
592 else {
593 Base::PyGILStateLocker lock;
594 return pyObjectFromAny(value).as_string();
595 }
596}
597
598bool isAnyEqual(const App::any &v1, const App::any &v2) {
599 if(v1.empty())

Callers 3

setPathValueMethod · 0.85
onChangeMethod · 0.85
checkExpressionMethod · 0.85

Calls 6

is_typeFunction · 0.85
pyObjectFromAnyFunction · 0.85
toStdStringMethod · 0.80
to_stringFunction · 0.50
getUserStringMethod · 0.45
as_stringMethod · 0.45

Tested by

no test coverage detected