Minsky
minsky::Port Class Reference

#include <port.h>

Inheritance diagram for minsky::Port:
Inheritance graph
Collaboration diagram for minsky::Port:
Collaboration graph

Public Member Functions

std::vector< Wire * > const & wires () const
 returns a vector of weak references to the wires attached to this port More...
 
std::size_t numWires () const
 
void eraseWire (Wire *)
 remove wire from wires. No ownership passed. More...
 
void deleteWires ()
 delete all attached wires More...
 
virtual bool input () const
 true if input port More...
 
virtual bool multiWireAllowed () const
 true if multiple wires are allowed to connect to an input port, such as an input port of an add operation. Irrelevant, otherwise More...
 
virtual void combineInput (double &x, double y) const
 combine two input wires More...
 
virtual double identity () const
 input port value if no wire attached More...
 
float x () const
 
float y () const
 
void moveTo (float x, float y)
 
 Port (Item &item)
 
 ~Port ()
 
double value () const
 value associated with this port More...
 
Units units (bool) const
 
Units checkUnits () const
 dimensional analysis with consistency check More...
 
Itemitem ()
 owner of this port More...
 
const Itemitem () const
 owner of this port More...
 

Private Member Functions

 CLASSDESC_ACCESS (Port)
 
 Port (const Port &)=delete
 
void operator= (const Port &)=delete
 

Private Attributes

float m_x {0}
 
float m_y {0}
 

Friends

struct SchemaHelper
 
class Wire
 

Detailed Description

Definition at line 53 of file port.h.

Constructor & Destructor Documentation

◆ Port() [1/2]

minsky::Port::Port ( const Port )
privatedelete

◆ Port() [2/2]

minsky::Port::Port ( Item item)
inline

Definition at line 96 of file port.h.

96 : classdesc::Exclude<PortExclude>(item) {}
Item & item()
owner of this port
Definition: port.h:66

◆ ~Port()

minsky::Port::~Port ( )
inline

Definition at line 99 of file port.h.

References deleteWires().

99 {deleteWires();}
void deleteWires()
delete all attached wires
Definition: port.cc:70
Here is the call graph for this function:

Member Function Documentation

◆ checkUnits()

Units minsky::Port::checkUnits ( ) const
inline

dimensional analysis with consistency check

Definition at line 105 of file port.h.

References units().

105 {return units(true);}
Units units(bool) const
Definition: port.cc:107
Here is the call graph for this function:

◆ CLASSDESC_ACCESS()

minsky::Port::CLASSDESC_ACCESS ( Port  )
private

◆ combineInput()

virtual void minsky::Port::combineInput ( double &  x,
double  y 
) const
inlinevirtual

combine two input wires

Parameters
xinput to be updated
yinput to be combined with x

Reimplemented in minsky::anonymous_namespace{operation.cc}::OrInputPort, minsky::anonymous_namespace{operation.cc}::AndInputPort, minsky::anonymous_namespace{operation.cc}::MinInputPort, minsky::anonymous_namespace{operation.cc}::MaxInputPort, minsky::anonymous_namespace{operation.cc}::MulInputPort, and minsky::anonymous_namespace{operation.cc}::SumInputPort.

Definition at line 89 of file port.h.

References x(), and y().

89 {x=y;}
float y() const
Definition: port.cc:44
float x() const
Definition: port.cc:39
Here is the call graph for this function:

◆ deleteWires()

void minsky::Port::deleteWires ( )

delete all attached wires

wires could be anywhere, so we need to walk the whole heirachy

Definition at line 70 of file port.cc.

Referenced by ~Port().

71  {
73  if (auto g=item().group.lock())
74  {
75  auto& gg=g->globalGroup();
76  auto wires=m_wires; // save copy, as Group::removeWire mutates it
77  vector<WirePtr> wireHold; // postpone actual wire destruction until after loop
78  wireHold.reserve(wires.size());
79  for (auto& w: wires)
80  wireHold.push_back(gg.removeWire(*w));
81  }
82  m_wires.clear();
83  }
std::vector< Wire * > const & wires() const
returns a vector of weak references to the wires attached to this port
Definition: port.h:71
Definition: group.tcl:84
Item & item()
owner of this port
Definition: port.h:66
Here is the caller graph for this function:

◆ eraseWire()

void minsky::Port::eraseWire ( Wire w)

remove wire from wires. No ownership passed.

Definition at line 60 of file port.cc.

61  {
62  for (auto i=m_wires.begin(); i!=m_wires.end(); ++i)
63  if (*i==w)
64  {
65  m_wires.erase(i);
66  break;
67  }
68  }

◆ identity()

virtual double minsky::Port::identity ( ) const
inlinevirtual

◆ input()

virtual bool minsky::Port::input ( ) const
inlinevirtual

true if input port

Reimplemented in minsky::InputPort.

Definition at line 80 of file port.h.

Referenced by minsky::TensorsFromPort::tensorsFromPort().

80 {return false;}
Here is the caller graph for this function:

◆ item() [1/2]

Item& minsky::Port::item ( )
inline

owner of this port

Definition at line 66 of file port.h.

Referenced by minsky::anonymous_namespace{minsky.cc}::Network::followWire().

66 {return m_item;};
Here is the caller graph for this function:

◆ item() [2/2]

const Item& minsky::Port::item ( ) const
inline

owner of this port

Definition at line 67 of file port.h.

67 {return m_item;}

◆ moveTo()

void minsky::Port::moveTo ( float  x,
float  y 
)

Definition at line 49 of file port.cc.

50  {
51  m_x=x-item().x();
52  m_y=y-item().y();
53  }
virtual float x() const
Definition: item.cc:107
virtual float y() const
Definition: item.cc:114
float m_y
Definition: port.h:57
float m_x
Definition: port.h:57
float y() const
Definition: port.cc:44
float x() const
Definition: port.cc:39
Item & item()
owner of this port
Definition: port.h:66

◆ multiWireAllowed()

virtual bool minsky::Port::multiWireAllowed ( ) const
inlinevirtual

true if multiple wires are allowed to connect to an input port, such as an input port of an add operation. Irrelevant, otherwise

Reimplemented in minsky::MultiWireInputPort.

Definition at line 85 of file port.h.

85 {return false;}

◆ numWires()

std::size_t minsky::Port::numWires ( ) const
inline

Definition at line 72 of file port.h.

72 {return m_wires.size();}

◆ operator=()

void minsky::Port::operator= ( const Port )
privatedelete

◆ units()

Units minsky::Port::units ( bool  check) const

Definition at line 107 of file port.cc.

Referenced by checkUnits().

108  {
109  if (!wires().empty())
110  return wires()[0]->units(check);
111  return {};
112  }
std::vector< Wire * > const & wires() const
returns a vector of weak references to the wires attached to this port
Definition: port.h:71
Here is the caller graph for this function:

◆ value()

double minsky::Port::value ( ) const

value associated with this port

Definition at line 92 of file port.cc.

92  {
93  if (input())
94  {
95  double r=identity();
96  for (auto* w: m_wires)
97  combineInput(r, w->from()->value());
98  return r;
99  }
100  auto vv=getVariableValue();
101  if (vv && vv->type()!=VariableType::undefined)
102  return vv->value();
103  return item().value();
104  }
virtual bool input() const
true if input port
Definition: port.h:80
virtual double value() const
current value of output port
Definition: item.h:209
virtual void combineInput(double &x, double y) const
combine two input wires
Definition: port.h:89
Item & item()
owner of this port
Definition: port.h:66
virtual double identity() const
input port value if no wire attached
Definition: port.h:91

◆ wires()

std::vector<Wire*> const& minsky::Port::wires ( ) const
inline

returns a vector of weak references to the wires attached to this port

Definition at line 71 of file port.h.

Referenced by minsky::TensorsFromPort::tensorsFromPort().

71 {return m_wires;}
Here is the caller graph for this function:

◆ x()

float minsky::Port::x ( ) const

Definition at line 39 of file port.cc.

Referenced by combineInput().

40  {
41  return m_x+item().x();
42  }
virtual float x() const
Definition: item.cc:107
float m_x
Definition: port.h:57
Item & item()
owner of this port
Definition: port.h:66
Here is the caller graph for this function:

◆ y()

float minsky::Port::y ( ) const

Definition at line 44 of file port.cc.

Referenced by combineInput().

45  {
46  return m_y+item().y();
47  }
virtual float y() const
Definition: item.cc:114
float m_y
Definition: port.h:57
Item & item()
owner of this port
Definition: port.h:66
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ SchemaHelper

friend struct SchemaHelper
friend

Definition at line 59 of file port.h.

◆ Wire

friend class Wire
friend

Definition at line 62 of file port.h.

Member Data Documentation

◆ m_x

float minsky::Port::m_x {0}
private

Definition at line 57 of file port.h.

◆ m_y

float minsky::Port::m_y {0}
private

Definition at line 57 of file port.h.


The documentation for this class was generated from the following files: