USRP Hardware Driver and USRP Manual Version: 4.1.0.1
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
13namespace uhd { namespace rfnoc {
14
18{
21 enum source_t {
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 =
58 type == USER
59 ? "USER"
60 : type == INPUT_EDGE ? "INPUT_EDGE"
61 : type == OUTPUT_EDGE ? "OUTPUT_EDGE" : "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
82namespace std {
83template <>
84struct 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:322
STL namespace.
Definition: build_info.hpp:12
size_t operator()(const uhd::rfnoc::res_source_info &src_info) const
Definition: res_source_info.hpp:86
Definition: res_source_info.hpp:18
bool operator!=(const res_source_info &rhs) const
Definition: res_source_info.hpp:49
size_t instance
The instance of the source. For resource that is sourced by a edge, it.
Definition: res_source_info.hpp:42
bool operator==(const res_source_info &rhs) const
Definition: res_source_info.hpp:44
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:55