13#include <unordered_map>
50 for(uint32_t i = 0; i < Port::Direction::N_DIRECTIONS; ++i) {
51 auto found_port = registered_ports_[i].find(named_port);
52 if(found_port != registered_ports_[i].end()) {
53 return found_port->second;
57 throw SpartaException(
"The port with the name : " + named_port +
" could not be found");
106 return registered_ports_[direction];
111 RegisteredPortMap registered_ports_[
static_cast<uint32_t
>(Port::Direction::N_DIRECTIONS)];
124 virtual void onAddingChild_(
TreeNode* child)
override {
126 throw SpartaException(
"Cannot add a child Port once a PortSet is finalized. "
131 Port* port =
dynamic_cast<Port*
>(child);
133 sparta_assert(registered_ports_[port->getDirection()].count(port->getName()) == 0,
134 "ERROR: Port '" << port->getName() <<
"' already registered");
135 registered_ports_[port->getDirection()][port->getName()] = port;
139 throw SpartaException(
"Cannot add TreeNode child ")
141 <<
" because the child is not a Port or derivative";
File that defines the Port base class.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
virtual bool isFinalized() const
Is this node (and thus the entire tree above it) "finalized".
A TreeNode that represents a set of ports used by a Resource.
PortSet(TreeNode *parent, const std::string &desc="Port Set")
Construct a PortSet with a given parent. The parent can be nullptr.
Port * getPort(const std::string &named_port) const
Get a port by the given name.
RegisteredPortMap & getPorts(Port::Direction direction)
Get the ports in this PortSet for the given direction.
PortSet(const PortSet &)=delete
Get a DataInPort by the given name (convenience function)
PortSet & operator=(const PortSet &)=delete
Cannot assign PortSets.
std::unordered_map< std::string, Port * > RegisteredPortMap
Convenience typedef.
The port interface used to bind port types together and defines a port behavior.
Direction
The direction of this port.
Used to construct and throw a standard C++ exception. Inherits from std::exception.
Node in a composite tree representing a sparta Tree item.
std::string getLocation() const override final
const std::string & getName() const override
Gets the name of this node.
Macros for handling exponential backoff.