USRP Hardware Driver and USRP Manual Version: 3.15.0.0-MacPorts-Release
UHD and USRP Manual
 
Loading...
Searching...
No Matches
block_id.hpp
Go to the documentation of this file.
1// Copyright 2014 Ettus Research LLC
2// Copyright 2018 Ettus Research, a National Instruments Company
3//
4// SPDX-License-Identifier: GPL-3.0-or-later
5//
6
7#ifndef INCLUDED_UHD_TYPES_BLOCK_ID_HPP
8#define INCLUDED_UHD_TYPES_BLOCK_ID_HPP
9
10#include <uhd/config.hpp>
11#include <stdint.h>
12#include <boost/shared_ptr.hpp>
13#include <iostream>
14#include <string>
15
16namespace uhd {
17struct fs_path;
18
19namespace rfnoc {
20
40{
41public:
43 block_id_t(const std::string& block_str);
47 block_id_t(const size_t device_no,
48 const std::string& block_name,
49 const size_t block_ctr = 0);
50
52 std::string to_string() const;
53
55 //
56 // Note: This only applies to the block *name*, not the entire block ID.
57 // Examples:
58 // * is_valid_blockname("FFT") will return true.
59 // * is_valid_blockname("FIR_Filter") will return false, because an underscore
60 // is not allowed in a block name.
61 //
62 // Internally, this matches the string with uhd::rfnoc::VALID_BLOCKNAME_REGEX.
63 static bool is_valid_blockname(const std::string& block_name);
64
66 //
67 // Note: This does necessary require a complete complete ID. If this returns
68 // true, then it is a valid input for block_id_t::match().
69 //
70 // Examples:
71 // * is_valid_block_id("FFT") will return true.
72 // * is_valid_block_id("0/Filter_1") will return true.
73 // * is_valid_block_id("0/Filter_Foo") will return false.
74 //
75 // Internally, this matches the string with uhd::rfnoc::VALID_BLOCKID_REGEX.
76 static bool is_valid_block_id(const std::string& block_id);
77
79 //
80 // A match is a less strict version of equality.
81 // Less specific block IDs will match more specific ones,
82 // e.g. "FFT" will match "0/FFT_1", "1/FFT_2", etc.
83 // "FFT_1" will only match the former, etc.
84 bool match(const std::string& block_str);
85
86 // Getters
87
89 std::string get() const
90 {
91 return to_string();
92 };
93
95 std::string get_local() const;
96
99
101 size_t get_device_no() const
102 {
103 return _device_no;
104 };
105
107 size_t get_block_count() const
108 {
109 return _block_ctr;
110 };
111
113 std::string get_block_name() const
114 {
115 return _block_name;
116 };
117
118 // Setters
119
121 // Returns true if successful (i.e. if string valid)
122 bool set(const std::string& new_name);
123
125 // and set_block_count() one after another, only if \p block_name is invalid, stops
126 // and returns false before chaning anything
127 bool set(const size_t device_no,
128 const std::string& block_name,
129 const size_t block_ctr = 0);
130
132 void set_device_no(size_t device_no)
133 {
134 _device_no = device_no;
135 };
136
138 bool set_block_name(const std::string& block_name);
139
141 void set_block_count(size_t count)
142 {
143 _block_ctr = count;
144 };
145
146 // Overloaded operators
147
149 block_id_t operator=(const std::string& new_name)
150 {
151 set(new_name);
152 return *this;
153 }
154
155 bool operator==(const block_id_t& block_id) const
156 {
157 return (_device_no == block_id.get_device_no())
158 and (_block_name == block_id.get_block_name())
159 and (_block_ctr == block_id.get_block_count());
160 }
161
162 bool operator!=(const block_id_t& block_id) const
163 {
164 return not(*this == block_id);
165 }
166
167 bool operator<(const block_id_t& block_id) const
168 {
169 return (_device_no < block_id.get_device_no()
170 or (_device_no == block_id.get_device_no()
171 and _block_name < block_id.get_block_name())
172 or (_device_no == block_id.get_device_no()
173 and _block_name == block_id.get_block_name()
174 and _block_ctr < block_id.get_block_count()));
175 }
176
177 bool operator>(const block_id_t& block_id) const
178 {
179 return (_device_no > block_id.get_device_no()
180 or (_device_no == block_id.get_device_no()
181 and _block_name > block_id.get_block_name())
182 or (_device_no == block_id.get_device_no()
183 and _block_name == block_id.get_block_name()
184 and _block_ctr > block_id.get_block_count()));
185 }
186
188 bool operator==(const std::string& block_id_str) const
189 {
190 return get() == block_id_str;
191 }
192
194 bool operator==(const char* block_id_str) const
195 {
196 std::string comp = std::string(block_id_str);
197 return *this == comp;
198 }
199
201 operator std::string() const
202 {
203 return to_string();
204 }
205
208 {
209 _block_ctr++;
210 return *this;
211 }
212
215 {
216 _block_ctr++;
217 return *this;
218 }
219
220private:
221 size_t _device_no;
222 std::string _block_name;
223 size_t _block_ctr;
224};
225
227inline std::ostream& operator<<(std::ostream& out, block_id_t block_id)
228{
229 out << block_id.to_string();
230 return out;
231}
232
233} // namespace rfnoc
234} // namespace uhd
235
236#endif /* INCLUDED_UHD_TYPES_BLOCK_ID_HPP */
Definition block_id.hpp:40
bool set(const std::string &new_name)
Set from string such as "0/FFT_1", "FFT_0", ...
void set_block_count(size_t count)
Set the block count.
Definition block_id.hpp:141
static bool is_valid_blockname(const std::string &block_name)
Check if a given string is valid as a block name.
bool operator==(const char *block_id_str) const
Check if a string matches the entire block ID (not like match())
Definition block_id.hpp:194
static bool is_valid_block_id(const std::string &block_id)
Check if a given string is valid as a block ID.
std::string get() const
Short for to_string()
Definition block_id.hpp:89
bool match(const std::string &block_str)
Check if block_str matches this block.
block_id_t(const std::string &block_str)
uhd::fs_path get_tree_root() const
Returns the property tree root for this block (e.g. "/mboards/0/xbar/FFT_1/")
size_t get_block_count() const
Return block count.
Definition block_id.hpp:107
bool operator!=(const block_id_t &block_id) const
Definition block_id.hpp:162
bool operator>(const block_id_t &block_id) const
Definition block_id.hpp:177
size_t get_device_no() const
Return device number.
Definition block_id.hpp:101
block_id_t operator++()
Increment the block count ("FFT_1" -> "FFT_2")
Definition block_id.hpp:207
std::string get_local() const
Like get(), but only returns the local part ("FFT_1")
bool operator==(const block_id_t &block_id) const
Definition block_id.hpp:155
std::string to_string() const
Return a string like this: "0/FFT_1" (includes all components, if set)
bool operator==(const std::string &block_id_str) const
Check if a string matches the entire block ID (not like match())
Definition block_id.hpp:188
block_id_t(const size_t device_no, const std::string &block_name, const size_t block_ctr=0)
block_id_t operator++(int)
Increment the block count ("FFT_1" -> "FFT_2")
Definition block_id.hpp:214
std::string get_block_name() const
Return block name.
Definition block_id.hpp:113
bool operator<(const block_id_t &block_id) const
Definition block_id.hpp:167
bool set_block_name(const std::string &block_name)
Set the block name. Will return false if invalid block string.
block_id_t operator=(const std::string &new_name)
Assignment: Works like set(std::string)
Definition block_id.hpp:149
bool set(const size_t device_no, const std::string &block_name, const size_t block_ctr=0)
Sets from individual compontents, like calling set_device_no(), set_block_name()
void set_device_no(size_t device_no)
Set the device number.
Definition block_id.hpp:132
#define UHD_RFNOC_API
Definition config.hpp:117
std::ostream & operator<<(std::ostream &out, block_id_t block_id)
Shortcut for << block_id.to_string()
Definition block_id.hpp:227
Definition build_info.hpp:13
Definition property_tree.hpp:200