USRP Hardware Driver and USRP Manual: res_source_info.hpp Source File

| USRP Hardware Driver and USRP Manual Version: 4.9.0.makepkg-0-g9ec1f582 UHD and USRP Manual |

Loading...
Searching...
No Matches
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
17 struct res_source_info
18{
21 enum source_t {
22 USER,
23 INPUT_EDGE,
24 OUTPUT_EDGE,
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
38 source_t type;
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
81namespace std {
82template <>
83struct 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
exception.hpp
UHD_ASSERT_THROW
#define UHD_ASSERT_THROW(code)
Definition exception.hpp:321
std
STL namespace.
uhd::rfnoc
Definition actions.hpp:24
uhd
Definition build_info.hpp:12
uhd::rfnoc::res_source_info::operator!=
bool operator!=(const res_source_info &rhs) const
Definition res_source_info.hpp:49
uhd::rfnoc::res_source_info::instance
size_t instance
The instance of the source. For resource that is sourced by a edge, it.
Definition res_source_info.hpp:42
uhd::rfnoc::res_source_info::operator==
bool operator==(const res_source_info &rhs) const
Definition res_source_info.hpp:44
uhd::rfnoc::res_source_info::type
source_t type
The type of source (user or edge).
Definition res_source_info.hpp:38
uhd::rfnoc::res_source_info::source_t
source_t
Definition res_source_info.hpp:21
uhd::rfnoc::res_source_info::INPUT_EDGE
@ INPUT_EDGE
An input edge sources this resource.
Definition res_source_info.hpp:23
uhd::rfnoc::res_source_info::FRAMEWORK
@ FRAMEWORK
This is a special resource, only accessed by the framework.
Definition res_source_info.hpp:25
uhd::rfnoc::res_source_info::OUTPUT_EDGE
@ OUTPUT_EDGE
An input edge sources this resource.
Definition res_source_info.hpp:24
uhd::rfnoc::res_source_info::USER
@ USER
The user API sources this resource.
Definition res_source_info.hpp:22
uhd::rfnoc::res_source_info::res_source_info
res_source_info(source_t source_type, size_t instance_=0)
Definition res_source_info.hpp:31
uhd::rfnoc::res_source_info::invert_edge
static source_t invert_edge(const source_t edge_direction)
Definition res_source_info.hpp:72
uhd::rfnoc::res_source_info::to_string
std::string to_string() const
Returns a string representation of the source.
Definition res_source_info.hpp:55
uhd::rfnoc::res_source_info::res_source_info
res_source_info()=delete