GNU Radio C++ API Reference 3.10.12.0
The Free & Open Software Radio Ecosystem
 
Loading...
Searching...
No Matches
buffer_type.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2020 Free Software Foundation, Inc.
4 *
5 * This file is part of GNU Radio
6 *
7 * SPDX-License-Identifier: GPL-3.0-or-later
8 *
9 */
10
11#ifndef INCLUDED_GR_RUNTIME_CUSTOM_BUFFER_TYPE_H
12#define INCLUDED_GR_RUNTIME_CUSTOM_BUFFER_TYPE_H
13
14#include <gnuradio/api.h>
16
17#include <cstdint>
18#include <functional>
19#include <string>
20#include <vector>
21
22namespace gr {
23
24/*!
25 * \brief Base class for describing a buffer's type.
26 */
28{
29public:
30 virtual ~buffer_type_base(){};
31
32 // Do not allow copying or assignment
33 // buffer_type_base(buffer_type_base const&) = delete;
34
35 // Temporarily define copy constructor to work around pybind issue with
36 // default non-copyable function argument
37 buffer_type_base(buffer_type_base const& other) : d_name(other.d_name) {}
38
39 void operator=(buffer_type_base const&) = delete;
40
41 // Allow equality and inequality comparison
42 bool operator==(const buffer_type_base& other) const
43 {
44 return d_name == other.d_name;
45 }
46
47 bool operator!=(const buffer_type_base& other) const
48 {
49 return d_name != other.d_name;
50 }
51
52 // Do not allow other comparison (just in case)
53 bool operator<(const buffer_type_base& other) = delete;
54 bool operator>(const buffer_type_base& other) = delete;
55 bool operator<=(const buffer_type_base& other) = delete;
56 bool operator>=(const buffer_type_base& other) = delete;
57 /*!
58 * \brief Get the human-readable name of the type
59 */
60 const std::string& name() const { return d_name; }
61
62 /*!
63 * \brief Make and return a buffer subclass of the corresponding type
64 */
65 virtual buffer_sptr
66 make_buffer([[maybe_unused]] int nitems,
67 [[maybe_unused]] size_t sizeof_item,
68 [[maybe_unused]] uint64_t downstream_lcm_nitems,
69 [[maybe_unused]] uint32_t downstream_max_out_mult,
70 [[maybe_unused]] block_sptr link = block_sptr(),
71 [[maybe_unused]] block_sptr buf_owner = block_sptr()) const
72 {
73 // NOTE: this is *never* intended to be called directly, instead the overridden
74 // version from a derived class (created from the template below) will be
75 // called.
76 return nullptr;
77 }
78
79protected:
80 const std::string d_name;
81
82 buffer_type_base(const std::string name) : d_name(name) {}
83};
84
86typedef std::vector<std::reference_wrapper<const buffer_type_base>> gr_vector_buffer_type;
87
88/*!
89 * \brief Template used to create buffer types. Note that the factory_class parameter
90 * must contain a static function make_buffer() that matches the signature below
91 * and will be used to create instances of the corresponding buffer type.
92 */
93template <typename classname, typename factory_class>
94struct buftype : public buffer_type_base {
95public:
96 using factory = factory_class;
97 buffer_sptr make_buffer(int nitems,
98 size_t sizeof_item,
99 uint64_t downstream_lcm_nitems,
100 uint32_t downstream_max_out_mult,
101 block_sptr link = block_sptr(),
102 block_sptr buf_owner = block_sptr()) const override
103 {
104 return factory::make_buffer(nitems,
105 sizeof_item,
106 downstream_lcm_nitems,
107 downstream_max_out_mult,
108 link,
109 buf_owner);
110 }
111
112 buftype() : buffer_type_base(typeid(classname).name()) {}
113};
114
115} // namespace gr
116
117#endif /* INCLUDED_GR_RUNTIME_CUSTOM_BUFFER_TYPE_H */
Base class for describing a buffer's type.
Definition buffer_type.h:28
virtual buffer_sptr make_buffer(int nitems, size_t sizeof_item, uint64_t downstream_lcm_nitems, uint32_t downstream_max_out_mult, block_sptr link=block_sptr(), block_sptr buf_owner=block_sptr()) const
Make and return a buffer subclass of the corresponding type.
Definition buffer_type.h:66
const std::string d_name
Definition buffer_type.h:80
bool operator>=(const buffer_type_base &other)=delete
bool operator<=(const buffer_type_base &other)=delete
bool operator!=(const buffer_type_base &other) const
Definition buffer_type.h:47
buffer_type_base(const std::string name)
Definition buffer_type.h:82
const std::string & name() const
Get the human-readable name of the type.
Definition buffer_type.h:60
bool operator<(const buffer_type_base &other)=delete
buffer_type_base(buffer_type_base const &other)
Definition buffer_type.h:37
virtual ~buffer_type_base()
Definition buffer_type.h:30
bool operator>(const buffer_type_base &other)=delete
void operator=(buffer_type_base const &)=delete
bool operator==(const buffer_type_base &other) const
Definition buffer_type.h:42
#define GR_RUNTIME_API
Definition gnuradio-runtime/include/gnuradio/api.h:18
GNU Radio logging wrapper.
Definition basic_block.h:29
const buffer_type_base & buffer_type
Definition buffer_type.h:85
std::vector< std::reference_wrapper< const buffer_type_base > > gr_vector_buffer_type
Definition buffer_type.h:86
Template used to create buffer types. Note that the factory_class parameter must contain a static fun...
Definition buffer_type.h:94
buffer_sptr make_buffer(int nitems, size_t sizeof_item, uint64_t downstream_lcm_nitems, uint32_t downstream_max_out_mult, block_sptr link=block_sptr(), block_sptr buf_owner=block_sptr()) const override
Make and return a buffer subclass of the corresponding type.
Definition buffer_type.h:97
buftype()
Definition buffer_type.h:112
factory_class factory
Definition buffer_type.h:96