The Sparta Modeling Framework
Loading...
Searching...
No Matches
ExportedPort.hpp
Go to the documentation of this file.
1// <ExportedPort.hpp> -*- C++ -*-
2
8#pragma once
9
10#include <string>
12#include "sparta/ports/Port.hpp"
13#include "sparta/utils/Utils.hpp"
14
15namespace sparta
16{
79 class ExportedPort : public Port
80 {
81 public:
82
93 const std::string & exported_port_name,
94 sparta::TreeNode * internal_port_search_path,
95 const std::string & internal_port_name) :
96 Port(portset, Port::Direction::UNKNOWN, exported_port_name),
97 internal_port_search_path_(internal_port_search_path),
98 internal_port_name_(internal_port_name)
99 {}
100
111 const std::string & exported_port_name,
112 sparta::Port * internal_port) :
113 Port(portset, sparta::notNull(internal_port)->getDirection(), exported_port_name),
114 internal_port_(internal_port),
115 internal_port_name_(internal_port->getName())
116 {}
117
120 void bind(Port * port) override final;
121
124 bool isBound() const override final
125 {
126 // If the internal_port is nullptr, it has not been bound
127 // yet (searched for)
128 if(nullptr != internal_port_) {
129 return internal_port_->isBound();
130 }
131 return false;
132 }
133
139 Direction getDirection() const override {
140 if(nullptr == internal_port_) {
142 }
143 return internal_port_->getDirection();
144 }
145
148 void participateInAutoPrecedence(bool) override final {
149 sparta_assert(false, "You cannot set auto precedence on an ExportedPort");
150 }
151
154 bool doesParticipateInAutoPrecedence() const override final {
155 if(internal_port_) {
156 return internal_port_->doesParticipateInAutoPrecedence();
157 }
158 return false;
159 }
160
166 sparta::Port * getInternalPort() { return internal_port_; }
167
173 const sparta::Port * getInternalPort() const { return internal_port_; }
174
177 std::string stringize(bool pretty=false) const override {
178 sparta_assert(internal_port_ != this);
179 std::stringstream ss;
180 ss << "[exported port <" << getLocation() << "> ";
181 if(internal_port_) {
182 ss << internal_port_->stringize(pretty);
183 }
184 else {
185 ss << "undefined";
186 }
187 ss << "]";
188 return ss.str();
189 }
190
191
192 private:
193 // The interal port -- to either be found or provided
194 sparta::Port * internal_port_ = nullptr;
195
196 // Non-const as the Port TreeNode contained in the path will
197 // be modified during binding. If this variable were const,
198 // the code could not find the to-be-modified internal_port_
199 sparta::TreeNode * internal_port_search_path_ = nullptr;
200 const std::string internal_port_name_;
201
202 // Resolve the internal port
203 void resolvePort_();
204 };
205}
File that defines the Port base class.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
Basic Node framework in sparta device tree composite pattern.
Class that "exports" a port that's contained in the same ResourceTreeNode structure.
Direction getDirection() const override
Get the direction of the port.
const sparta::Port * getInternalPort() const
Return the intenal representative port (const)
ExportedPort(sparta::TreeNode *portset, const std::string &exported_port_name, sparta::TreeNode *internal_port_search_path, const std::string &internal_port_name)
Create an ExportedPort that exposes an internal port by name.
std::string stringize(bool pretty=false) const override
Print the exported port.
bool isBound() const override final
Override Port::isBound.
sparta::Port * getInternalPort()
Return the intenal representative port (non-const)
ExportedPort(sparta::TreeNode *portset, const std::string &exported_port_name, sparta::Port *internal_port)
Create an ExportedPort for an explicit internal port.
void participateInAutoPrecedence(bool) override final
Function that cannot be used in ExportedPort. The user must set auto precedence directly in the inter...
bool doesParticipateInAutoPrecedence() const override final
Does the internal Port participate in auto-precedence.
void bind(Port *port) override final
Override Port::bind.
The port interface used to bind port types together and defines a port behavior.
Definition Port.hpp:59
std::string stringize(bool x) const override
Stringize the Port.
Definition Port.hpp:177
virtual bool isBound() const
Is this port bound to another port?
Definition Port.hpp:126
Direction
The direction of this port.
Definition Port.hpp:68
virtual bool doesParticipateInAutoPrecedence() const
Does this Port participate in auto-precedence establishment by sparta::Unit?
Definition Port.hpp:168
virtual Direction getDirection() const
The direction of the port.
Definition Port.hpp:142
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
std::string getLocation() const override final
const std::string & getName() const override
Gets the name of this node.
Macros for handling exponential backoff.
T * notNull(T *p)
Ensures that a pointer is not null.
Definition Utils.hpp:224