Commit 74b7d6d7 authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

python: do not instantiate component in Python initialization

parent 1cb74c54
......@@ -37,6 +37,7 @@
#include <cps/PowerComponent.h>
#include <cps/Attribute.h>
#include <dpsim/Utils.h>
#include <dpsim/Python/Node.h>
#include <dpsim/Python/Utils.h>
......@@ -120,26 +121,8 @@ namespace Python {
{
std::stringstream doc;
T comp("uid", "name");
doc << comp.type() << "(name, nodes, **attributes)" << std::endl
doc << Utils::type<T>() << "(name, nodes, **attributes)" << std::endl
<< "Construct a new component with a given name and list of nodes." << std::endl;
#if 0
<< comp.description() << std::endl
<< std::endl;
for (auto& it : comp.attributes()) {
auto name = it.first;
auto attr = it.second;
if (!(attr->flags() & CPS::Flags::write))
continue;
doc << ":param " << name << ": " << attr->description() << std::endl;
}
<< ":returns: A new `Component` representing this " << comp.type() << "." << std::endl;
#endif
auto docstr = new CPS::String(doc.str());
......
......@@ -21,6 +21,10 @@
#pragma once
#if defined(__GNUC__) && !defined(__clang__)
#include <cxxabi.h>
#endif
#include <list>
#include <dpsim/Timer.h>
......@@ -85,4 +89,35 @@ public:
std::map<String, Real> options;
};
namespace Utils {
template<typename T>
static CPS::String type(const CPS::String &stripPrefix = "CPS::") {
Int status = 1;
const char *mangled, *unmangled;
mangled = typeid(T).name();
#ifdef _MSC_VER
return CPS::String(mangled);
#else
unmangled = abi::__cxa_demangle(mangled, NULL, NULL, &status);
if (status)
return mangled;
else {
CPS::String type = unmangled;
delete unmangled;
if (type.find(stripPrefix) == 0)
type = type.substr(stripPrefix.size());
return type;
}
#endif
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment