USRP Hardware Driver and Device Manual  Version: 4.11.0.0-0-g0d7ed3b1
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,
25  FRAMEWORK
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 
43  size_t instance = 0;
44 
45  bool operator==(const res_source_info& rhs) const
46  {
47  return rhs.type == type && rhs.instance == instance;
48  }
49 
50  bool operator!=(const res_source_info& rhs) const
51  {
52  return !(*this == rhs);
53  }
54 
56  std::string to_string() const
57  {
58  const std::string type_repr = type == USER ? "USER"
59  : type == INPUT_EDGE ? "INPUT_EDGE"
60  : type == OUTPUT_EDGE ? "OUTPUT_EDGE"
61  : "INVALID";
62  return type_repr + ":" + std::to_string(instance);
63  }
64 
73  static source_t invert_edge(const source_t edge_direction)
74  {
75  UHD_ASSERT_THROW(edge_direction == INPUT_EDGE || edge_direction == OUTPUT_EDGE);
76  return edge_direction == INPUT_EDGE ? OUTPUT_EDGE : INPUT_EDGE;
77  }
78 };
79 
80 }} /* namespace uhd::rfnoc */
81 
82 namespace std {
83 template <>
84 struct hash<uhd::rfnoc::res_source_info>
85 {
86  size_t operator()(const uhd::rfnoc::res_source_info& src_info) const
87  {
88  const size_t hash_type = std::hash<size_t>{}(src_info.type);
89  const size_t hash_inst = std::hash<size_t>{}(src_info.instance);
90  return hash_type ^ (hash_inst << 1);
91  }
92 };
93 } // namespace std
#define UHD_ASSERT_THROW(code)
Definition: exception.hpp:321
Definition: build_info.hpp:12
Definition: res_source_info.hpp:18
bool operator!=(const res_source_info &rhs) const
Definition: res_source_info.hpp:50
size_t instance
Definition: res_source_info.hpp:43
bool operator==(const res_source_info &rhs) const
Definition: res_source_info.hpp:45
source_t type
The type of source (user or edge)
Definition: res_source_info.hpp:38
source_t
Definition: res_source_info.hpp:21
@ INPUT_EDGE
An input edge sources this resource.
Definition: res_source_info.hpp:23
@ FRAMEWORK
This is a special resource, only accessed by the framework.
Definition: res_source_info.hpp:25
@ OUTPUT_EDGE
An input edge sources this resource.
Definition: res_source_info.hpp:24
@ USER
The user API sources this resource.
Definition: res_source_info.hpp:22
res_source_info(source_t source_type, size_t instance_=0)
Definition: res_source_info.hpp:31
static source_t invert_edge(const source_t edge_direction)
Definition: res_source_info.hpp:73
std::string to_string() const
Returns a string representation of the source.
Definition: res_source_info.hpp:56