USRP Hardware Driver and USRP Manual  Version: 004.000.000.HEAD-0-g8773fb2c
UHD and USRP Manual
block_id.hpp
Go to the documentation of this file.
1 // Copyright 2014 Ettus Research LLC
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
15 //
16 
17 #ifndef INCLUDED_UHD_TYPES_BLOCK_ID_HPP
18 #define INCLUDED_UHD_TYPES_BLOCK_ID_HPP
19 
20 #include <uhd/config.hpp>
21 #include <boost/cstdint.hpp>
22 #include <boost/shared_ptr.hpp>
23 #include <iostream>
24 #include <string>
25 
26 namespace uhd {
27  struct fs_path;
28 
29  namespace rfnoc {
30 
50  {
51  public:
52  block_id_t();
53  block_id_t(const std::string &block_str);
57  block_id_t(const size_t device_no, const std::string &block_name, const size_t block_ctr=0);
58 
60  std::string to_string() const;
61 
63  //
64  // Note: This only applies to the block *name*, not the entire block ID.
65  // Examples:
66  // * is_valid_blockname("FFT") will return true.
67  // * is_valid_blockname("FIR_Filter") will return false, because an underscore
68  // is not allowed in a block name.
69  //
70  // Internally, this matches the string with uhd::rfnoc::VALID_BLOCKNAME_REGEX.
71  static bool is_valid_blockname(const std::string &block_name);
72 
74  //
75  // Note: This does necessary require a complete complete ID. If this returns
76  // true, then it is a valid input for block_id_t::match().
77  //
78  // Examples:
79  // * is_valid_block_id("FFT") will return true.
80  // * is_valid_block_id("0/Filter_1") will return true.
81  // * is_valid_block_id("0/Filter_Foo") will return false.
82  //
83  // Internally, this matches the string with uhd::rfnoc::VALID_BLOCKID_REGEX.
84  static bool is_valid_block_id(const std::string &block_id);
85 
87  //
88  // A match is a less strict version of equality.
89  // Less specific block IDs will match more specific ones,
90  // e.g. "FFT" will match "0/FFT_1", "1/FFT_2", etc.
91  // "FFT_1" will only match the former, etc.
92  bool match(const std::string &block_str);
93 
94  // Getters
95 
97  std::string get() const { return to_string(); };
98 
100  std::string get_local() const;
101 
103  uhd::fs_path get_tree_root() const;
104 
106  size_t get_device_no() const { return _device_no; };
107 
109  size_t get_block_count() const { return _block_ctr; };
110 
112  std::string get_block_name() const { return _block_name; };
113 
114  // Setters
115 
117  // Returns true if successful (i.e. if string valid)
118  bool set(const std::string &new_name);
119 
121  // and set_block_count() one after another, only if \p block_name is invalid, stops
122  // and returns false before chaning anything
123  bool set(const size_t device_no, const std::string &block_name, const size_t block_ctr=0);
124 
126  void set_device_no(size_t device_no) { _device_no = device_no; };
127 
129  bool set_block_name(const std::string &block_name);
130 
132  void set_block_count(size_t count) { _block_ctr = count; };
133 
134  // Overloaded operators
135 
137  block_id_t operator = (const std::string &new_name) {
138  set(new_name);
139  return *this;
140  }
141 
142  bool operator == (const block_id_t &block_id) const {
143  return (_device_no == block_id.get_device_no())
144  and (_block_name == block_id.get_block_name())
145  and (_block_ctr == block_id.get_block_count());
146  }
147 
148  bool operator != (const block_id_t &block_id) const {
149  return not (*this == block_id);
150  }
151 
152  bool operator < (const block_id_t &block_id) const {
153  return (
154  _device_no < block_id.get_device_no()
155  or (_device_no == block_id.get_device_no() and _block_name < block_id.get_block_name())
156  or (_device_no == block_id.get_device_no() and _block_name == block_id.get_block_name() and _block_ctr < block_id.get_block_count())
157  );
158  }
159 
160  bool operator > (const block_id_t &block_id) const {
161  return (
162  _device_no > block_id.get_device_no()
163  or (_device_no == block_id.get_device_no() and _block_name > block_id.get_block_name())
164  or (_device_no == block_id.get_device_no() and _block_name == block_id.get_block_name() and _block_ctr > block_id.get_block_count())
165  );
166  }
167 
169  bool operator == (const std::string &block_id_str) const {
170  return get() == block_id_str;
171  }
172 
174  bool operator == (const char *block_id_str) const {
175  std::string comp = std::string(block_id_str);
176  return *this == comp;
177  }
178 
180  operator std::string() const {
181  return to_string();
182  }
183 
186  _block_ctr++;
187  return *this;
188  }
189 
192  _block_ctr++;
193  return *this;
194  }
195 
196  private:
197  size_t _device_no;
198  std::string _block_name;
199  size_t _block_ctr;
200  };
201 
203  inline std::ostream& operator<< (std::ostream& out, block_id_t block_id) {
204  out << block_id.to_string();
205  return out;
206  }
207 
208 }} //namespace uhd::rfnoc
209 
210 #endif /* INCLUDED_UHD_TYPES_BLOCK_ID_HPP */
211 // vim: sw=4 et:
void set_block_count(size_t count)
Set the block count.
Definition: block_id.hpp:132
size_t get_device_no() const
Return device number.
Definition: block_id.hpp:106
std::string to_string() const
Return a string like this: "0/FFT_1" (includes all components, if set)
Definition: property_tree.hpp:204
UHD_INLINE bool operator>(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition: fp_compare_delta.ipp:91
UHD_INLINE bool operator!=(fp_compare_delta< float_t > lhs, fp_compare_delta< float_t > rhs)
Definition: fp_compare_delta.ipp:75
block_id_t operator++()
Increment the block count ("FFT_1" -> "FFT_2")
Definition: block_id.hpp:185
Definition: block_id.hpp:49
Definition: build_info.hpp:25
std::ostream & operator<<(std::ostream &out, block_id_t block_id)
Shortcut for << block_id.to_string()
Definition: block_id.hpp:203
size_t get_block_count() const
Return block count.
Definition: block_id.hpp:109
void set_device_no(size_t device_no)
Set the device number.
Definition: block_id.hpp:126
#define UHD_RFNOC_API
Definition: config.hpp:103
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:191
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:112