3232
3333template <typename block_type>
3434BlockFactoryFunc block_factory () {
35- return [](int count, Model *model) -> Block * {
36- return new block_type (count, model);
35+ return [](int count, Model *model) -> std::shared_ptr< Block> {
36+ return std::make_shared< block_type> (count, model);
3737 };
3838}
3939
@@ -60,27 +60,27 @@ Model::Model() {
6060
6161Model::~Model () {}
6262
63- Block * Model::create_block (const std::string &block_type) {
63+ std::shared_ptr< Block> Model::create_block (const std::string &block_type) {
6464 // Get block from factory
6565 auto it = block_factory_map.find (block_type);
6666 if (it == block_factory_map.end ()) {
6767 throw std::runtime_error (" Invalid block type " + block_type);
6868 }
69- Block * block = it->second (block_count, this );
69+ std::shared_ptr< Block> block = it->second (block_count, this );
7070 return block;
7171}
7272
73- int Model::add_block (Block * block, const std::string_view &name,
73+ int Model::add_block (std::shared_ptr< Block> block, const std::string_view &name,
7474 const std::vector<int > &block_param_ids, bool internal) {
7575 // Set global parameter IDs
7676 block->setup_params_ (block_param_ids);
7777
7878 auto name_string = static_cast <std::string>(name);
7979
8080 if (internal) {
81- hidden_blocks.push_back (std::shared_ptr<Block>( block) );
81+ hidden_blocks.push_back (block);
8282 } else {
83- blocks.push_back (std::shared_ptr<Block>( block) );
83+ blocks.push_back (block);
8484 }
8585
8686 block_types.push_back (block->block_type );
0 commit comments