Skip to content

Commit

Permalink
Update block generation
Browse files Browse the repository at this point in the history
  • Loading branch information
kharold23 committed Jul 31, 2024
1 parent 444960c commit f7f81ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/model/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,27 @@ Model::Model() {

Model::~Model() {}

Block *Model::create_block(const std::string &block_type) {
std::shared_ptr<Block> Model::create_block(const std::string &block_type) {
// Get block from factory
auto it = block_factory_map.find(block_type);
if (it == block_factory_map.end()) {
throw std::runtime_error("Invalid block type " + block_type);
}
std::shared_ptr<Block> block = it->second(block_count, this);
return block.get();
return block;
}

int Model::add_block(Block *block, const std::string_view &name,
int Model::add_block(std::shared_ptr<Block> block, const std::string_view &name,
const std::vector<int> &block_param_ids, bool internal) {
// Set global parameter IDs
block->setup_params_(block_param_ids);

auto name_string = static_cast<std::string>(name);

if (internal) {
hidden_blocks.push_back(std::shared_ptr<Block>(block));
hidden_blocks.push_back(block);
} else {
blocks.push_back(std::shared_ptr<Block>(block));
blocks.push_back(block);
}

block_types.push_back(block->block_type);
Expand Down
4 changes: 2 additions & 2 deletions src/model/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Model {
* @param block_name The block name (defined in block_factory_map)
* @return int Global ID of the block
*/
Block *create_block(const std::string &block_name);
std::shared_ptr<Block> create_block(const std::string &block_name);

/**
* @brief Add a block to the model (without parameters)
Expand All @@ -110,7 +110,7 @@ class Model {
* @param internal Toggle whether block is internal
* @return int Global ID of the block
*/
int add_block(Block *block, const std::string_view &name,
int add_block(std::shared_ptr<Block> block, const std::string_view &name,
const std::vector<int> &block_param_ids, bool internal = false);

/**
Expand Down

0 comments on commit f7f81ff

Please sign in to comment.