summaryrefslogtreecommitdiff
path: root/gnuradio-runtime
diff options
context:
space:
mode:
authorThomas Habets <thomas@habets.se>2020-04-14 17:45:11 +0100
committerMarcus Müller <marcus@hostalia.de>2020-07-30 18:12:44 +0200
commitd16f2d3d4c46a177475053dff173557ad34290dc (patch)
tree6ff5b4501abd1ec720e8c95e29de9ab5812c5558 /gnuradio-runtime
parentaef17664ba3047acaab71a61adb60aee4ea7c2fc (diff)
blocks: move the `new` from the block `::make()` to core
This includes the first edit of a block, so that it's easy to review. A following commit changes this globally.
Diffstat (limited to 'gnuradio-runtime')
-rw-r--r--gnuradio-runtime/include/gnuradio/sptr_magic.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/gnuradio-runtime/include/gnuradio/sptr_magic.h b/gnuradio-runtime/include/gnuradio/sptr_magic.h
index fdcb68f91d..6800ea1db7 100644
--- a/gnuradio-runtime/include/gnuradio/sptr_magic.h
+++ b/gnuradio-runtime/include/gnuradio/sptr_magic.h
@@ -6,6 +6,10 @@
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
+ * The magic here is a way of constructing std::shared_ptr<> to blocks, in a way
+ * that allows the constructors of those blocks to reference them.
+ * This is only used for blocks that derive from hier_blocks2, so that they can
+ * create and connect sub-blocks in their constructor.
*/
#ifndef INCLUDED_GR_RUNTIME_SPTR_MAGIC_H
@@ -41,6 +45,17 @@ std::shared_ptr<T> get_initial_sptr(T* p)
return std::dynamic_pointer_cast<T, gr::basic_block>(
detail::sptr_magic::fetch_initial_sptr(p));
}
+
+/*
+ * \brief GNU Radio version of std::make_shared<> that also provides magic. For
+ * blocks that don't reference self() in any constructor it's equivalent to
+ * std::make_shared<>.
+ */
+template <typename T, typename... Args>
+std::shared_ptr<T> make_block_sptr(Args&&... args)
+{
+ return get_initial_sptr(new T(std::forward<Args>(args)...));
+}
} // namespace gnuradio
#endif /* INCLUDED_GR_RUNTIME_SPTR_MAGIC_H */