Loading...
Searching...
No Matches
res_source_info.hpp
Go to the documentation of this file.
//
// Copyright 2019 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#pragma once
#include <uhd/exception.hpp>
#include <cstdint>
#include <string>
namespace uhd { namespace rfnoc {
struct res_source_info
{
enum source_t {
USER,
INPUT_EDGE,
OUTPUT_EDGE,
FRAMEWORK
};
// No default ctor: The source type must be specified
res_source_info() = delete;
res_source_info(source_t source_type, size_t instance_ = 0)
: type(source_type), instance(instance_)
{
// nop
}
source_t type;
// corresponds to the port number
size_t instance = 0;
bool operator==(const res_source_info& rhs) const
{
return rhs.type == type && rhs.instance == instance;
}
bool operator!=(const res_source_info& rhs) const
{
return !(*this == rhs);
}
std::string to_string() const
{
const std::string type_repr = type == USER ? "USER"
: type == INPUT_EDGE ? "INPUT_EDGE"
: type == OUTPUT_EDGE ? "OUTPUT_EDGE"
: "INVALID";
return type_repr + ":" + std::to_string(instance);
}
static source_t invert_edge(const source_t edge_direction)
{
UHD_ASSERT_THROW(edge_direction == INPUT_EDGE || edge_direction == OUTPUT_EDGE);
return edge_direction == INPUT_EDGE ? OUTPUT_EDGE : INPUT_EDGE;
}
};
}} /* namespace uhd::rfnoc */
namespace std {
template <>
struct hash<uhd::rfnoc::res_source_info>
{
size_t operator()(const uhd::rfnoc::res_source_info& src_info) const
{
const size_t hash_type = std::hash<size_t>{}(src_info.type);
const size_t hash_inst = std::hash<size_t>{}(src_info.instance);
return hash_type ^ (hash_inst << 1);
}
};
} // 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