|
@@ -13,8 +13,8 @@ namespace mdd{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- bool ProcessorBase::configure(const std::string& config) {
|
|
|
- json jconfig = json::parse(config);
|
|
|
+ bool ProcessorBase::configure(const json& config) {
|
|
|
+ json jconfig = config;
|
|
|
bool sucess = false;
|
|
|
auto jit = jconfig.find("GUI");
|
|
|
if (jit != jconfig.end())
|
|
@@ -30,9 +30,13 @@ namespace mdd{
|
|
|
{
|
|
|
for (size_t i = 0; i < jit.value().size(); i++)
|
|
|
{
|
|
|
- inputs.push_back(std::make_shared<Parameter>(this));
|
|
|
- inputs.back()->setName(jit2.value()["type"].get<std::string>());
|
|
|
- inputs.back()->setAppendix(jit2.value()["appendix"].get<int>());
|
|
|
+ inputs.push_back(std::make_shared<Parameter>());
|
|
|
+ if (auto input_ptr = inputs.back())
|
|
|
+ {
|
|
|
+ input_ptr->setParent(shared_from_this());
|
|
|
+ input_ptr->setName(jit2.value()["type"].get<std::string>());
|
|
|
+ input_ptr->setAppendix(jit2.value()["appendix"].get<int>());
|
|
|
+ }
|
|
|
}
|
|
|
sucess = true;
|
|
|
}
|
|
@@ -42,9 +46,13 @@ namespace mdd{
|
|
|
{
|
|
|
for (size_t i = 0; i < jit.value().size(); i++)
|
|
|
{
|
|
|
- outputs.push_back(std::make_shared<Parameter>(this));
|
|
|
- outputs.back()->setName(jit2.value()["type"].get<std::string>());
|
|
|
- outputs.back()->setAppendix(jit2.value()["appendix"].get<int>());
|
|
|
+ outputs.push_back(std::make_shared<Parameter>());
|
|
|
+ if (auto output_ptr = outputs.back())
|
|
|
+ {
|
|
|
+ output_ptr->setParent(shared_from_this());
|
|
|
+ output_ptr->setName(jit2.value()["type"].get<std::string>());
|
|
|
+ output_ptr->setAppendix(jit2.value()["appendix"].get<int>());
|
|
|
+ }
|
|
|
}
|
|
|
sucess = true;
|
|
|
}
|
|
@@ -57,9 +65,13 @@ namespace mdd{
|
|
|
{
|
|
|
const json& jmodule = jit.value()[i];
|
|
|
addModule(regi.generateModule(jmodule["id"].get<std::string>()));
|
|
|
- modules.back()->setName(jmodule["type"].get<std::string>());
|
|
|
- modules.back()->setAppendix(jmodule["appendix"].get<int>());
|
|
|
- modules.back()->load(jmodule["load"]);
|
|
|
+ if (auto module_ptr = modules.back())
|
|
|
+ {
|
|
|
+ module_ptr->setParent(shared_from_this());
|
|
|
+ module_ptr->setName(jmodule["type"].get<std::string>());
|
|
|
+ module_ptr->setAppendix(jmodule["appendix"].get<int>());
|
|
|
+ module_ptr->load(jmodule["load"]);
|
|
|
+ }
|
|
|
}
|
|
|
sucess = true;
|
|
|
}
|
|
@@ -85,15 +97,29 @@ namespace mdd{
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- const std::string& ProcessorBase::getConfiguration() {
|
|
|
+ const json& ProcessorBase::getConfiguration() {
|
|
|
//update module apendix ?
|
|
|
- return _base_config.dump();
|
|
|
+ return _base_config;
|
|
|
}
|
|
|
|
|
|
std::string ProcessorBase::getType() {
|
|
|
return type;
|
|
|
}
|
|
|
|
|
|
+ void ProcessorBase::setParent(std::shared_ptr<IModule> parent) {
|
|
|
+ _parent = parent;
|
|
|
+ }
|
|
|
+
|
|
|
+ std::vector<std::string> ProcessorBase::getParentID() {
|
|
|
+ std::vector<std::string> ret;
|
|
|
+ if (auto parent_ptr = _parent.lock())
|
|
|
+ {
|
|
|
+ ret = parent_ptr->getParentID();
|
|
|
+ ret.push_back(parent_ptr->getID());
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
std::string ProcessorBase::getGeneratorKey() {
|
|
|
return key;
|
|
|
}
|
|
@@ -123,13 +149,17 @@ namespace mdd{
|
|
|
|
|
|
std::string ProcessorBase::addModule(std::shared_ptr<IModule> module){
|
|
|
modules.emplace_back(module);
|
|
|
- modules.back()->setAppendix(modules.size()-1);
|
|
|
- return modules.back()->getID();
|
|
|
+ if (auto module_ptr = modules.back())
|
|
|
+ {
|
|
|
+ module_ptr->setParent(shared_from_this());
|
|
|
+ module_ptr->setAppendix(modules.size() - 1);
|
|
|
+ return module_ptr->getID();
|
|
|
+ }
|
|
|
+ return "";
|
|
|
}
|
|
|
|
|
|
void ProcessorBase::removeModule(std::shared_ptr<IModule> module)
|
|
|
{
|
|
|
-
|
|
|
for (auto it = modules.begin(); it != modules.end(); ++it) {
|
|
|
if ((*it) == module)
|
|
|
{
|
|
@@ -182,10 +212,13 @@ namespace mdd{
|
|
|
else {
|
|
|
for (size_t i = 0; i < modules.size(); i++)
|
|
|
{
|
|
|
- if (modules[i]->getID() == str_module_id)
|
|
|
+ if (auto module_ptr = modules[i])
|
|
|
{
|
|
|
- out_ptr = modules[i]->getOutput(str_output_id);
|
|
|
- break;
|
|
|
+ if (module_ptr->getID() == str_module_id)
|
|
|
+ {
|
|
|
+ out_ptr = module_ptr->getOutput(str_output_id);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -204,11 +237,14 @@ namespace mdd{
|
|
|
else {
|
|
|
for (size_t i = 0; i < modules.size(); i++)
|
|
|
{
|
|
|
- if (modules[i]->getID() == str_module_id)
|
|
|
+ if (auto module_ptr = modules[i])
|
|
|
{
|
|
|
- auto in_ptr = modules[i]->getInput(str_input_id);
|
|
|
- in_ptr->connect(out_ptr);
|
|
|
- break;
|
|
|
+ if (module_ptr->getID() == str_module_id)
|
|
|
+ {
|
|
|
+ auto in_ptr = module_ptr->getInput(str_input_id);
|
|
|
+ in_ptr->connect(out_ptr);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -269,8 +305,11 @@ namespace mdd{
|
|
|
{
|
|
|
addModule(regi.generateProcessor(jmodule["key"]));
|
|
|
}
|
|
|
- modules.back()->load(jmodule);
|
|
|
- int check = 0;
|
|
|
+ if (auto module_ptr = modules.back())
|
|
|
+ {
|
|
|
+ module_ptr->setParent(shared_from_this());
|
|
|
+ module_ptr->load(jmodule);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -342,23 +381,30 @@ namespace mdd{
|
|
|
ret["params"]["inputs"];
|
|
|
for (size_t i = 0; i < inputs.size(); i++)
|
|
|
{
|
|
|
- json sub;
|
|
|
- sub["type"] = inputs[i]->getType();
|
|
|
- sub["appendix"] = inputs[i]->getAppendix();
|
|
|
- ret["params"]["inputs"].push_back(sub);
|
|
|
+ if (auto in_ptr = inputs[i])
|
|
|
+ {
|
|
|
+ json sub;
|
|
|
+ sub["type"] = in_ptr->getType();
|
|
|
+ sub["appendix"] = in_ptr->getAppendix();
|
|
|
+ ret["params"]["inputs"].push_back(sub);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
ret["params"]["outputs"];
|
|
|
for (size_t i = 0; i < outputs.size(); i++)
|
|
|
{
|
|
|
- json sub;
|
|
|
- sub["type"] = outputs[i]->getType();
|
|
|
- sub["appendix"] = outputs[i]->getAppendix();
|
|
|
- ret["params"]["outputs"].push_back(sub);
|
|
|
+ if (auto out_ptr = outputs[i])
|
|
|
+ {
|
|
|
+ json sub;
|
|
|
+ sub["type"] = out_ptr->getType();
|
|
|
+ sub["appendix"] = out_ptr->getAppendix();
|
|
|
+ ret["params"]["outputs"].push_back(sub);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
for (auto& in : processor_inputs)
|
|
|
{
|
|
|
+ in->setParent(shared_from_this());
|
|
|
ret["inputs"].push_back(in->dump());
|
|
|
}
|
|
|
for (auto& in : inputs)
|
|
@@ -368,6 +414,7 @@ namespace mdd{
|
|
|
|
|
|
for (auto& out : processor_outputs)
|
|
|
{
|
|
|
+ out->setParent(shared_from_this());
|
|
|
ret["outputs"].push_back(out->dump());
|
|
|
}
|
|
|
for (auto& out : outputs)
|
|
@@ -376,28 +423,36 @@ namespace mdd{
|
|
|
}
|
|
|
for (auto& mod : modules)
|
|
|
{
|
|
|
- if (mod->getType()=="module")
|
|
|
- {
|
|
|
- ret["modules"].push_back(mod->dump());
|
|
|
- }
|
|
|
- else
|
|
|
+ if (auto module_ptr = mod)
|
|
|
{
|
|
|
- ret["modules"].push_back(mod->dump());
|
|
|
+ if (module_ptr->getType() == "module")
|
|
|
+ {
|
|
|
+ ret["modules"].push_back(module_ptr->dump());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ret["modules"].push_back(module_ptr->dump());
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+ }
|
|
|
|
|
|
- for (size_t j = 0; j < mod->getNumOutputs(); j++)
|
|
|
+ for (auto& mod : modules)
|
|
|
+ {
|
|
|
+ if (auto module_ptr = mod)
|
|
|
{
|
|
|
- auto input_connections = mod->getOutput(j)->getConnections();
|
|
|
- if (!input_connections.empty())
|
|
|
+ for (size_t j = 0; j < module_ptr->getNumOutputs(); j++)
|
|
|
{
|
|
|
- json connect;
|
|
|
- connect["output"] = mod->getOutput(j)->getIdentifier();
|
|
|
- for (size_t k = 0; k < input_connections.size(); k++)
|
|
|
+ auto input_connections = module_ptr->getOutput(j)->getConnections();
|
|
|
+ if (!input_connections.empty())
|
|
|
{
|
|
|
- connect["inputs"].push_back(input_connections[k]->getIdentifier());
|
|
|
+ json connect;
|
|
|
+ connect["output"] = module_ptr->getOutput(j)->getIdentifier();
|
|
|
+ for (size_t k = 0; k < input_connections.size(); k++)
|
|
|
+ {
|
|
|
+ connect["inputs"].push_back(input_connections[k]->getIdentifier());
|
|
|
+ }
|
|
|
+ ret["connections"].push_back(connect);
|
|
|
}
|
|
|
- ret["connections"].push_back(connect);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -409,7 +464,7 @@ namespace mdd{
|
|
|
jID["name"] = _name;
|
|
|
jID["appendix"] = getAppendix();
|
|
|
jID["type"] = type;
|
|
|
- jID["prefix"] = std::vector<std::string>();
|
|
|
+ jID["prefix"] = getParentID();
|
|
|
return jID;
|
|
|
}
|
|
|
|