USRP Hardware Driver and USRP Manual  Version: 3.12.0.0-0-unknown
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 //
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 
16 namespace uhd {
17  struct fs_path;
18 
19  namespace rfnoc {
20 
40  {
41  public:
42  block_id_t();
43  block_id_t(const std::string &block_str);
47  block_id_t(const size_t device_no, const std::string &block_name, const size_t block_ctr=0);
48 
50  std::string to_string() const;
51 
53  //
54  // Note: This only applies to the block *name*, not the entire block ID.
55  // Examples:
56  // * is_valid_blockname("FFT") will return true.
57  // * is_valid_blockname("FIR_Filter") will return false, because an underscore
58  // is not allowed in a block name.
59  //
60  // Internally, this matches the string with uhd::rfnoc::VALID_BLOCKNAME_REGEX.
61  static bool is_valid_blockname(const std::string &block_name);
62 
64  //
65  // Note: This does necessary require a complete complete ID. If this returns
66  // true, then it is a valid input for block_id_t::match().
67  //
68  // Examples:
69  // * is_valid_block_id("FFT") will return true.
70  // * is_valid_block_id("0/Filter_1") will return true.
71  // * is_valid_block_id("0/Filter_Foo") will return false.
72  //
73  // Internally, this matches the string with uhd::rfnoc::VALID_BLOCKID_REGEX.
74  static bool is_valid_block_id(const std::string &block_id);
75 
77  //
78  // A match is a less strict version of equality.
79  // Less specific block IDs will match more specific ones,
80  // e.g. "FFT" will match "0/FFT_1", "1/FFT_2", etc.
81  // "FFT_1" will only match the former, etc.
82  bool match(const std::string &block_str);
83 
84  // Getters
85 
87  std::string get() const { return to_string(); };
88 
90  std::string get_local() const;
91 
93  uhd::fs_path get_tree_root() const;
94 
96  size_t get_device_no() const { return _device_no; };
97 
99  size_t get_block_count() const { return _block_ctr; };
100 
102  std::string get_block_name() const { return _block_name; };
103 
104  // Setters
105 
107  // Returns true if successful (i.e. if string valid)
108  bool set(const std::string &new_name);
109 
111  // and set_block_count() one after another, only if \p block_name is invalid, stops
112  // and returns false before chaning anything
113  bool set(const size_t device_no, const std::string &block_name, const size_t block_ctr=0);
114 
116  void set_device_no(size_t device_no) { _device_no = device_no; };
117 
119  bool set_block_name(const std::string &block_name);
120 
122  void set_block_count(size_t count) { _block_ctr = count; };
123 
124  // Overloaded operators
125 
127  block_id_t operator = (const std::string &new_name) {
128  set(new_name);
129  return *this;
130  }
131 
132  bool operator == (const block_id_t &block_id) const {
133  return (_device_no == block_id.get_device_no())
134  and (_block_name == block_id.get_block_name())
135  and (_block_ctr == block_id.get_block_count());
136  }
137 
138  bool operator != (const block_id_t &block_id) const {
139  return not (*this == block_id);
140  }
141 
142  bool operator < (const block_id_t &block_id) const {
143  return (
144  _device_no < block_id.get_device_no()
145  or (_device_no == block_id.get_device_no() and _block_name < block_id.get_block_name())
146  or (_device_no == block_id.get_device_no() and _block_name == block_id.get_block_name() and _block_ctr < block_id.get_block_count())
147  );
148  }
149 
150  bool operator > (const block_id_t &block_id) const {
151  return (
152  _device_no > block_id.get_device_no()
153  or (_device_no == block_id.get_device_no() and _block_name > block_id.get_block_name())
154  or (_device_no == block_id.get_device_no() and _block_name == block_id.get_block_name() and _block_ctr > block_id.get_block_count())
155  );
156  }
157 
159  bool operator == (const std::string &block_id_str) const {
160  return get() == block_id_str;
161  }
162 
164  bool operator == (const char *block_id_str) const {
165  std::string comp = std::string(block_id_str);
166  return *this == comp;
167  }
168 
170  operator std::string() const {
171  return to_string();
172  }
173 
176  _block_ctr++;
177  return *this;
178  }
179 
182  _block_ctr++;
183  return *this;
184  }
185 
186  private:
187  size_t _device_no;
188  std::string _block_name;
189  size_t _block_ctr;
190  };
191 
193  inline std::ostream& operator<< (std::ostream& out, block_id_t block_id) {
194  out << block_id.to_string();
195  return out;
196  }
197 
198 }} //namespace uhd::rfnoc
199 
200 #endif /* INCLUDED_UHD_TYPES_BLOCK_ID_HPP */
201 // vim: sw=4 et:
void set_block_count(size_t count)
Set the block count.
Definition: block_id.hpp:122
size_t get_device_no() const
Return device number.
Definition: block_id.hpp:96
std::string to_string() const
Return a string like this: "0/FFT_1" (includes all components, if set)
Definition: property_tree.hpp:194
UHD_INLINE bool operator>(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition: fp_compare_delta.ipp:81
UHD_INLINE bool operator!=(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition: fp_compare_delta.ipp:65
block_id_t operator++()
Increment the block count ("FFT_1" -> "FFT_2")
Definition: block_id.hpp:175
Definition: block_id.hpp:39
Definition: build_info.hpp:14
std::ostream & operator<<(std::ostream &out, block_id_t block_id)
Shortcut for << block_id.to_string()
Definition: block_id.hpp:193
size_t get_block_count() const
Return block count.
Definition: block_id.hpp:99
void set_device_no(size_t device_no)
Set the device number.
Definition: block_id.hpp:116
#define UHD_RFNOC_API
Definition: config.hpp:93
UHD_API bool operator<(const time_spec_t &, const time_spec_t &)
Implement less_than_comparable interface.
block_id_t operator++(int)
Increment the block count ("FFT_1" -> "FFT_2")
Definition: block_id.hpp:181
UHD_API bool operator==(const time_spec_t &, const time_spec_t &)
Implement equality_comparable interface.
std::string get_block_name() const
Return block name.
Definition: block_id.hpp:102