Loading...
Searching...
No Matches
block_id.hpp
Go to the documentation of this file.
// Copyright 2014 Ettus Research LLC
// Copyright 2018 Ettus Research, a National Instruments Company
// Copyright 2019 Ettus Research, a National Instruments Company
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#pragma once
#include <uhd/config.hpp>
#include <stdint.h>
#include <iostream>
#include <memory>
#include <string>
namespace uhd {
struct fs_path;
namespace rfnoc {
class UHD_API block_id_t
{
public:
block_id_t();
block_id_t(const std::string& block_str);
block_id_t(const size_t device_no,
const std::string& block_name,
const size_t block_ctr = 0);
std::string to_string() const;
//
// Note: This only applies to the block *name*, not the entire block ID.
// Examples:
// * is_valid_blockname("FFT") will return true.
// * is_valid_blockname("FIR#Filter") will return false, because a # symbol
// is not allowed in a block name. Only alphanumerical characters and
// underscores are allowed.
//
// Internally, this matches the string with uhd::rfnoc::VALID_BLOCKNAME_REGEX.
static bool is_valid_blockname(const std::string& block_name);
//
// Note: This does necessary require a complete complete ID. If this returns
// true, then it is a valid input for block_id_t::match().
//
// Examples:
// * is_valid_block_id("FFT") will return true.
// * is_valid_block_id("0/Filter#1") will return true.
// * is_valid_block_id("0/Filter#Foo") will return false.
//
// Internally, this matches the string with uhd::rfnoc::VALID_BLOCKID_REGEX.
static bool is_valid_block_id(const std::string& block_id);
//
// A match is a less strict version of equality.
// Less specific block IDs will match more specific ones,
// e.g. "FFT" will match "0/FFT#1", "1/FFT#2", etc.
// "FFT#1" will only match the former, etc.
bool match(const std::string& block_str);
// Getters
std::string get() const
{
return to_string();
};
std::string get_local() const;
uhd::fs_path get_tree_root() const;
size_t get_device_no() const
{
return _device_no;
};
size_t get_block_count() const
{
return _block_ctr;
};
std::string get_block_name() const
{
return _block_name;
};
// Setters
// Returns true if successful (i.e. if string valid)
bool set(const std::string& new_name);
// and set_block_count() one after another, only if \p block_name is invalid, stops
// and returns false before changing anything
bool set(const size_t device_no,
const std::string& block_name,
const size_t block_ctr = 0);
void set_device_no(size_t device_no)
{
_device_no = device_no;
};
bool set_block_name(const std::string& block_name);
void set_block_count(size_t count)
{
_block_ctr = count;
};
// Overloaded operators
block_id_t operator=(const std::string& new_name)
{
set(new_name);
return *this;
}
bool operator==(const block_id_t& block_id) const
{
return (_device_no == block_id.get_device_no())
and (_block_name == block_id.get_block_name())
and (_block_ctr == block_id.get_block_count());
}
bool operator!=(const block_id_t& block_id) const
{
return not(*this == block_id);
}
bool operator<(const block_id_t& block_id) const
{
return (_device_no < block_id.get_device_no()
or (_device_no == block_id.get_device_no()
and _block_name < block_id.get_block_name())
or (_device_no == block_id.get_device_no()
and _block_name == block_id.get_block_name()
and _block_ctr < block_id.get_block_count()));
}
bool operator>(const block_id_t& block_id) const
{
return (_device_no > block_id.get_device_no()
or (_device_no == block_id.get_device_no()
and _block_name > block_id.get_block_name())
or (_device_no == block_id.get_device_no()
and _block_name == block_id.get_block_name()
and _block_ctr > block_id.get_block_count()));
}
bool operator==(const std::string& block_id_str) const
{
return get() == block_id_str;
}
bool operator==(const char* block_id_str) const
{
std::string comp = std::string(block_id_str);
return *this == comp;
}
operator std::string() const
{
return to_string();
}
block_id_t operator++()
{
_block_ctr++;
return *this;
}
block_id_t operator++(int)
{
_block_ctr++;
return *this;
}
private:
size_t _device_no;
std::string _block_name;
size_t _block_ctr;
};
inline std::ostream& operator<<(std::ostream& out, block_id_t block_id)
{
out << block_id.to_string();
return out;
}
} // namespace rfnoc
} // namespace uhd
uhd::rfnoc::block_id_t
Definition block_id.hpp:40
uhd::rfnoc::block_id_t::set
bool set(const std::string &new_name)
Set from string such as "0/FFT#1", "FFT#0", ...
uhd::rfnoc::block_id_t::set_block_count
void set_block_count(size_t count)
Set the block count.
Definition block_id.hpp:142
uhd::rfnoc::block_id_t::is_valid_blockname
static bool is_valid_blockname(const std::string &block_name)
Check if a given string is valid as a block name.
uhd::rfnoc::block_id_t::operator==
bool operator==(const char *block_id_str) const
Check if a string matches the entire block ID (not like match()).
Definition block_id.hpp:195
uhd::rfnoc::block_id_t::is_valid_block_id
static bool is_valid_block_id(const std::string &block_id)
Check if a given string is valid as a block ID.
uhd::rfnoc::block_id_t::get
std::string get() const
Short for to_string().
Definition block_id.hpp:90
uhd::rfnoc::block_id_t::match
bool match(const std::string &block_str)
Check if block_str matches this block.
uhd::rfnoc::block_id_t::block_id_t
block_id_t(const std::string &block_str)
uhd::rfnoc::block_id_t::get_tree_root
uhd::fs_path get_tree_root() const
Returns the property tree root for this block (e.g. "/mboards/0/xbar/FFT#1/").
uhd::rfnoc::block_id_t::get_block_count
size_t get_block_count() const
Return block count.
Definition block_id.hpp:108
uhd::rfnoc::block_id_t::operator!=
bool operator!=(const block_id_t &block_id) const
Definition block_id.hpp:163
uhd::rfnoc::block_id_t::operator>
bool operator>(const block_id_t &block_id) const
Definition block_id.hpp:178
uhd::rfnoc::block_id_t::get_device_no
size_t get_device_no() const
Return device number.
Definition block_id.hpp:102
uhd::rfnoc::block_id_t::operator++
block_id_t operator++()
Increment the block count ("FFT#1" -> "FFT_2").
Definition block_id.hpp:208
uhd::rfnoc::block_id_t::get_local
std::string get_local() const
Like get(), but only returns the local part ("FFT#1").
uhd::rfnoc::block_id_t::block_id_t
block_id_t()
uhd::rfnoc::block_id_t::operator==
bool operator==(const block_id_t &block_id) const
Definition block_id.hpp:156
uhd::rfnoc::block_id_t::to_string
std::string to_string() const
Return a string like this: "0/FFT#1" (includes all components, if set).
uhd::rfnoc::block_id_t::operator==
bool operator==(const std::string &block_id_str) const
Check if a string matches the entire block ID (not like match()).
Definition block_id.hpp:189
uhd::rfnoc::block_id_t::block_id_t
block_id_t(const size_t device_no, const std::string &block_name, const size_t block_ctr=0)
uhd::rfnoc::block_id_t::operator++
block_id_t operator++(int)
Increment the block count ("FFT#1" -> "FFT_2").
Definition block_id.hpp:215
uhd::rfnoc::block_id_t::get_block_name
std::string get_block_name() const
Return block name.
Definition block_id.hpp:114
uhd::rfnoc::block_id_t::operator<
bool operator<(const block_id_t &block_id) const
Definition block_id.hpp:168
uhd::rfnoc::block_id_t::set_block_name
bool set_block_name(const std::string &block_name)
Set the block name. Will return false if invalid block string.
uhd::rfnoc::block_id_t::operator=
block_id_t operator=(const std::string &new_name)
Assignment: Works like set(std::string).
Definition block_id.hpp:150
uhd::rfnoc::block_id_t::set
bool set(const size_t device_no, const std::string &block_name, const size_t block_ctr=0)
Sets from individual components, like calling set_device_no(), set_block_name().
uhd::rfnoc::block_id_t::set_device_no
void set_device_no(size_t device_no)
Set the device number.
Definition block_id.hpp:133
UHD_API
#define UHD_API
Definition config.h:87
config.hpp
uhd::rfnoc
Definition actions.hpp:24
uhd::rfnoc::operator<<
std::ostream & operator<<(std::ostream &out, block_id_t block_id)
Shortcut for << block_id.to_string().
Definition block_id.hpp:228
uhd
Definition build_info.hpp:12
uhd::fs_path
Definition property_tree.hpp:207