USRP Hardware Driver and USRP Manual  Version: 4.6.0.0-7-gece7c4811
UHD and USRP Manual
res_source_info.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2019 Ettus Research, a National Instruments Brand
3 //
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 //
6 
7 #pragma once
8 
9 #include <uhd/exception.hpp>
10 #include <cstdint>
11 #include <string>
12 
13 namespace uhd { namespace rfnoc {
14 
18 {
21  enum source_t {
22  USER,
26  };
27 
28  // No default ctor: The source type must be specified
29  res_source_info() = delete;
30 
31  res_source_info(source_t source_type, size_t instance_ = 0)
32  : type(source_type), instance(instance_)
33  {
34  // nop
35  }
36 
39 
41  // corresponds to the port number
42  size_t instance = 0;
43 
44  bool operator==(const res_source_info& rhs) const
45  {
46  return rhs.type == type && rhs.instance == instance;
47  }
48 
49  bool operator!=(const res_source_info& rhs) const
50  {
51  return !(*this == rhs);
52  }
53 
55  std::string to_string() const
56  {
57  const std::string type_repr = type == USER ? "USER"
58  : type == INPUT_EDGE ? "INPUT_EDGE"
59  : type == OUTPUT_EDGE ? "OUTPUT_EDGE"
60  : "INVALID";
61  return type_repr + ":" + std::to_string(instance);
62  }
63 
72  static source_t invert_edge(const source_t edge_direction)
73  {
74  UHD_ASSERT_THROW(edge_direction == INPUT_EDGE || edge_direction == OUTPUT_EDGE);
75  return edge_direction == INPUT_EDGE ? OUTPUT_EDGE : INPUT_EDGE;
76  }
77 };
78 
79 }} /* namespace uhd::rfnoc */
80 
81 namespace std {
82 template <>
83 struct hash<uhd::rfnoc::res_source_info>
84 {
85  size_t operator()(const uhd::rfnoc::res_source_info& src_info) const
86  {
87  const size_t hash_type = std::hash<size_t>{}(src_info.type);
88  const size_t hash_inst = std::hash<size_t>{}(src_info.instance);
89  return hash_type ^ (hash_inst << 1);
90  }
91 };
92 } // namespace std
static source_t invert_edge(const source_t edge_direction)
Definition: res_source_info.hpp:72
std::string to_string() const
Returns a string representation of the source.
Definition: res_source_info.hpp:55
STL namespace.
#define UHD_ASSERT_THROW(code)
Definition: exception.hpp:321
size_t operator()(const uhd::rfnoc::res_source_info &src_info) const
Definition: res_source_info.hpp:85
res_source_info(source_t source_type, size_t instance_=0)
Definition: res_source_info.hpp:31
Definition: build_info.hpp:12
source_t
Definition: res_source_info.hpp:21
source_t type
The type of source (user or edge)
Definition: res_source_info.hpp:38
The user API sources this resource.
Definition: res_source_info.hpp:22
Definition: res_source_info.hpp:17
bool operator==(const res_source_info &rhs) const
Definition: res_source_info.hpp:44
bool operator!=(const res_source_info &rhs) const
Definition: res_source_info.hpp:49
This is a special resource, only accessed by the framework.
Definition: res_source_info.hpp:25
size_t instance
The instance of the source. For resource that is sourced by a edge, it.
Definition: res_source_info.hpp:42
An input edge sources this resource.
Definition: res_source_info.hpp:23
An input edge sources this resource.
Definition: res_source_info.hpp:24