USRP Hardware Driver and Device Manual  Version: 4.11.0.0-0-g0d7ed3b1
UHD and USRP Manual
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 // Copyright 2019 Ettus Research, a National Instruments Company
4 //
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7 
8 #pragma once
9 
10 #include <uhd/config.hpp>
11 #include <stdint.h>
12 #include <iostream>
13 #include <memory>
14 #include <string>
15 
16 namespace uhd {
17 struct fs_path;
18 
19 namespace rfnoc {
20 
40 {
41 public:
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 
65  static bool is_valid_blockname(const std::string& block_name);
66 
79  static bool is_valid_block_id(const std::string& block_id);
80 
88  bool match(const std::string& block_str);
89 
90  // Getters
91 
93  std::string get() const
94  {
95  return to_string();
96  };
97 
99  std::string get_local() const;
100 
103 
105  size_t get_device_no() const
106  {
107  return _device_no;
108  };
109 
111  size_t get_block_count() const
112  {
113  return _block_ctr;
114  };
115 
117  std::string get_block_name() const
118  {
119  return _block_name;
120  };
121 
122  // Setters
123 
127  bool set(const std::string& new_name);
128 
133  bool set(const size_t device_no,
134  const std::string& block_name,
135  const size_t block_ctr = 0);
136 
138  void set_device_no(size_t device_no)
139  {
140  _device_no = device_no;
141  };
142 
144  bool set_block_name(const std::string& block_name);
145 
147  void set_block_count(size_t count)
148  {
149  _block_ctr = count;
150  };
151 
152  // Overloaded operators
153 
155  block_id_t operator=(const std::string& new_name)
156  {
157  set(new_name);
158  return *this;
159  }
160 
161  bool operator==(const block_id_t& block_id) const
162  {
163  return (_device_no == block_id.get_device_no())
164  and (_block_name == block_id.get_block_name())
165  and (_block_ctr == block_id.get_block_count());
166  }
167 
168  bool operator!=(const block_id_t& block_id) const
169  {
170  return not(*this == block_id);
171  }
172 
173  bool operator<(const block_id_t& block_id) const
174  {
175  return (_device_no < block_id.get_device_no()
176  or (_device_no == block_id.get_device_no()
177  and _block_name < block_id.get_block_name())
178  or (_device_no == block_id.get_device_no()
179  and _block_name == block_id.get_block_name()
180  and _block_ctr < block_id.get_block_count()));
181  }
182 
183  bool operator>(const block_id_t& block_id) const
184  {
185  return (_device_no > block_id.get_device_no()
186  or (_device_no == block_id.get_device_no()
187  and _block_name > block_id.get_block_name())
188  or (_device_no == block_id.get_device_no()
189  and _block_name == block_id.get_block_name()
190  and _block_ctr > block_id.get_block_count()));
191  }
192 
194  bool operator==(const std::string& block_id_str) const
195  {
196  return get() == block_id_str;
197  }
198 
200  bool operator==(const char* block_id_str) const
201  {
202  std::string comp = std::string(block_id_str);
203  return *this == comp;
204  }
205 
207  operator std::string() const
208  {
209  return to_string();
210  }
211 
214  {
215  _block_ctr++;
216  return *this;
217  }
218 
221  {
222  _block_ctr++;
223  return *this;
224  }
225 
226 private:
227  size_t _device_no;
228  std::string _block_name;
229  size_t _block_ctr;
230 };
231 
233 inline std::ostream& operator<<(std::ostream& out, block_id_t block_id)
234 {
235  out << block_id.to_string();
236  return out;
237 }
238 
239 } // namespace rfnoc
240 } // namespace uhd
Definition: block_id.hpp:40
bool set(const std::string &new_name)
Set from string such as "0/FFT#1", "FFT#0", ... Returns true if successful (i.e. if string valid)
void set_block_count(size_t count)
Set the block count.
Definition: block_id.hpp:147
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:200
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:93
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:111
bool operator!=(const block_id_t &block_id) const
Definition: block_id.hpp:168
bool operator>(const block_id_t &block_id) const
Definition: block_id.hpp:183
size_t get_device_no() const
Return device number.
Definition: block_id.hpp:105
block_id_t operator++()
Increment the block count ("FFT#1" -> "FFT_2")
Definition: block_id.hpp:213
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:161
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:194
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:220
std::string get_block_name() const
Return block name.
Definition: block_id.hpp:117
bool operator<(const block_id_t &block_id) const
Definition: block_id.hpp:173
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:155
bool set(const size_t device_no, const std::string &block_name, const size_t block_ctr=0)
void set_device_no(size_t device_no)
Set the device number.
Definition: block_id.hpp:138
#define UHD_API
Definition: config.h:87
std::ostream & operator<<(std::ostream &out, block_id_t block_id)
Shortcut for << block_id.to_string()
Definition: block_id.hpp:233
Definition: build_info.hpp:12
Definition: property_tree.hpp:207