Skip to content

Commit

Permalink
Make properties message field optional for block creation
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Čukić <ivan.cukic@kdab.com>
  • Loading branch information
ivan-cukic committed Oct 28, 2024
1 parent a9f7d06 commit 2465afb
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions core/include/gnuradio-4.0/Graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <gnuradio-4.0/PluginLoader.hpp>
#include <gnuradio-4.0/Port.hpp>
#include <gnuradio-4.0/Sequence.hpp>
#include <gnuradio-4.0/meta/typelist.hpp>
#include <gnuradio-4.0/meta/reflection.hpp>
#include <gnuradio-4.0/meta/typelist.hpp>
#include <gnuradio-4.0/thread/thread_pool.hpp>

#include <algorithm>
Expand Down Expand Up @@ -248,7 +248,13 @@ class Graph : public gr::Block<Graph> {
const auto& data = message.data.value();
const std::string& type = std::get<std::string>(data.at("type"s));
const std::string& parameters = std::get<std::string>(data.at("parameters"s));
const property_map& properties = std::get<property_map>(data.at("properties"s));
const property_map& properties = [&] {
if (auto it = data.find("properties"s); it != data.end()) {
return std::get<property_map>(it->second);
} else {
return property_map{};
}
}();

auto& newBlock = emplaceBlock(type, parameters, properties);

Expand Down Expand Up @@ -281,7 +287,13 @@ class Graph : public gr::Block<Graph> {
const std::string& uniqueName = std::get<std::string>(data.at("uniqueName"s));
const std::string& type = std::get<std::string>(data.at("type"s));
const std::string& parameters = std::get<std::string>(data.at("parameters"s));
const property_map& properties = std::get<property_map>(data.at("properties"s));
const property_map& properties = [&] {
if (auto it = data.find("properties"s); it != data.end()) {
return std::get<property_map>(it->second);
} else {
return property_map{};
}
}();

auto it = std::ranges::find_if(_blocks, [&uniqueName](const auto& block) { return block->uniqueName() == uniqueName; });
if (it == _blocks.end()) {
Expand Down

0 comments on commit 2465afb

Please sign in to comment.